预留模板到货短信

This commit is contained in:
liu 2024-06-15 18:46:37 +08:00
parent 80d24acad4
commit 1976367b3c
3 changed files with 39 additions and 10 deletions

View File

@ -314,7 +314,7 @@ class StoreOrderLogic extends BaseLogic
} }
public function dealSendSms($param) public function dealSendSms($param,$type = 0)
{ {
$code = generateRandomCode(); $code = generateRandomCode();
$phone = User::where('id',$param['uid'])->value('mobile'); $phone = User::where('id',$param['uid'])->value('mobile');
@ -322,8 +322,12 @@ class StoreOrderLogic extends BaseLogic
throw new \Exception('用户未设置手机号'); throw new \Exception('用户未设置手机号');
} }
$template = getenv('SMS_TEMPLATE'); $template = getenv('SMS_TEMPLATE');
if($type){
$check =(new SmsService())->client($phone,$template,$code,1);
}else{
$check =(new SmsService())->client($phone,$template,$code); $check =(new SmsService())->client($phone,$template,$code);
}
if($check){ if($check){
$remark = $param['uid'].'_smsPay'; $remark = $param['uid'].'_smsPay';
Cache::set($remark,$code,5*60); Cache::set($remark,$code,5*60);

View File

@ -45,11 +45,12 @@ class SmsService
} }
public function client($phone,$template,$code) public function client($phone,$template,$code,$type = 0)
{ {
try{ try{
$easySms = new EasySms($this->config); $easySms = new EasySms($this->config);
if($type){//预留发送到货短信
$res = $easySms->send($phone, [ $res = $easySms->send($phone, [
'content' => '您的验证码为: '.$code, 'content' => '您的验证码为: '.$code,
'template' => $template, 'template' => $template,
@ -57,6 +58,17 @@ class SmsService
'code' => $code 'code' => $code
], ],
]); ]);
}else{
$res = $easySms->send($phone, [
'content' => '您的验证码为: '.$code,
'template' => $template,
'data' => [
'code' => $code
],
]);
}
if($res && $res['aliyun']['status'] == 'success'){ if($res && $res['aliyun']['status'] == 'success'){
return true; return true;
}else{ }else{

View File

@ -374,4 +374,17 @@ class StoreOrderController extends BaseAdminController
return $this->fail('支付失败'); return $this->fail('支付失败');
} }
public function stocking()
{
$uid = $this->request->post('uid');
$res = (new StoreOrderLogic())->dealSendSms(['uid'=>$uid],1);
if($res){
return $this->success('发送成功',[],0,1);
}else{
return $this->fail('发送失败');
}
}
} }