| | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.profile.DefaultProfile; |
| | | import com.aliyuncs.profile.IClientProfile; |
| | |
| | | |
| | | static final String connectTime = "30000"; |
| | | static final String readTime = "30000"; |
| | | static final String keyId = "LTAI5tFGHa9bwhuEDKH6YPnc"; |
| | | static final String keyId = "LTAI5tRr7uLjPPxzGMJPH6fz"; |
| | | static final String keySecret = "GiOamDfkVP4TWiNnuSptyGQLuMRBMG"; |
| | | |
| | | static final String keySecret = "BrY0BM4pvDXhVKOMLsXzgzlhVe1keQ"; |
| | | static final String signName = "云南花满芫花卉"; |
| | | static final String signName = "苏州云游四方信息科技"; |
| | | |
| | | public static SendSmsResponse sendSms(final String tel, final String templateCode, Object paramMap) throws ClientException { |
| | | return sendSms(tel, templateCode, JSON.toJSONString(paramMap)); |
| | | } |
| | | |
| | | public static SendSmsResponse sendSms(final String tel, final String templateCode, final String templateParam) throws ClientException { |
| | | return sendSms(tel, templateCode, templateParam, null); |
| | | } |
| | | |
| | | public static SendSmsResponse sendSms(final String tel, final String templateCode, final String templateParam, final String outId) throws ClientException { |
| | | log.info("Send SMS [mobile no:" + tel + " templateCode:" + templateCode + " templateParam:" + templateParam + "]"); |
| | | System.setProperty("sun.net.client.defaultConnectTimeout", connectTime); |
| | | System.setProperty("sun.net.client.defaultReadTimeout", readTime); |
| | | IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", keyId, keySecret); |
| | | DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain); |
| | | IAcsClient acsClient = new DefaultAcsClient(profile); |
| | | SendSmsRequest request = new SendSmsRequest(); |
| | | request.setPhoneNumbers(tel); |
| | | request.setSignName(signName); |
| | | request.setTemplateCode(templateCode); |
| | | request.setTemplateParam(templateParam); |
| | | request.setOutId(outId); |
| | | SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); |
| | | log.info("Send SMS [mobile no:" + tel + " templateCode:" + templateCode + " templateParam:" + templateParam + "] result: " + sendSmsResponse.getCode() + " " + sendSmsResponse.getMessage()); |
| | | return sendSmsResponse; |
| | | } |
| | | |
| | | } |