Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of sending SMS CAPTCHA by PHP

Shulou Source: shulou.com Published: 2022-06-02 21:26:26 10月30日 Update

This article mainly explains "what is the method of PHP to send SMS CAPTCHA". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the method of sending SMS CAPTCHA by PHP"?

1. Create HTML and js files.

2. Create a "Msm.php" file with the content of "public function sendmsm () {...}".

3. Send a HTTP request through CURL.

Example

/ * send SMS * @ author * @ return [type] [description] * / public function sendmsm () {$phone = input ('phone'); if (! $phone) {return WPreturn (' Please enter your cell phone number!' ,-1);} $code = rand (1000 ~ 9999); $_ SESSION ['code'] = $code; $res = sendmessage ($code, $phone); if ($res) {return WPreturn (' sent successfully', 1);} else {return WPreturn ('failed to send CAPTCHA!' ,-1);}} / * Class name: ChuanglanSmsApi * function: blue-creating SMS API request class * details: construct blue-creating SMS API request to obtain remote HTTP data * description: * the following code is only sample code and uses a third-party blue SMS API to send SMS messages. * this code is for learning only and provides a reference only. * / public function sendmessage ($code, $telephone) {$conf = getconf (''); if (! $code) {return false;} if (! $telephone) {return false;} $content = "your verification code is: {$code}, if you do not do it yourself, please ignore this SMS." / / Blue-creating API parameters $postArr = array ('account' = > $conf [' msm_appkey'], 'password' = > $conf [' msm_secretkey'], 'msg' = > urlencode ($content),' phone' = > $telephone, 'report' = > true); $result = $this- > curlPost ("http://smssh2.253.com/msg/send/json", $postArr); $json = json_decode ($result); if ($json-> code! = 0) {return false;} else {return true }} / * send HTTP request via CURL * @ param string $url / / request URL * @ param array $postFields / / request parameters * @ return mixed * * / private function curlPost ($url,$postFields) {$postFields = json_encode ($postFields); $ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json) Charset=utf-8' / / json version requires Content-Type: application/json;); curl_setopt ($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt ($ch, CURLOPT_TIMEOUT,60); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0) $ret = curl_exec ($ch); if (false = = $ret) {$result = curl_error ($ch);} else {$rsp = curl_getinfo ($ch, CURLINFO_HTTP_CODE); if (200! = $rsp) {$result = "request status". $rsp. "". Curl_error ($ch);} else {$result = $ret;}} curl_close ($ch); return $result;} so far, I believe you have a deeper understanding of "what is the method of sending SMS CAPTCHA by PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: SMS verification method interface code content learning parameters just file practical deeper success interest function number example practicality reality mobile phone Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple MariaDB Docker Shulou Information