secret_id = $config['secret_id'] ?? ''; $this->secret_key = $config['secret_key'] ?? ''; $this->sign = $config['sign'] ?? ''; $this->app_id = $config['app_id'] ?? ''; } /** * 发送短信 * @return bool|mixed */ public function send(string $mobile, string $template_id, array $data = []) { try { $cred = new Credential($this->secret_id, $this->secret_key); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("sms.tencentcloudapi.com"); $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new SmsClient($cred, 'ap-guangzhou', $clientProfile); $params = [ 'PhoneNumberSet' => ['+86' . $mobile], 'TemplateID' => $template_id, 'Sign' => $this->sign, 'TemplateParamSet' => $data, 'SmsSdkAppid' => $this->app_id, ]; $req = new SendSmsRequest(); $req->fromJsonString(json_encode($params, JSON_THROW_ON_ERROR)); $resp = json_decode($client->SendSms($req)->toJsonString(), true, 512, JSON_THROW_ON_ERROR); if (isset($resp['SendStatusSet']) && $resp['SendStatusSet'][0]['Code'] == 'Ok') { return $resp; } else { $message = $res['SendStatusSet'][0]['Message'] ?? json_encode($resp, JSON_THROW_ON_ERROR); throw new CommonException($message); } } catch ( Exception $e ) { throw new NoticeException($e->getMessage()); } } public function modify(string $sign = null, string $mobile, string $code) { } public function template(int $page = 0, int $limit = 15, int $type = 1) { } public function apply(string $title, string $content, int $type) { } public function localTemplate(int $type, int $page, int $limit) { } public function record($id) { } }