1. 程式人生 > >網易雲信簡訊驗證碼驗證php實現

網易雲信簡訊驗證碼驗證php實現

有評論問我怎麼用,,,於是簡單更新了一下使用方法。。。。

網易雲信5分一條,阿里大於4分5一條,但是網易雲信自帶驗證系統,阿里大於需要自己指定驗證碼,自己做驗證,但是,,,,阿里大於可以自己定義簽名,而網易雲信只能使用預設的【雲簡訊】,而且阿里大於的簡訊模板稽核很快,,,網易雲信媽的,。,,稽核了兩天,這還是我聯絡了客服妹子,要不,,,好了。。。不黑網易了。。。接下來上程式碼。

<?php
/**
 * Created by PhpStorm.
 * User: leif
 * Date: 2016/9/10
 * Time: 9:20
 */

//Auth 類,直接引入就行

class Auth
{
//將你註冊的 key和 secret 定義好。 const APP_KEY = 'your key'; const APP_SECRET = 'tour secret'; //傳送驗證碼函式,傳入手機號即可 public function SendSmsCode($mobile = ""){ $appKey = self::APP_KEY; $appSecret = self::APP_SECRET; $nonce = '100'; $curTime = time(); $checkSum = sha1($appSecret
. $nonce . $curTime); $data = array( 'mobile'=> $mobile, ); $data = http_build_query($data); $opts = array ( 'http' => array( 'method' => 'POST', 'header' => array( 'Content-Type:application/x-www-form-urlencoded;charset=utf-8'
, "AppKey:$appKey", "Nonce:$nonce", "CurTime:$curTime", "CheckSum:$checkSum" ), 'content' => $data ), ); $context = stream_context_create($opts); $html = file_get_contents("https://api.netease.im/sms/sendcode.action", false, $context); echo $html; } //驗證碼校驗函式,傳入手機號,以及該手機號反饋給你的驗證碼, public function CheckSmsYzm($mobile = "",$Code=""){ $appKey = self::APP_KEY; $appSecret = self::APP_SECRET; $nonce = '100'; $curTime = time(); $checkSum = sha1($appSecret . $nonce . $curTime); $data = array( 'mobile'=> $mobile, 'code' => $Code, ); $data = http_build_query($data); $opts = array ( 'http' => array( 'method' => 'POST', 'header' => array( 'Content-Type:application/x-www-form-urlencoded;charset=utf-8', "AppKey:$appKey", "Nonce:$nonce", "CurTime:$curTime", "CheckSum:$checkSum" ), 'content' => $data ), ); $context = stream_context_create($opts); $html = file_get_contents("https://api.netease.im/sms/verifycode.action", false, $context); } }