Text message verification code who has an API on the website now has only one front-end page. could you tell me how to write PHP? I have never touched anyone before. if anyone can, add my QQ804135715 to solve this problem. I 'd like to be a master.
Reply to discussion (solution)
You haven't used the api provided by the text message service provider.
There should be a demo
The SMS verification code for www.yuntongxun.com is fast, with an average of about 8 seconds. The following are class files
AccountSid = $ accountsid; $ this-> AccountToken = $ accounttoken; $ this-> AppId = $ appid; $ this-> TemplateId = $ tempid; $ this-> Batch = date ('ymdhis ', time ();}/*** send SMS */public function sendMsg ($ to, $ datas) {// splice the request body $ data = ""; for ($ I = 0; $ I
TemplateId. "', 'appid': '$ this-> appId', 'datas ':[". $ data. "]}"; // upper case sig parameter $ sig = strtoupper (md5 ($ this-> AccountSid. $ this-> AccountToken. $ this-> Batch); // Generate the request URL $ url = "https: // $ this-> ServerIP: $ this-> ServerPort/$ this-> SoftVersion/Accounts/$ this-> AccountSid/SMS/TemplateSMS? Sig = $ sig "; // Generate authorization: master account Id + English colon + timestamp. $ Authen = base64_encode ($ this-> AccountSid. ":". $ this-> Batch); // Generate the header $ header = array ("Accept: application/json", "Content-Type: application/json; charset = utf-8 ", "Authorization: $ authen"); // send a request $ result = $ this-> curl_post ($ url, $ body, $ header); $ datas = json_decode ($ result ); /* if ($ datas = FALSE) {$ datas = new stdClass (); $ datas-> statusCode = '20180101 '; $ datas-> statusMsg = 'return package body error';} * // reload the data if ($ dat As-> statusCode = 0) {$ datas-> TemplateSMS = $ datas-> templateSMS; unset ($ datas-> templateSMS);} return $ datas ;} /*** initiate HTTPS request */private function curl_post ($ url, $ data, $ header, $ post = 1) {// initialize curl $ ch = curl_init (); // parameter settings $ res = curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); Curl_setopt ($ ch, CURLOPT_POST, $ post); if ($ post) curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header); $ result = curl_exec ($ ch); curl_close ($ ch); return $ result ;}} /*** application instance // primary account $ accountSid = 'xxxxxx'; // primary account Token $ accountToken = 'xxxxxx'; // application Id $ appId = 'xxxxxx '; // template Id $ templateId = 'xxxxxx'; $ Sms_yuntongxun = new Sms_yunton Gxun ($ accountSid, $ accountToken, $ appId, $ templateId); print_r ($ Sms_yuntongxun-> sendMsg ('123', array (13612345678, 'register a new user ', 15); */?>
Text message providers should have interfaces, just write them according to the demo they gave.