ThinkPHP3.2.3 integration send mobile phone SMS authentication Code ____php

Source: Internet
Author: User
Tags sendmsg

Description

The use of this example is the United States and soft text messaging platform, the URL is: http://web.5c.com.cn

Each price in a few cents, the greater the amount of purchase, the greater the intensity of concessions.


Main code

1, in the \thinkphp\library\org folder, create the Msg.class.php file, the code is as follows:

? /*--------------------------------function: PHP HTTP interface to send SMS Modified Date: 2013-05-08 Description: Http://m.5c.com.cn/api/send/?username= username &

amp;password= Password &mobile= mobile phone number &content= content &apikey=apikey Status: Send successful Success:msgid send failure error:msgid attention, need curl support. The return value indicates the success of Success:msgid commit, send status See 4.1 error:msgid commit failed error:missing username username is empty Error:missi				ng password Password is empty error:missing apikey apikey is empty error:missing recipient cell phone number is empty error:missing message content SMS content is empty Error:account is blocked account is disabled error:unrecognized encoding encoding failed to recognize Error:apikey or password error apike 				Y or password error error:unauthorized IP address error:account balance is insufficient balance insufficient error:black keywords is: Central Committee		Shielding words--------------------------------/function sendmsg ($vcode, $mobile) {$username = ' * * * *;	User account $password = ' Hu Jintao ';	Password $apikey = ' *********** ';	API Key//$mobile = ' 18612345678,18988888888,18688888888 '; Phone Code//Var_dump ($vcode); exit; $content = ' Your SMS Verification code is: '. $vcode. '		"Hunan * * * * * Information Technology Co., Ltd.";
    Content//Instant Send $result = Sendsms ($username, $password, $mobile, $content, $apikey);
    if ($result) {return false;
    }else{return true;
    }//echo $vcode;

echo $result;
    function Sendsms ($username, $password, $mobile, $content, $apikey) {$url = ' http://m.5c.com.cn/api/send/? '; $data = Array (' username ' => $username,//user account ' password ' => $password,//password ' mobile
    ' => $mobile,//number ' content ' => $content,//Contents ' Apikey ' => $apikey,//apikey);			$result = Curlsms ($url, $data);
Post method to submit return $result;
    function Curlsms ($url, $post _fields=array ()) {$ch = Curl_init ();
    curl_setopt ($ch, Curlopt_url, $url);
    curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, curlopt_timeout, 3600);
    60 Seconds curl_setopt ($ch, curlopt_header,1);
  curl_setopt ($ch, Curlopt_referer, ' http://www.xxoo.com ');  curl_setopt ($ch, curlopt_post,1);
    curl_setopt ($ch, Curlopt_postfields, $post _fields);
    $data = curl_exec ($ch);
    Curl_close ($ch);
$res = Explode ("\r\n\r\n", $data);
return $res [2];
}//$vcode = rand (1000,9999);
$mobile = $_post[' mobile ']; Sendmsg ($vcode, $mobile);?>


2. Controller

Send SMS
import (' org.msg ');
$vcode =mt_rand (000000,999999);
$mobile =i (' post.mobile ');
$result =sendmsg ($vcode, $mobile);//Explain the parameters: Parameter 1---Verification code, parameter 2----mobile phone number;
if ($result ===false) {
    //Send failed
    echo ' Send SMS failed, please try again '; exit;
} else{
    ///Send Success
    echo ' SMS authentication code sent '; exit;
}

There's a picture of the truth.



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.