12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\common\server;
- use TencentCloud\Common\Credential;
- // 导入要请求接口对应的Request类
- use TencentCloud\Common\Exception\TencentCloudSDKException;
- use TencentCloud\Common\Profile\ClientProfile;
- use TencentCloud\Common\Profile\HttpProfile;
- // 导入可选配置类
- use TencentCloud\Sms\V20210111\Models\SendSmsRequest;
- use TencentCloud\Sms\V20210111\SmsClient;
- class tencentcloudserver
- {
- public function getconfig()
- {
- $config = [
- "SecretId" => 'AKIDRhiSv84j8H9j25sOdbJq77rKWR6TZOwE',
- "SecretKey" => 'ziANIxLbbNt87pGQLzMSIr9AuObfWoth',
- 'region' => 'ap-beijing',
- 'endpoint' => 'ocr.tencentcloudapi.com',
- ];
- return $config;
- }
- /**
- * 发送短信
- *
- * @param [type] $appid
- * @param [type] $SignName
- * @param [type] $TemplateId
- * @param [type] $TemplateParamSet
- * @param [type] $PhoneNumberSet
- * @return void
- * @author wj
- * @date 2022-07-26
- */
- public function sendsms($appid, $SignName, $TemplateId, $TemplateParamSet, $PhoneNumberSet)
- {
- try {
- $config = $this->getconfig();
- $cred = new Credential($config['SecretId'], $config['SecretKey']);
- $httpProfile = new HttpProfile();
- $httpProfile->setReqMethod("GET");
- $httpProfile->setReqTimeout(30);
- $httpProfile->setEndpoint($config['endpoint']); // 指定接入地域域名(默认就近接入)
- $clientProfile = new ClientProfile();
- $clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为HmacSHA256)
- $clientProfile->setHttpProfile($httpProfile);
- $client = new SmsClient($cred, $config['region'], $clientProfile);
- $req = new SendSmsRequest();
- $req->SmsSdkAppId = $appid;
- $req->SignName = $SignName;
- $req->TemplateId = $TemplateId;
- $req->TemplateParamSet = $TemplateParamSet;
- /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
- * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
- $req->PhoneNumberSet = $PhoneNumberSet;
- /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
- //$req->SessionContext = "";
- /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
- //$req->ExtendCode = "";
- /* 国际/港澳台短信 SenderId(无需要可忽略): 国内短信填空,默认未开通,如需开通请联系 [腾讯云短信小助手] */
- //$req->SenderId = "";
- $resp = $client->SendSms($req);
- $respArray = $resp->serialize();
- $respArray = $respArray['SendStatusSet'][0];
- if ('Ok' != $respArray['Code']) {
- return backarr(0, $respArray['Message']);
- }
- return backarr(1, 'suceess');
- } catch (TencentCloudSDKException $e) {
- return backarr(0, $e->getMessage());
- }
- }
- }
|