阿里大鱼 短信处理

https://dysms.console.aliyun.com/dysms.htm?spm=5176.2020520001.aliyun_topbar.3.79334bd3nxBn2Z#/dayu/application/test
阿里短信 页面网页 (登录状态)

在 : 应用测试 栏目里面有php的示例代码,并且此处可以进行短信发送测试

我在项目中是如下处理:

public static function sends(array $param) {
$client = new TopClient();
$client->appkey = '235110';//虚假
$client->secretKey = '0ad54d2c185';//虚假
$req = new AlibabaAliqinFcSmsNumSendRequest();
$req->setExtend('');
$req->setSmsType('normal');
$req->setSmsFreeSignName($param['signName']);
$req->setSmsParam($param['smsParam']);
$req->setRecNum($param['phone']);
$req->setSmsTemplateCode($param['templCode']);
try {
$resp = $client->execute($req);
if ($resp->result->success) {
return true;
}
return false;
} catch (Exception $e) {
return false;
}
}
在项目使用中应该是将阿里的php包放在目录中,引用了(这里没有自己核实,但是应该不差多少)
//前台手机验证码
public function telCode(Request $r)
{
$data = $r->all();
$phone = $data['phone'];
$code = (string)mt_rand(10000, 99999);
$param = [
'smsParam' => json_encode(['code' => $code, 'product' => '医疗系统']),
'phone' => $phone,
'signName' => '身份验证',
'templCode' => 'SMS_1424'//虚假
];
$tel = $param['phone'];
//验证手机号是否已发送过验证码
$return = User::checkTel($tel);
if ($return) {
//已有验证码就再次发送并修改验证码
if (\App\Library\Lib\alidayu\Sms::sends($param)) {
$res = User::where('admin_tel', $tel)
->update(['admin_code' => $code]);
if ($res) {
return ['code' => 1000, 'data' => ['message' => '手机验证码发送成功!']];
} else {
return ['code' => 1002, 'data' => ['message' => '系统繁忙,请重新发送!']];
}
} else {
return ['code' => 1001, 'data' => ['message' => '系统繁忙,请稍后重试!']];
}
} else {
//将验证码存入数据库
$res = User::create(['admin_tel' => $tel, 'admin_code' => $code]);
if ($res) {
if (\App\Library\Lib\alidayu\Sms::sends($param)) {
return ['code' => 1000, 'data' => ['message' => '手机验证码发送成功!']];
} else {
return ['code' => 1001, 'data' => ['message' => '手机验证码发送失败!']];
}
} else {
return ['code' => 1002, 'data' => ['message' => '系统繁忙请重试!']];
}
}
}
posted @ 2018-08-02 16:10  LvFish  阅读(249)  评论(0编辑  收藏  举报