pom
com.aliyun aliyun-java-sdk-core4.5.16
实现方法
public String generateAuthCode(String telephone) { StringBuilder sb = new StringBuilder(); Random random = new Random(); for(int i=0;i<6;i++){ sb.append(random.nextInt(10)); } DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "ccessKeyId", "accessKeySecret"); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setMethod(MethodType.POST); request.setDomain("dysmsapi.aliyuncs.com"); request.setVersion("2017-05-25"); request.setAction("SendSms"); // 自定义的参数(手机号、验证码、签名、模板) request.putQueryParameter("PhoneNumbers", telephone); request.putQueryParameter("SignName", "公司名"); request.putQueryParameter("TemplateCode", ""); // 构建一个短信 HashMaphashMap = new HashMap<>(); hashMap.put("code", sb.toString()); request.putQueryParameter("TemplateParam", JSONObject.toJSONString(hashMap)); try { CommonResponse response = client.getCommonResponse(request); System.out.println(response.getData()); } catch (ClientException e) { e.printStackTrace(); } return sb.toString(); }
~有写错的或者有更优雅的写法记得@ 我~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)