PHP使用网易短信验证码使用详解
来源:互联网 发布:淘宝卖家如何隐藏差评 编辑:程序博客网 时间:2024/05/22 13:01
<?php
/**
* 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;
$checkSum = sha1($appSecret . $nonce . $curTime);
$data = array(
);
$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;
?>
/**
* 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;
?>
0 0
- PHP使用网易短信验证码使用详解
- 网易云信-网易验证码短信,网易通知类短信的使用
- 使用网易云通信发送验证码,通知类型短信
- 网易云信短信验证码验证php实现
- Java使用【网易云信】短信接口,给手机用户发送并校验验证码
- php使用阿里大于短信平台发送验证码记录
- 网易云短信接口 ---- 短信验证码
- 使用mob实现短信验证码验证
- Mob- 短信验证使用
- 网易云短信验证
- 验证码短信接口如何使用
- 使用第三方的短信验证码
- 使用ShareSDK的SMSSDK短信验证码
- mob短信验证码SMSSDK的使用
- 使用mob获取短信验证码
- 使用阿里大于发送短信验证码
- 阿里大于短信验证码简单使用
- 阿里大于短信验证码简单使用
- rac通过tnsnames.ora实现负载均衡 scan-vip访问
- 剑指offer——从上往下打印二叉树
- Spring 源码分析(一)
- java获取指定日期所在周的第一天和最后一天
- 面试1
- PHP使用网易短信验证码使用详解
- Volley源码阅读之缓存分发器(CacheDispatcher)工作原理
- Node.js 特点
- Excel 工具类
- Caffe-Face extractDeepFeature C++
- ISE中RTL Schematic和Technology Schematic之间的区别
- Python——dict
- [Lpp]PHP的日期/时间函数
- Android Studio系列-签名打包