sign = $config['sign']; $this->appid = $config['app_id']; $this->app_key = $config['app_key']; $this->secret_key = $config['secret_key']; } /** * @Notes: 设置模板编码 * @Author: kiki * @param $template_code * @return $this */ public function setTemplateCode($template_code){ $this->template_code = $template_code; return $this; } /** * @Notes: 设置手机号 * @Author: kiki * @param $mobile * @return $this */ public function setMobile($mobile){ $this->mobile = $mobile; return $this; } /** * @Notes: 设置模板参数 * @Author: kiki * @param string $template_param * @return $this */ public function setTemplateParam($template_param = ''){ $this->template_param = $template_param; return $this; } /** * @Notes: 发送短信 * @Author: kiki */ public function sendSms() { $cred = new Credential($this->app_key, $this->secret_key); $httpProfile = new HttpProfile(); $httpProfile->setEndpoint('sms.tencentcloudapi.com'); $clientProfile = new ClientProfile(); $clientProfile->setHttpProfile($httpProfile); $client = new SmsClient($cred, "", $clientProfile); $req = new SendSmsRequest(); $params = [ 'Sign' => $this->sign, 'SmsSdkAppid' => $this->appid, 'TemplateID' => $this->template_code, 'PhoneNumberSet' => ['+86'.$this->mobile], 'TemplateParamSet' => $this->template_param, ]; $req->fromJsonString(json_encode($params)); $resp = $client->SendSms($req); // return $resp->toJsonString(); return json_decode($resp->toJsonString(), true); } }