公告
sms.tencentcloudapi.com。curl -sS https://getcomposer.org/installer | phpsudo mv composer.phar /usr/local/bin/composer
composer require tencentcloud/tencentcloud-sdk-php
/path/to/为项目根目录的实际绝对路径,如果是在项目根目录执行,可以省略绝对路径。require '/path/to/vendor/autoload.php';
<?phprequire_once '../../../TCloudAutoLoader.php';// 导入 SMS 模块的 clientuse TencentCloud\\Sms\\V20190711\\SmsClient;// 导入要请求接口对应的 Request 类use TencentCloud\\Sms\\V20190711\\Models\\AddSmsTemplateRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// 导入可选配置类use TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {/* 必要步骤:* 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId 和 secretKey* 本示例采用从环境变量读取的方式,需要预先在环境变量中设置这两个值* 您也可以直接在代码中写入密钥对,但需谨防泄露,不要将代码复制、上传或者分享给他人* CAM 密钥查询:https://console.tencentcloud.com/cam/capi*/$cred = new Credential("xxx", "xxx");//$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个 http 选项,可选,无特殊需求时可以跳过$httpProfile = new HttpProfile();// 配置代理// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // POST 请求(默认为 POST 请求)$httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)// 实例化一个 client 选项,可选,无特殊需求时可以跳过$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为 HmacSHA256)$clientProfile->setHttpProfile($httpProfile);// 实例化 SMS 的 client 对象,clientProfile 是可选的$client = new SmsClient($cred, "ap-shanghai", $clientProfile);// 实例化一个 AddSmsTemplateRequest 请求对象,每个接口都会对应一个 request 对象。$req = new AddSmsTemplateRequest();/* 填充请求参数,这里 request 对象的成员变量即对应接口的入参* 您可以通过官网接口文档或跳转到 request 对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台:https://console.tencentcloud.com/smsv2* sms helper:https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1*//* 模板名称 */$req->TemplateName = "腾讯云";/* 模板内容 */$req->TemplateContent = "{1}为您的登录验证码,请于{2}分钟内填写,如非本人操作,请忽略本短信。";/* 短信类型:0表示普通短信, 1表示营销短信 */$req->SmsType = 0;/* 是否国际/港澳台短信:0表示中国大陆地区短信1表示国际/港澳台短信 */$req->International = 0;/* 模板备注:例如申请原因,使用场景等 */$req->Remark = "xxx";// 通过 client 对象调用 AddSmsTemplate 方法发起请求。注意请求方法名与请求对象是对应的$resp = $client->AddSmsTemplate($req);// 输出 JSON 格式的字符串回包print_r($resp->toJsonString());// 可以取出单个值,您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义print_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '../../../TCloudAutoLoader.php';// 导入 SMS 的 clientuse TencentCloud\\Sms\\V20190711\\SmsClient;// 导入要请求接口对应的 Request 类use TencentCloud\\Sms\\V20190711\\Models\\SendSmsRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// 导入可选配置类use TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {/* 必要步骤:* 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId 和 secretKey* 本示例采用从环境变量读取的方式,需要预先在环境变量中设置这两个值* 您也可以直接在代码中写入密钥对,但需谨防泄露,不要将代码复制、上传或者分享给他人* CAM 密钥查询:https://console.tencentcloud.com/cam/capi*/$cred = new Credential("xxx", "xxx");//$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个 http 选项,可选,无特殊需求时可以跳过$httpProfile = new HttpProfile();// 配置代理// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // POST 请求(默认为 POST 请求)$httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)// 实例化一个 client 选项,可选,无特殊需求时可以跳过$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为 HmacSHA256)$clientProfile->setHttpProfile($httpProfile);// 实例化 SMS 的 client 对象,clientProfile 是可选的$client = new SmsClient($cred, "ap-shanghai", $clientProfile);// 实例化一个 sms 发送短信请求对象,每个接口都会对应一个 request 对象。$req = new SendSmsRequest();/* 填充请求参数,这里 request 对象的成员变量即对应接口的入参* 您可以通过官网接口文档或跳转到 request 对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台:https://console.tencentcloud.com/smsv2* sms helper:https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1 *//* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SDKAppID,例如1400006666 */$req->SmsSdkAppid = "1400787878";/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名,可登录 [短信控制台] 查看签名信息 */$req->Sign = "xxx";/* 短信码号扩展号: 默认未开通,如需开通请联系 [sms helper] */$req->ExtendCode = "";/* 下发手机号码,采用 e.164 标准,+[国家或地区码][手机号]* 例如+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/$req->PhoneNumberSet = array("+8613711112222", "+8613711333222", "+8613711144422");/* 国际/港澳台短信 senderid: 中国大陆地区短信填空,默认未开通,如需开通请联系 [sms helper] */$req->SenderId = "";/* 用户的 session 内容: 可以携带用户侧 ID 等上下文信息,server 会原样返回 */$req->SessionContext = "xxx";/* 模板 ID: 必须填写已审核通过的模板 ID。可登录 [短信控制台] 查看模板 ID */$req->TemplateID = "449739";/* 模板参数: 若无模板参数,则设置为空*/$req->TemplateParamSet = array("0");// 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的$resp = $client->SendSms($req);// 输出 JSON 格式的字符串回包print_r($resp->toJsonString());// 可以取出单个值,您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义print_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '../../../TCloudAutoLoader.php';// 导入 SMS 模块的 clientuse TencentCloud\\Sms\\V20190711\\SmsClient;// 导入要请求接口对应的 Request 类use TencentCloud\\Sms\\V20190711\\Models\\PullSmsSendStatusRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// 导入可选配置类use TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {/* 必要步骤:* 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId 和 secretKey* 本示例采用从环境变量读取的方式,需要预先在环境变量中设置这两个值* 您也可以直接在代码中写入密钥对,但需谨防泄露,不要将代码复制、上传或者分享给他人* CAM 密钥查询:https://console.tencentcloud.com/cam/capi*/$cred = new Credential("xxx", "xxx");//$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个 http 选项,可选,无特殊需求时可以跳过$httpProfile = new HttpProfile();// 配置代理// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // POST 请求(默认为 POST 请求)$httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)// 实例化一个 client 选项,可选,无特殊需求时可以跳过$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为 HmacSHA256)$clientProfile->setHttpProfile($httpProfile);// 实例化 SMS 的 client 对象,clientProfile 是可选的$client = new SmsClient($cred, "ap-shanghai", $clientProfile);// 实例化一个 SMS 发送短信请求对象,每个接口都会对应一个request对象$req = new PullSmsSendStatusRequest();/* 填充请求参数,这里 request 对象的成员变量即对应接口的入参* 您可以通过官网接口文档或跳转到 request 对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台:https://console.tencentcloud.com/smsv2* sms helper:https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1 *//* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SDKAppID,例如1400006666 */$req->SmsSdkAppid = "1400787878";/* 拉取最大条数,最多100条 */$req->Limit = 10;// 通过 client 对象调用 PullSmsSendStatus 方法发起请求。注意请求方法名与请求对象是对应的$resp = $client->PullSmsSendStatus($req);// 输出 JSON 格式的字符串回包print_r($resp->toJsonString());// 可以取出单个值,您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义print_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '../../../TCloudAutoLoader.php';// 导入 SMS 模块的 clientuse TencentCloud\\Sms\\V20190711\\SmsClient;// 导入要请求接口对应的 Request 类use TencentCloud\\Sms\\V20190711\\Models\\SendStatusStatisticsRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// 导入可选配置类use TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {/* 必要步骤:* 实例化一个认证对象,入参需要传入腾讯云账户密钥对 secretId 和 secretKey* 本示例采用从环境变量读取的方式,需要预先在环境变量中设置这两个值* 您也可以直接在代码中写入密钥对,但需谨防泄露,不要将代码复制、上传或者分享给他人* CAM 密钥查询:https://console.tencentcloud.com/cam/capi*/$cred = new Credential("xxx", "xxx");//$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"), getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个 http 选项,可选,无特殊需求时可以跳过$httpProfile = new HttpProfile();// 配置代理// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // POST 请求(默认为 POST 请求)$httpProfile->setReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)// 实例化一个 client 选项,可选,无特殊需求时可以跳过。$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // 指定签名算法(默认为 HmacSHA256)$clientProfile->setHttpProfile($httpProfile);// 实例化 SMS 的 client 对象,clientProfile 是可选的$client = new SmsClient($cred, "ap-shanghai", $clientProfile);// 实例化一个 SMS 发送短信请求对象,每个接口都会对应一个 request 对象$req = new SendStatusStatisticsRequest();/* 填充请求参数,这里 request 对象的成员变量即对应接口的入参* 您可以通过官网接口文档或跳转到 request 对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台:https://console.tencentcloud.com/smsv2* sms helper:https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1 *//* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SDKAppID,例如1400006666 */$req->SmsSdkAppid = "1400787878";/* 拉取最大条数,最多100条 */$req->Limit = 10;/* 偏移量 注:目前固定设置为0 */$req->Offset = 0;/* 开始时间,yyyymmddhh 需要拉取的起始时间,精确到小时 */$req->StartDateTime = "2019122500";/* 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时* 注:EndDataTime 必须大于 StartDateTime */$req->EndDataTime = "2019122523";// 通过 client 对象调用 SendStatusStatistics 方法发起请求。注意请求方法名与请求对象是对应的$resp = $client->SendStatusStatistics($req);// 输出 JSON 格式的字符串回包print_r($resp->toJsonString());// 可以取出单个值,您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义print_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
cURL error 60: See http://curl.haxx.se/libcurl/c/libcurl-errors.html,请尝试按以下步骤解决:cacert.pem,将其保存到 PHP 安装路径下。php.ini文件,删除curl.cainfo配置项前的分号注释符(;),值设置为保存的证书文件cacert.pem的绝对路径。cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)php -r "echo sys_get_temp_dir();",打印系统默认临时目录绝对路径,然后在php.ini配置sys_temp_dir为这个值,尝试是否能解决。git clone命令才能拿到 vendor 目录的情况,对一些不熟悉 github 的用户造成了困扰。从3.0.188版本开始,我们暂时移除了源码安装,必须使用 composer 安装 SDK 和依赖的包。https_proxy,否则可能无法正常调用,抛出连接超时的异常。
或使用 GuzzleHttp 代理配置:$cred = new Credential("secretId", "secretKey");$httpProfile = new HttpProfile();$httpProfile->setProxy('https://ip:port');$clientProfile = new ClientProfile();$clientProfile->setHttpProfile($httpProfile);
文档反馈