PHP Sky-wing open platform SMS delivery Interface implementation method _php skills

Source: Internet
Author: User
Tags sha1

This paper illustrates the implementation method of SMS delivery interface of PHP sky-wing open platform. Share to everyone for your reference. The specific analysis is as follows:

Temporary demand, studied the sky Wing development platform of things, used to send the verification code is good, but the daily limit is not much, so very chicken, but to ensure that 100% to buy the words or pretty expensive, the code did not do any optimization processing, just test whether the interface can be implemented, with the students remember to improve the code, Just finished the eldest brother said is a chicken, no, the code in the blog record, the code is as follows:

Copy Code code as follows:
<?php
//
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 Post submitted data
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
Check to see if 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 ']}&timestamp= '. $timestamp. " &sign= ". $sign);
$code = Json_decode ($code, true);
$code = $code [' token '];
Echo $code;
Issued 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&timestamp={$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 Post submitted data
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
Check to see if 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 help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.