com.haoxuer.discover.App Maven / Gradle / Ivy
package com.haoxuer.discover;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.json.JSONObject;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws ClientException {
System.out.println( "Hello World!" );
//设置超时时间-可自行调整
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化ascClient需要的几个参数
final String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)
final String domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改)
//替换成你的AK
final String accessKeyId = "LTAI5rIYav12KhGh";//你的accessKeyId,参考本文档步骤2
final String accessKeySecret = "RzWXcCEJg0jweOVurYrbwdJZ1uVHyq";//你的accessKeySecret,参考本文档步骤2
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId,
accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
request.setMethod(MethodType.POST);
request.setPhoneNumbers("18229060103");
request.setSignName("开一票");
request.setTemplateCode("SMS_154591121");
JSONObject object=new JSONObject();
object.put("hotel","");
object.put("room","");
request.setTemplateParam("{\"name\":\"Tom\", \"code\":\"123\"}");
request.setOutId("yourOutId");
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
//请求成功
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy