1. Purchase Service
I purchased the API service that was promoted in Baidu. Buy as required, then get your own apikey.
2. Modify the provided code to integrate into the project:
<?php /** * * * Send SMS * * * * /class Phonemsg{public $ak = ' Apikey: *************** '; Public Function sendphonemsg ($phonenumber, $sendmsg) { $ch = Curl_init (); $url = ' http://apis.baidu.com/kingtto_media/106sms/106sms?mobile= '. $phonenumber. ' &content= '. $sendmsg; $header = Array ($ak); curl_setopt ($ch, Curlopt_httpheader , $header); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_url, $url); $res = curl_exec ($ch); return $res; } }? >
<?php /** * * send mobile phone verification short Note * * * /session_start (); Generate random Code $rand = substr ($randStr, 0,6); $randnum = Array (); for ($i =0; $i <5; $i + +) { $randnum []=rand (0,9);// } $uniqid = implode ($randnum); $_session[' validnum '] = $uniqid; $validNum = UrlEncode (' Instant print ' Your verification code is: '. $uniqid. '. If you do not operate, please ignore this message '); Require_once "phoneMsg.class.php"; $send = new Phonemsg (); There is a return value that can get the return information $res = $send->sendphonemsg ($_post[' PhoneNumber '), $validNum); >
PHP-Send SMS