Home >Backend Development >PHP Tutorial >PHP Tianyi open platform SMS sending interface implementation method, PHP SMS sending_PHP tutorial

PHP Tianyi open platform SMS sending interface implementation method, PHP SMS sending_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:02822browse

implementation method of php Tianyi open platform SMS sending interface, php SMS sending

The example in this article describes the implementation method of the SMS sending interface of the PHP Tianyi open platform. Share it with everyone for your reference. The specific analysis is as follows:

For temporary needs, I studied the Tianyi development platform. It is good for sending verification codes, but the daily limit is not much, so it is useless. But if you guarantee 100% arrival, it is still quite expensive to buy. The code does not Any optimization processing is done just to test whether the interface can be implemented. Students who use it remember to improve the code. I just finished writing it and the boss said it was useless. No need. The code is recorded in the blog. The code is as follows:

Copy code The code is as follows:
//
date_default_timezone_set('PRC');
//Get 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);//Use post to submit data
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//Set 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);
//Get SMS trust code
$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']}×tamp=".$timestamp."&sign=".$ sign);
$code = json_decode($code,true);
$code = $code['token'];
echo $code;
//Send 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=http://wx.podapi.com/test.php&exp_time=2×tamp={$timestamp}&sign=" .$sign;
$ch = curl_init("http://api.189.cn/v2/dm/randcode/send");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);//Use post to submit data
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//Set 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);
$state = curl_exec($ch);
//var_dump(curl_getinfo($ch));
curl_close($ch);
//echo $state;
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/931543.htmlTechArticlephp Tianyi open platform SMS sending interface implementation method, php SMS sending This article describes the php Tianyi open platform SMS sending interface Implementation method. Share it with everyone for your reference. Specifically...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn