Mobile phone to get verification code interface case

Source: Internet
Author: User

        $sms=NewSMS (); $result=$sms->sendmsg ($mobile); if($result[' result '] = = "0") {            $array[' status '] = 0; $array[' comment '] = ' send successfully ... '; $array[' data '] =$result; }Else {            $array[' status '] = 1; $array[' comment '] = ' send failed ... '; }

SMS.class.php

classSmsextendsController {//Expiration Time is 60s    Private $expire= 60; //Send Verification Code     Public functionSendmsg ($mobile) {        $sms=Newm5c_sms (); $content= ' XX company ' Your verification code is: '; //Verification Code        $code=$this-Getverifycode (); //Send Request        $content.=$code; $result=$sms->send ($mobile,$content); if(Strpos($result, "Success") >-1)        {            //Submit Success            $array[' result '] = "0"; $array[' verifymobile '] =$mobile; $array[' verifycode '] =$code; //Verification Code expiration point: 60 seconds later            $verifycodeexpire= Time() +$this-expire; $array[' verifycodeexpire '] = "$verifycodeexpire"; }        Else {            //Commit Failed            $array[' result '] = "1"; }        return $array; }    /** * Get 6-digit verification Code*/    Private functionGetverifycode () {$authnum= ' '; Srand((Double)Microtime() *1000000);//Create a random number feed.        $ychar= "0,1,2,3,4,5,6,7,8,9"; $list=Explode(",",$ychar);  for($i= 0;$i<6;$i++){            $randnum=Rand(0,9);//10+26;            $authnum.=$list[$randnum]; }        return $authnum; }    /** * Returns the saved verification code and expiration time point*/     Public functionGetcodeexpire () {return Array(Cookies (' Verify-code '),Cookies (' Verify-code-expire '),Cookies (' Verify-phone ')            ); }

m5c_sms.class.php

classm5c_sms{/*     * Garbled problem solution, 1, GBK encoding submitted by the first UrlEncode SMS content (contents), and then in the API request, brought into ENCODE=GBK 2, UTF-8 encoded content do urlencode encoding, brought into the encode =utf8 or Utf-8 instance:http://m.5c.com.cn/api/send/index.php?username=xxx&password_md5=xxx&apikey=xxx&      Mobile=xxx&content=%e4%bd%a0%e5%a5%bd%e6%89%8d%e6%94%b6%e7%9b%8a%e9%9f%a6&encode=utf8 * * for content transcoding issues. UTF-8 Turn GBK: $content = Iconv ("UTF-8", "Gbk//ignore", $content);     GBK Turn UTF-8: $content = Iconv ("GBK", "UTF-8", $content);   * * Username username * PASSWORD_MD5 Password * Mobile phone number * Apikey apikey key * Content SMS Contents * StartTime     Unix timestamp, not written for immediate send, http://tool.chinaz.com/Tools/unixtime.aspx (Unix timestamp website) * * Success:msgid submitted successfully.     Error:msgid Commit failed error:missing username user name is empty error:missing password password is empty error:missing apikey Apikey is empty Error:missing recipient mobile number is empty error:missing message content text message contents is empty Error:account is blocked account is disabled error: Unrecognized encoding encoding failed to recognize Error:apikey or Password error apikey or password error error:unauthorized IP address unauthorized IP addresses Error:account balance is insufficient insufficient balance  **/    Private $encode= ' UTF-8 ';//page encoding and SMS content encoded as GBK. Important NOTE: If you get garbled after submitting SMS, please change GBK to UTF-8 test. If the program page is encoded in the format: ASCII/GB2312/GBK the place is GBK. If this page is encoded as UTF-8 or needs to support Unicode such as traditional, Arabic, please write here as: UTF-8    Private $username=' XXXXXX ';  //User name    Private $password=' XXXXX '; //private $password _md5 = ' 1adbb3178591fd5bb0c248518f39bf6d '; 32-bit MD5 password encryption, case insensitive    Private $apikey= ' b20abdab8b1d02ae8f1f5f7a38d6716d ';//apikey key (please login http://m.5c.com.cn SMS Platform--account management--copy apikey in my message)     Public functionSend$mobile,$content) {        //$mobile = ' 18610310068 '; Mobile phone number, only one number: 13800000001. Send multiple numbers: 13800000001,13800000002,... N.        Use a comma-delimited half-width.  $content = ' Hello, your verification code is: 12345 "Mei Lian"; To send the message content, special note: The signature must be set, the Web code application needs to add a "graphics identification code."         $password _md5=MD5($this-password); $contentUrlEncode=UrlEncode($content);//perform urlencode encoding, $content = UrlDecode ($content); Decode        $result=$this->sendsms ($this->username,$password _md5,$this->apikey,$mobile,$contentUrlEncode,$this->encode);//to send//echo $result; Output result content, view return value, Success is success, error is wrong, (error content is shown above)        /*if (Strpos ($result, "success") >-1) {//Submit success//logic code} else { Commit failed//logic code}*/        return $result; }    //Send Interface    Private functionSendsms ($username,$password _md5,$apikey,$mobile,$contentUrlEncode,$encode)    {        //Send link (username, password, apikey, mobile number, content)        $url= "http://m.5c.com.cn/api/send/index.php?";//if the connection times out, your server may not support domain name resolution, please change the following connection: "m.5c.com.cn" to IP: "115.28.23.78"        $data=Array        (            ' Username ' =$username, ' password_md5 ' =$password _md5, ' apikey ' =$apikey, ' mobile ' =$mobile, ' content ' =$contentUrlEncode, ' encode ' =$encode,        ); $result=$this->curlsms ($url,$data); return $result; }    Private functionCurlsms ($url,$post _fields=Array())    {        $ch=Curl_init (); curl_setopt ($ch, Curlopt_url,$url);//URL address retrieved with PHP (value will be used as a string)curl_setopt ($ch, Curlopt_returntransfer, 1);//use curl_setopt to get page content or submit data, and sometimes you want the returned content to be stored as a variable instead of a direct output, which you want to return as a variablecurl_setopt ($ch, Curlopt_timeout, 30);//30-second timeout limitcurl_setopt ($ch, Curlopt_header, 1);//Direct file header output is visible. curl_setopt ($ch, Curlopt_post, 1);//set this option to a 0 non-value, this post is the normal application/x-www-from-urlencoded type, most of which is called by the HTTP table. curl_setopt ($ch, Curlopt_postfields,$post _fields);//A string of all data for the post operation.         $data= Curl_exec ($ch);//fetch the URL and pass it to the browserCurl_close ($ch);//Freeing Resources        $res=Explode("\r\n\r\n",$data);//explode him into an array .        return $res[2];//the array is then returned here. }

SMSMessage.class.php

classSmsmessage {//Send Message     Public functionSendmsg ($mobile,$content) {        $sms=Newm5c_sms (); $result=$sms->send ($mobile,$content); if(Strpos($result, "Success") >-1)        {            //Submit Success            return Array(                ' Result ' =true, ' msg ' =$result            ); } Else {            //Commit Failed            return Array(                ' Result ' =false, ' msg ' =$result            ); }        return $result; }

Mobile phone to get verification code interface case

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.