SecretID
and SecretKey
on the API Key Management page in the CAM console.SecretID
is used to identify the API caller.SecretKey
is used to encrypt the string to sign that can be verified on the server. You should keep it private and avoid disclosure.sms.tencentcloudapi.com
.<?phprequire_once '/path/to/vendor/autoload.php';// Import the client of the corresponding product moduleuse TencentCloud\\Sms\\V20210111\\SmsClient;// Import the `Request` class corresponding to the request APIuse TencentCloud\\Sms\\V20210111\\Models\\SendSmsRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// Import the optional configuration classesuse TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {// Instantiate a certificate object. The input parameters require the Tencent Cloud account SecretId, SecretKey// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// $cred = new Credential("SecretId", "SecretKey");$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option$httpProfile = new HttpProfile();// Configure the proxy// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // GET request (POST request by default)$httpProfile->setReqTimeout(10); // Request timeout period in seconds (60 seconds by default)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // Specify the access region domain name (nearby access by default)// Instantiate a client option (optional; skip if no special requirements are present)$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // Specify the signature algorithm$clientProfile->setHttpProfile($httpProfile);// Instantiate the client object of the requested product (with SMS as an example). `clientProfile` is optional// The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.$client = new SmsClient($cred, "ap-singapore", $clientProfile);// Instantiate an SMS message sending request object. Each API corresponds to a request object$req = new SendSmsRequest();/* Populate the request parameters. Here, the member variables of the request object are the input parameters of the corresponding API* You can view the definition of the request parameters in the API documentation at the official website or by redirecting to the definition of the request object* Settings of a basic parameter:* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper: https://www.tencentcloud.com/document/product/382/3773 *//* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */$req->SmsSdkAppId = "2400006666";/* SMS signature content, which should be encoded in UTF-8. You must enter an approved signature, which can be viewed in the [SMS console] */$req->SignName = "xxx";/* SMS code number extension, which is not activated by default. If you need to activate it, please contact [SMS Helper] */$req->ExtendCode = "";/* Target mobile number in the E.164 standard (+[country/region code][mobile number])* Example: +60198890000, which has a + sign followed by 60 (country/region code) and then by 198890000 (mobile number). Up to 200 mobile numbers are supported */$req->PhoneNumberSet = array("+60198890000");/* `SenderId` for Global SMS, which is not activated by default. If you need to activate it, please contact [SMS Helper] for assistance. This parameter should be left empty for Mainland China SMS */$req->SenderId = "";/* User session content, which can carry context information such as user-side ID and will be returned as-is by the server */$req->SessionContext = "xxx";/* Template ID. You must enter the ID of an approved template, which can be viewed in the [SMS console] */$req->TemplateId = "449739";/* Template parameters. If there are no template parameters, leave it empty */$req->TemplateParamSet = array("0");// Initialize the request by calling the `SendSms` method on the client object. Note: the request method name corresponds to the request object// The returned `resp` is an instance of the `SendSmsResponse` class which corresponds to the request object$resp = $client->SendSms($req);// A string return packet in JSON format is outputprint_r($resp->toJsonString());// You can also take a single value// You can view the definition of the return field in the API documentation at the official website or by redirecting to the definition of the response objectprint_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '/path/to/vendor/autoload.php';// Import the client of the corresponding product moduleuse TencentCloud\\Sms\\V20210111\\SmsClient;// Import the `Request` class corresponding to the request APIuse TencentCloud\\Sms\\V20210111\\Models\\PullSmsSendStatusRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// Import the optional configuration classesuse TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {// Instantiate a certificate object. The input parameters require the Tencent Cloud account SecretId, SecretKey// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// $cred = new Credential("SecretId", "SecretKey");$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option$httpProfile = new HttpProfile();// Configure the proxy// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // GET request (POST request by default)$httpProfile->setReqTimeout(30); // Request timeout period in seconds (60 seconds by default)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // Specify the access region domain name (nearby access by default)// Instantiate a client option (optional; skip if no special requirements are present)$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // Specify the signature algorithm$clientProfile->setHttpProfile($httpProfile);// Instantiate the client object of the requested product (with SMS as an example). `clientProfile` is optional// The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.$client = new SmsClient($cred, "ap-singapore", $clientProfile);// Instantiate an SMS message sending request object. Each API corresponds to a request object$req = new PullSmsSendStatusRequest();/* Populate the request parameters. Here, the member variables of the request object are the input parameters of the corresponding API* You can view the definition of the request parameters in the API documentation at the official website or by redirecting to the definition of the request object* Settings of a basic parameter:* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper: https://www.tencentcloud.com/document/product/382/3773 *//* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */$req->SmsSdkAppId = "2400006666";/* Maximum number of pulled entries. Maximum value: 100 */$req->Limit = 10;// Initialize the request by calling the `PullSmsSendStatus` method on the client object. Note: the request method name corresponds to the request object// The returned `resp` is an instance of the `PullSmsSendStatusResponse` class which corresponds to the request object$resp = $client->PullSmsSendStatus($req);// A string return packet in JSON format is outputprint_r($resp->toJsonString());// You can also take a single value// You can view the definition of the return field in the API documentation at the official website or by redirecting to the definition of the response objectprint_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '/path/to/vendor/autoload.php';// Import the client of the corresponding product moduleuse TencentCloud\\Sms\\V20210111\\SmsClient;// Import the `Request` class corresponding to the request APIuse TencentCloud\\Sms\\V20210111\\Models\\SendStatusStatisticsRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// Import the optional configuration classesuse TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {// Instantiate a certificate object. The input parameters require the Tencent Cloud account SecretId, SecretKey// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// $cred = new Credential("SecretId", "SecretKey");$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option$httpProfile = new HttpProfile();// Configure the proxy// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // GET request (POST request by default)$httpProfile->setReqTimeout(30); // Request timeout period in seconds (60 seconds by default)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // Specify the access region domain name (nearby access by default)// Instantiate a client option (optional; skip if no special requirements are present)$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // Specify the signature algorithm$clientProfile->setHttpProfile($httpProfile);// Instantiate the client object of the requested product (with SMS as an example). `clientProfile` is optional// The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.$client = new SmsClient($cred, "ap-singapore", $clientProfile);// Instantiate an SMS message sending request object. Each API corresponds to a request object$req = new SendStatusStatisticsRequest();/* Populate the request parameters. Here, the member variables of the request object are the input parameters of the corresponding API* You can view the definition of the request parameters in the API documentation at the official website or by redirecting to the definition of the request object* Settings of a basic parameter:* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper: https://www.tencentcloud.com/document/product/382/3773 *//* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */$req->SmsSdkAppId = "2400006666";/* Maximum number of pulled entries. Maximum value: 100 */$req->Limit = 10;/* Offset. Note: this parameter is currently fixed at 0 */$req->Offset = 0;/* Start time of pull in the format of `yyyymmddhh` accurate to the hour */$req->BeginTime = "2019122500";/* End time of pull in the format of `yyyymmddhh` accurate to the hour* Note: `EndTime` must be after `BeginTime` */$req->EndTime = "2019122523";// Initialize the request by calling the `SendStatusStatistics` method on the client object. Note: the request method name corresponds to the request object// The returned `resp` is an instance of the `SendStatusStatisticsResponse` class which corresponds to the request object$resp = $client->SendStatusStatistics($req);// A string return packet in JSON format is outputprint_r($resp->toJsonString());// You can also take a single value// You can view the definition of the return field in the API documentation at the official website or by redirecting to the definition of the response objectprint_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
<?phprequire_once '/path/to/vendor/autoload.php';// Import the client of the SMS moduleuse TencentCloud\\Sms\\V20210111\\SmsClient;// Import the `Request` class corresponding to the API to be requesteduse TencentCloud\\Sms\\V20210111\\Models\\AddSmsTemplateRequest;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Common\\Credential;// Import the optional configuration classesuse TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;try {// Instantiate a certificate object. The input parameters require the Tencent Cloud account SecretId, SecretKey// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// $cred = new Credential("SecretId", "SecretKey");$cred = new Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// Instantiate an HTTP option (optional; skip if there are no special requirements)$httpProfile = new HttpProfile();// Configure the proxy// $httpProfile->setProxy("https://ip:port");$httpProfile->setReqMethod("GET"); // GET request (POST request by default)$httpProfile->setReqTimeout(30); // Request timeout period in seconds (60 seconds by default)$httpProfile->setEndpoint("sms.tencentcloudapi.com"); // Specify the access region domain name (nearby access by default)// Instantiate a client option (optional; skip if no special requirements are present)$clientProfile = new ClientProfile();$clientProfile->setSignMethod("TC3-HMAC-SHA256"); // Specify the signature algorithm$clientProfile->setHttpProfile($httpProfile);// Instantiate an SMS client object. `clientProfile` is optional// The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.$client = new SmsClient($cred, "ap-singapore", $clientProfile);// Instantiate an `AddSmsTemplateRequest` request object. Each API corresponds to a request object$req = new AddSmsTemplateRequest();/* Populate the request parameters. Here, the member variables of the request object are the input parameters of the corresponding API* You can view the definition of the request parameters in the API documentation at the official website or by redirecting to the definition of the request object* Settings of a basic parameter:* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper:https://www.tencentcloud.com/document/product/382/3773*//* Template name */$req->TemplateName = "Tencent Cloud";/* Template content */$req->TemplateContent = "Your login verification code is {1}. Please enter it within {2} minutes. If the login was not initiated by you, please ignore this message.";/* SMS type. 1: Marketing SMS, 2: Notification SMS, 3: OTP SMS */$req->SmsType = 3;/* Whether it is Global SMS:0: Mainland China SMS1: Global SMS */$req->International = 0;/* Template remarks, such as reason for application and use case */$req->Remark = "xxx";// Initialize the request by calling the `AddSmsTemplate` method on the client object. Note: the request method name corresponds to the request object$resp = $client->AddSmsTemplate($req);// A string return packet in JSON format is outputprint_r($resp->toJsonString());// You can take a single value. You can view the definition of the return field in the API documentation at the official website or by redirecting to the definition of the response objectprint_r($resp->TotalCount);}catch(TencentCloudSDKException $e) {echo $e;}
cURL error 60: See http://curl.haxx.se/libcurl/c/libcurl-errors.html
may occur, which can be solved as follows:cacert.pem
at https://curl.haxx.se/ca/cacert.pem and save it to the PHP installation path.php.ini
file: delete the semicolon comment (;) before the curl.cainfo
configuration item and set the value to the absolute path of the saved certificate file cacert.pem
./etc/php/7.1/apache2/php.ini
to see whether the extension=php_curl.dll
configuration item has been commented. Please delete the comment before it and restart Apache.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();"
to print the absolute path of the default system temporary directory and set sys_temp_dir
in php.ini
to this value, and then check whether this error is fixed.vendor
directory. However, considering that incompatibility with Composer should not be caused, we had to forbid importing the vendor
directory on GitHub, which resulted in the problem where the git clone
command had to be used to get the vendor
directory. This practice caused confusion for some users not familiar with GitHub. Therefore, starting from v3.0.188, we have temporarily removed the method of installation through source code, and Composer must be used to install the SDK and dependent packages.https_proxy
; otherwise, it may not be called normally, and a connection timeout exception will be thrown.
You can also use GuzzleHttp
to configure the proxy:$cred = new Credential("secretId", "secretKey");$httpProfile = new HttpProfile();$httpProfile->setProxy('https://ip:port');$clientProfile = new ClientProfile();$clientProfile->setHttpProfile($httpProfile);
Was this page helpful?