|
<? Php
//
Date_default_timezone_set ('prc ');
// Obtain access_token
$ Data = "app_id = x & app_secret = x & grant_type = client_credentials ";
$ Ch = curl_init ("https://oauth.api.189.cn/emp/oauth2/v2/access_token ");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1); // submit data using post
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // sets the data submitted by post.
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
// Check whether the SSL encryption algorithm exists from the certificate
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false );
$ Access_token = curl_exec ($ ch );
Curl_close ($ ch );
$ Access_token = json_decode ($ access_token, true );
// Obtain the SMS Trust Code www.111cn.net
$ Timestamp = date ('Y-m-d H: I: s ');
$ Param ['app _ id'] = "app_id = x ";
$ Param ['Access _ token'] = "access_token =". $ access_token ['Access _ token'];
$ Param ['timestamp'] = "timestamp =". $ timestamp;
Ksort ($ param );
$ Plaintext = implode ("&", $ param );
$ Sign = rawurlencode (base64_encode (hash_hmac ('sha1', $ plaintext, app_secret, true )));
// Echo $ sign; exit;
$ Code = file_get_contents ("http://api.189.cn/v2/dm/randcode/token? App_id = x & access_token = {$ access_token ['Access _ token']} & timestamp = ". $ timestamp." & sign = ". $ sign );
$ Code = json_decode ($ code, true );
$ Code = $ code ['token'];
Echo $ code;
// Send the verification code
Unset ($ param, $ plaintext, $ sign );
$ Param ['app _ id'] = "app_id = x ";
$ Param ['Access _ token'] = "access_token =". $ access_token ['Access _ token'];
$ Param ['token'] = "token =". $ code;
$ Param ['phone'] = "phone = 15091421612 ";
$ Param ['URL'] = "url = http://wx.podapi.com/test.php ";
$ Param ['Exp _ time'] = "exp_time = 2 ";
$ Param ['timestamp'] = "timestamp =". $ timestamp;
Ksort ($ param );
$ Plaintext = implode ("&", $ param );
$ Sign = rawurlencode (base64_encode (hash_hmac ('sha1', $ plaintext, 'XX', true )));
$ Data = "app_id = x & access_token = {$ access_token ['Access _ token']} & token = {$ code} & phone = 15091421612 & url = token ". $ sign;
$ Ch = curl_init ("http://api.189.cn/v2/dm/randcode/send ");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1); // submit data using post
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // sets the data submitted by post.
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
// Check the SSL www.111cn.net encryption algorithm from the certificate
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false );
$ State = curl_exec ($ ch );
// Var_dump (curl_getinfo ($ ch ));
Curl_close ($ ch );
// Echo $ state; |