config = [ 'appid' => $config->get('access_app_id'), 'secret_id' => $config->get('access_key_id'), 'secret_key' => $config->get('access_key_secret'), ]; try { $cred = new Credential($this->config['secret_id'], $this->config['secret_key']); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint("sms.tencentcloudapi.com"); $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new SmsClient($cred, "ap-guangzhou", $clientProfile); $req = new SendSmsRequest(); $params = [ "PhoneNumberSet" => [ '86'.$to->getNumber(), ], "TemplateID" => $message->getTemplate(), "Sign" => $config->get('sign_name'), "TemplateParamSet" => [ (string)$message->getData()['code'], ], "SmsSdkAppid" => $this->config['appid'], ]; $req->fromJsonString(Json::encode($params)); $resp = $client->SendSms($req); $result = $resp->toJsonString(); $result = Json::decode($result); } catch (TencentCloudSDKException $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } if (isset($result['SendStatusSet'][0]['Code']) && $result['SendStatusSet'][0]['Code'] == 'Ok') { return true; } throw new UnprocessableEntityHttpException($result['SendStatusSet'][0]['Message'] ?? '发送失败'); } }