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
|
public String sendSms(String mobile) { DefaultProfile profile = DefaultProfile.getProfile(this.aliyunSMSConfig.getRegionId(), this.aliyunSMSConfig.getAccessKeyId(), this.aliyunSMSConfig.getAccessKeySecret()); IAcsClient client = new DefaultAcsClient(profile);
String code = RandomUtils.nextInt(100000, 999999) + "";
CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain(this.aliyunSMSConfig.getDomain()); request.setSysVersion("2017-05-25"); request.setSysAction("SendSms"); request.putQueryParameter("RegionId", this.aliyunSMSConfig.getRegionId()); request.putQueryParameter("PhoneNumbers", mobile); request.putQueryParameter("SignName", this.aliyunSMSConfig.getSignName()); request.putQueryParameter("TemplateCode", this.aliyunSMSConfig.getTemplateCode()); request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}"); try { CommonResponse response = client.getCommonResponse(request); String data = response.getData(); if (StringUtils.contains(data, "\"Message\":\"OK\"")) { return code; } log.info("发送短信验证码失败~ data = " + data); } catch (Exception e) { log.error("发送短信验证码失败~ mobile = " + mobile, e); } return null; }
public ErrorResult sendCheckCode(String phone) {
String redisKey = "CHECK_CODE_" + phone;
if (this.redisTemplate.hasKey(redisKey)) { String msg = "上一次发送的验证码还未失效!"; return ErrorResult.builder().errCode("000001").errMessage(msg).build(); }
String code = "123456";
if (StringUtils.isEmpty(code)) { String msg = "发送短信验证码失败!"; return ErrorResult.builder().errCode("000000").errMessage(msg).build(); }
this.redisTemplate.opsForValue().set(redisKey, code, Duration.ofMinutes(5)); return null; }
|