|
package sms.v20190711; |
|
|
|
import com.tencentcloudapi.common.Credential; |
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException; |
|
|
|
|
|
import com.tencentcloudapi.common.profile.ClientProfile; |
|
import com.tencentcloudapi.common.profile.HttpProfile; |
|
|
|
|
|
import com.tencentcloudapi.sms.v20190711.SmsClient; |
|
|
|
|
|
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest; |
|
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SendSms |
|
{ |
|
public static void main( String[] args ) |
|
{ |
|
try { |
|
|
|
Credential cred = new Credential("secretId", "secretKey"); |
|
|
|
|
|
HttpProfile httpProfile = new HttpProfile(); |
|
|
|
httpProfile.setProxyHost("host"); |
|
httpProfile.setProxyPort(port); |
|
|
|
httpProfile.setReqMethod("POST"); |
|
|
|
httpProfile.setConnTimeout(60); |
|
|
|
httpProfile.setEndpoint("sms.tencentcloudapi.com"); |
|
|
|
|
|
ClientProfile clientProfile = new ClientProfile(); |
|
|
|
clientProfile.setSignMethod("HmacSHA256"); |
|
clientProfile.setHttpProfile(httpProfile); |
|
|
|
|
|
SmsClient client = new SmsClient(cred, "",clientProfile); |
|
|
|
|
|
SendSmsRequest req = new SendSmsRequest(); |
|
|
|
|
|
|
|
|
|
String appid = "1400009099"; |
|
req.setSmsSdkAppid(appid); |
|
|
|
|
|
String sign = "签名内容"; |
|
req.setSign(sign); |
|
|
|
|
|
String templateID = "400000"; |
|
req.setTemplateID(templateID); |
|
|
|
|
|
String[] phoneNumbers = {"+8621212313123", "+8612345678902", "+8612345678903"}; |
|
req.setPhoneNumberSet(phoneNumbers); |
|
|
|
|
|
String[] templateParams = {"5678"}; |
|
req.setTemplateParamSet(templateParams); |
|
|
|
|
|
|
|
SendSmsResponse res = client.SendSms(req); |
|
|
|
|
|
System.out.println(SendSmsResponse.toJsonString(res)); |
|
|
|
|
|
|
|
System.out.println(res.getRequestId()); |
|
|
|
} catch (TencentCloudSDKException e) { |
|
e.printStackTrace(); |
|
} |
|
} |
|
} |