systemConfig('aliyun_AccessKeyId'), // 您的 AccessKey Secret "accessKeySecret" => systemConfig('aliyun_AccessKeySecret') ]); // 访问的域名 $config->endpoint = "dysmsapi.aliyuncs.com"; return new Dysmsapi($config); } /** * @param string $phone * @param string $templateId * @param array $data * @return array[]|bool|mixed */ public function send(string $phone, string $templateId, array $data = []) { if (empty($phone)) { return $this->setError('电话号码不能为空'); } //验证码只支持一个参数 if ($templateId == 'VERIFICATION_CODE') { unset($data['time']); } if (isset($data['site'])) { unset($data['site']); } $client = self::createClient("accessKeyId", "accessKeySecret"); $temp = app()->make(SystemNoticeConfigRepository::class)->getSmsTemplate($templateId); if (!$temp) throw new ValidateException('模板不存在:'. $templateId); $sendSmsRequest = new SendSmsRequest([ "phoneNumbers" => $phone, "signName" => systemConfig('aliyun_SignName'), "templateCode" => $temp, "templateParam" => json_encode($data), ]); $runtime = new RuntimeOptions([]); try { // 复制代码运行请自行打印 API 的返回值 $resp = $client->sendSmsWithOptions($sendSmsRequest, $runtime); } catch (Exception $error) { if (!($error instanceof TeaError)) { $error = new TeaError([], $error->getMessage(), $error->getCode(), $error); } // 如有需要,请打印 error throw new ValidateException('【阿里云平台错误提示】:'.$error->message); //$resp = Utils::assertAsString($error->message); } if (isset($resp) && $resp->body->code !== 'OK') { throw new ValidateException('【阿里云平台错误提示】:'.$resp->body->message); } return 'ok'; } public function open(){} public function modify(string $sign = null , string $phone, string $code){} public function info(){} public function temps(int $page = 0, int $limit = 10, int $type = 1){} public function apply(string $title, string $content, int $type){} public function applys(int $tempType, int $page, int $limit){} public function record($record_id){} }