params['sms']["smsKey"], Yii::$app->params['sms']["smsSecret"])->asDefaultClient(); $query = [ 'PhoneNumbers' => $mobile, 'SignName' => $signName, 'TemplateCode' => $templateCode, ]; if ($templateParam) { $query['TemplateParam'] = json_encode($templateParam); } $result = AlibabaCloud::rpc() ->regionId("cn-hangzhou") // 指定请求的区域,不指定则使用客户端区域、默认区域 ->product('Dysmsapi') // 指定产品 ->version('2017-05-25') // 指定产品版本 ->action('SendSms') // 指定产品接口 ->method('POST') // 指定请求方式 ->options([ 'query' => $query, ]) ->request(); // 发起请求并返回结果对象,请求需要放在设置的最后面 $result = $result->toArray(); AppLog::DEBUG('短信发送结果:' . '
' . print_r($result, 1) . ''); return $result; } catch (ClientException $exception) { AppLog::DEBUG('短信发送出错:' . $exception->getErrorMessage()); return false; } catch (ServerException $exception) { AppLog::DEBUG('短信发送出错:' . $exception->getErrorMessage()); return false; } } /** * @return string */ private function getSignName() { $smsConfig = Yii::$app->params['sms']; return isset($smsConfig['smsSignName'])?$smsConfig['smsSignName']:''; } /** * 手机验证码 * 模版内容: 验证码${code},您正在注册成为新用户,感谢您的支持! * 申请说明: 用户注册验证码 * 模版CODE: SMS_181866843 * @param $phone * @param $code * @param $signName * @return mixed */ public function sendRegCode($phone, $code) { //return true; $signName = $this->getSignName(); return $this->send($phone, $signName, "SMS_181866843", ["code" => $code]); } /** * 登录验证码 * 模版内容: 模版CODE: SMS_181866846 * 模版内容: 尊敬的用户,您的登录码为:${code},请勿泄漏于他人! * @param $phone * @return mixed */ public function sendLoginCode($phone, $code) { //return true; $signName = $this->getSignName(); return $this->send($phone, $signName, "SMS_181866846", ["code" => $code]); } /* * 模版CODE: SMS_181853499 * 尊敬的车主,您的爱车正在${maintainer}维修,预计${dateTime}维修完成,预估维修内容:${repairPlan},预估维修费:${repairPrice},维修厂地址:${address},联系电话:${tel} * */ public function sendSubmitInfo($phone, $postData) { //return true; $signName = $this->getSignName(); return $this->send($phone, $signName, "SMS_181853499", $postData); } /* * 模版CODE: SMS_181853499 * 【XX车管家】尊敬的车主,您的爱车正在${maintainer}维修,预计${dateTime}维修完成,预估维修内容:${repairPlan},预估维修费:${repairPrice},维修厂地址:${address},联系电话:${tel} * */ public function sendFinishInfo($phone, $postData) { //return true; $signName = $this->getSignName(); return $this->send($phone, $signName, "SMS_181853499", $postData); } }