ThinkPHP3.2.3整合傳送簡訊驗證碼____PHP

來源:互聯網
上載者:User

說明:

本例使用的是美聯軟通的簡訊發送平台,網址是:http://web.5c.com.cn

每條價格在幾分錢,買的量越大,優惠力度越大。


主要代碼

1、在\ThinkPHP\Library\Org檔案夾下,建立Msg.class.php檔案,代碼如下:

<?/*--------------------------------功能:PHP HTTP介面 傳送簡訊修改日期:2013-05-08說明:http://m.5c.com.cn/api/send/?username=使用者名稱&password=密碼&mobile=手機號&content=內容&apikey=apikey狀態:發送成功success:msgid發送失敗error:msgid注意,需curl支援。傳回值說明success:msgid提交成功,發送狀態請見4.1error:msgid提交失敗error:Missing username使用者名稱為空白error:Missing password密碼為空白error:Missing apikeyAPIKEY為空白error:Missing recipient手機號碼為空白error:Missing message content簡訊內容為空白error:Account is blocked帳號被禁用error:Unrecognized encoding編碼未能識別error:APIKEY or password errorAPIKEY 或密碼錯誤error:Unauthorized IP address未授權 IP 位址error:Account balance is insufficient餘額不足error:Black keywords is:黨中央屏蔽詞--------------------------------*/function sendmsg($vcode,$mobile){    $username = '*****';//使用者帳號    $password = '******';//密碼    $apikey = '***********';//api key    //$mobile = '18612345678,18988888888,18688888888';//號手機碼     //var_dump($vcode);exit;    $content = '您的簡訊驗證碼是:'.$vcode.'【湖南****資訊科技有限公司】';//內容    //即時發送    $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,//使用者帳號        'password'=>$password,//密碼        'mobile'=>$mobile,//號碼        'content'=>$content,//內容        'apikey'=>$apikey,    //apikey    );    $result= curlSMS($url,$data);//POST方式提交    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秒    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、控制器

//傳送簡訊import('Org.Msg');$vcode=mt_rand(000000,999999);$mobile=I('post.mobile');$result=sendmsg($vcode,$mobile);//解釋下參數: 參數1---驗證碼, 參數2----手機號;if($result===false){    //發送失敗    echo '傳送簡訊失敗,請重試';exit;}else{    //發送成功    echo '簡訊驗證碼已發送';exit;}

有圖有真相



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.