/**
* 阿里云发送获取短信验证码
* @PROJECT_NAME 凯能婷电商APP
* Notes:
* @param:
* User: CHAOQUN
* Date: 2019/12/25
* Time: 2:33
*/
public function send_sms()
{
$sms=new SmsDemo();
$phone=input('phone');
if (empty($phone)){
json_fail('请输入手机号');
}
//获取验证码方法
$code= numberCaptcha();
set_time_limit(0);
header('Content-Type: text/plain; charset=utf-8');
$response = $sms->sendSms($phone, $code);//dump($response);exit;
//$response = (new \SmsDemo)::sendBatchSms();
$response = $sms->querySendDetails($phone);
// 保存验证码
Cache::set($phone,$code,300);
json_success($code);
}
/**
* @function 调用aliyun 发送手机验证码
* @return int
* @接口地址 http://auction.jiangliping.com/api/registered/send_dx
* @type POST
* @return json
*/
public function send_dx()
{
// 加载extend文件夹里面的文件
// Loader::import('aliyun.api_demo.SmsDemo', EXTEND_PATH);
$sms = new SmsDemo();
$phone = input('mobile');
if (empty($phone)){
json_fail('缺少手机号');
}
//获取验证码方法
$code= numberCaptcha();
// 调用示例:
set_time_limit(0);
header('Content-Type: text/plain; charset=utf-8');
//查询短信发送总条数 可以到方法里设置要查询的时间段
$res = $sms->querySendDetails($phone);
if ($res->Code =='OK'){
$count=$res->TotalCount;
if ($count>=5){
json_fail('每天最多获取5次');
}
}else{
json_fail($res->Message);
}
//单条发送短信
$response =$sms->sendSms($phone, $code);
//批量发送短信
// $response = (new \SmsDemo)::sendBatchSms();
Cache::set(trim($phone),$code,600);
// 保存验证码
if ($response->Code=='OK'){
json_success('获取成功');
}
json_fail('获取验证码失败');
}
/**
* 腾讯
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* 发送手机验证码
*/
public function sendCaptcha()
{
$mobile = input('post.mobile');
if (!$mobile) {
json_fail('获取手机号失败!');
}
//取4位验证码
$captcha_num = numberCaptcha();
$templ_id = 423175;
$params = array($captcha_num);
$result = $this->sendSms($mobile, $templ_id, $params);
if ($result) {
$result = json_decode($result, true);
}
//判断是否发送短信成功
if ($result['result'] == 0) {
Cache::set(trim($mobile), $captcha_num, 300);
json_success('发送成功');
} else {
json_fail($result['errmsg']);
}
}