作者:多米音乐_34063629 | 来源:互联网 | 2023-08-14 16:35
/**
* Created by PhpStorm.
* User: leif
* Date: 2016/9/10
* Time: 9:20
*/
//Auth 类,直接引入就行
class Auth
{
//将你注册的 key和 secret 定义好。
//这是你注册网易云信获得的xxxxxxxxx为你自己需要填写的地方
const APP_KEY = 'xxxxxxxxx';
const APP_SECRET = 'xxxxxxxxxxxxx';
//发送验证码函数,传入手机号即可
public function SendSmsCode($mobile = ""){
$appKey = self::APP_KEY;
$appSecret = self::APP_SECRET;
//填写短信
//下方填写的是模板id
$nOnce= 'xxxxxxxxxxxxxxxxx';
$curTime = time();
$checkSum = sha1($appSecret . $nonce . $curTime);
$data = array(
'mobile'=> $mobile,
//下方填写的是模板id
'templateid'=>xxxxxxxxxxxxxxx,
);
$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);
return $html;
}
}
$a = new Auth();
//电话号码发送 取消注释就可以发送了输入你想发送的电话号码
// echo $a->SendSmsCode(xxxxxxxxxxxxx);
//电话号码验证模板 200为正确,取消注释就验证,第一个xxxx是电话号码,第二个xxxxxx是验证码
// $code= $a->CheckSmsYzm(xxxxxxx,xxxxxxxx);
// $c = json_decode($code);
// echo $c->code;
?>