setReqMethod("GET"); // post请求(默认为post请求) $httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒) $httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入) $clientProfile = new ClientProfile(); $clientProfile->setSignMethod("TC3-HMAC-SHA256"); $clientProfile->setHttpProfile($httpProfile); $client = new SmsClient($cred, "ap-guangzhou", $clientProfile); $req = new SendSmsRequest(); $req->SmsSdkAppId = Env::get("sms.tencent_cloud_sms_sdk_app_id"); $req->SignName = Env::get("sms.tencent_cloud_sms_sign_name"); $req->TemplateId = $templateId; $req->TemplateParamSet = $params; $req->PhoneNumberSet = array("+86{$mobile}"); // 通过client对象调用SendSms方法发起请求。注意请求方法名与请求对象是对应的 // 返回的resp是一个SendSmsResponse类的实例,与请求对象对应 $resp = $client->SendSms($req); $resp_data = $resp->toJsonString(); if (false === $resp_data) return new \SResult(0, "请求发送失败"); $fmt_data = json_decode($resp_data, true); return new \SResult("Ok" === $fmt_data["SendStatusSet"][0]["Code"], "请求发送失败!", $fmt_data); } catch (TencentCloudSDKException $e) { return new \SResult(0, $e->getMessage()); } } public static function tencent_cloud_vms_send($mobile, $template_id, $params = null) { try { $cred = new Credential( config("site.tencent_cloud_secret_id"), config("site.tencent_cloud_secret_key") ); $httpProfile = new HttpProfile(); $httpProfile->setReqMethod("POST"); $httpProfile->setReqTimeout(30); $httpProfile->setEndpoint("vms.tencentcloudapi.com"); $clientProfile = new ClientProfile(); $clientProfile->setSignMethod("TC3-HMAC-SHA256"); $clientProfile->setHttpProfile($httpProfile); $client = new VmsClient($cred, "ap-guangzhou", $clientProfile); $req = new SendTtsVoiceRequest(); $req->TemplateId = $template_id; if (!is_null($params)) { $req->TemplateParamSet = $params; } $req->CalledNumber = "+86{$mobile}"; $req->VoiceSdkAppid = config("site.tencent_cloud_vms_sdk_app_id"); $req->PlayTimes = 2; $resp = $client->SendTtsVoice($req); $resp_data = $resp->toJsonString(); if (false === $resp_data) return new \SResult(0, "请求发送失败"); $fmt_data = json_decode($resp_data, true); return new \SResult(isset($fmt_data["RequestId"]), "请求发送失败!"); } catch (TencentCloudSDKException $e) { return new \SResult(0, $e->getMessage()); } } }