mobile 手机号码 //['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time] function smsSend($sms) { return '11111'; return $this->sendMsg($sms->mobile,['code'=>$sms->code],'code'); } function smsCheck($sms) { return $this->sendMsg($sms['mobile'],['code'=>$sms['code']],'code'); if($this->sendMsg($sms['mobile'],['code'=>$sms['code']],'code')){ $sms = \app\common\model\Sms::create(['event' => $sms['event'], 'mobile' => $sms['mobile'], 'code' => $sms['code'], 'ip' => '', 'createtime' => $sms['createtime']]); } } //@mobile 手机号码 //@param 短信发送参数 //@template 短信发送模板编号key值 private function sendMsg($mobile,$param,$template){ $config = \config('alisms'); // return json($config); if(empty($param)||!isset($config)||empty($config)){ return false; } AlibabaCloud::accessKeyClient($config['accessKeyId'], $config['accessSecret']) ->regionId($config['regionId']) ->asGlobalClient(); $TemplateCode = isset($config['TemplateCode'][$template])?$config['TemplateCode'][$template]:$config['TemplateCode']['code']; try { $result = AlibabaCloud::rpcRequest() ->product('Dysmsapi') ->version('2017-05-25') ->action('SendSms') ->method('POST') ->options([ 'query' => [ 'PhoneNumbers' => $mobile, 'SignName' => $config['SignName'], 'TemplateCode' => $TemplateCode, 'TemplateParam' => json_encode($param) ], ]) ->request(); if($result->Code=="OK"){ return true; }else{ return false; } print_r($result->toArray()); } catch (ClientException $e) { return false; echo $e->getErrorMessage() . PHP_EOL; } catch (ServerException $e) { return false; echo $e->getErrorMessage() . PHP_EOL; } } }