发送短信工具集(阿里云)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| package com.test.util; import java.io.IOException; import java.util.Random; 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.exceptions.ServerException; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.IClientProfile;
public class SendSMS { public static int sendSm(String phone) throws ClientException{ System.setProperty("sun.net.client.defaultConnectTimeout", "10000"); System.setProperty("sun.net.client.defaultReadTimeout", "10000"); final String product = "Dysmsapi"; final String domain = "dysmsapi.aliyuncs.com"; final String accessKeyId = "LTAISz2Gh0v0hApy"; final String accessKeySecret = "PD9ReGIxxDMski8WAY9HSv9yBOebdk"; 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(phone); request.setSignName("追能云"); request.setTemplateCode("SMS_127215050"); int code=randomInt(); request.setTemplateParam("{\"code\":\""+code+"\"}"); System.out.print(code); SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) { System.out.print("请求成功"); return code; } return 0; } private static int randomInt() { int verifyCode = (new Random().nextInt(899999) + 100000); return verifyCode; } public static void main(String[] args) throws ClientException { sendSm("手机号");
} }
|
-
Next Post
sqlserver
-
Previous Post
MySQL数据库