From 748118dc1ffbf899926785d35d589f4bc8bb5c84 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Mon, 25 Oct 2021 21:50:19 +0800 Subject: [PATCH] 1 --- .../cweb/controller/SmsContentController.java | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/hai-cweb/src/main/java/com/cweb/controller/SmsContentController.java b/hai-cweb/src/main/java/com/cweb/controller/SmsContentController.java index 9f3fec68..c9b6597f 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/SmsContentController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/SmsContentController.java @@ -54,42 +54,42 @@ public class SmsContentController { @Resource private RedisUtil redisUtil; - @RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET) - @ApiOperation(value = "发送短信验证码") - @ResponseBody - public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone) { - try { - VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); - String smsCode; - if (verifyCode != null){ - smsCode = verifyCode.getObject(); - }else{ - // 生成随机6位验证码 - smsCode = String.valueOf(new Random().nextInt(899999) + 100000); - } - String param = "88200409698&to="+phone+"&templateId=f42261f78d54488391f1d1ac4bd5bd3f&templateParas=[\"" + smsCode +"\"]"; - Map body = new LinkedHashMap<>(); - body.put("from", param); - String nonce = UUID.randomUUID().toString(); - String created = DateUtil.date2String(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); - String passwordDigest = Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")) + "=="; - Map header = new LinkedHashMap<>(); - header.put("Authorization", "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""); - header.put("X-WSSE", "UsernameToken Username=\"QR5eMVrcW0Md6r634M6tf2i34cvb\",PasswordDigest=\""+passwordDigest+"\",Nonce=\""+nonce+"\",Created=\""+created+"\""); - JSONObject object = HttpsUtils.doSmsPost("https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1", body,header); - String code = object.getString("code"); - if (code.equals("000000")) { - redisUtil.set(phone,smsCode, 60*10); - return ResponseMsgUtil.success("发送成功"); - } - return ResponseMsgUtil.success(object); - } catch (Exception e) { - log.error("CmsContentController --> sendSmsCode() error!", e); - return ResponseMsgUtil.exception(e); - } - } +// @RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET) +// @ApiOperation(value = "发送短信验证码") +// @ResponseBody +// public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone) { +// try { +// VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); +// String smsCode; +// if (verifyCode != null){ +// smsCode = verifyCode.getObject(); +// }else{ +// // 生成随机6位验证码 +// smsCode = String.valueOf(new Random().nextInt(899999) + 100000); +// } +// String param = "88200409698&to="+phone+"&templateId=f42261f78d54488391f1d1ac4bd5bd3f&templateParas=[\"" + smsCode +"\"]"; +// Map body = new LinkedHashMap<>(); +// body.put("from", param); +// String nonce = UUID.randomUUID().toString(); +// String created = DateUtil.date2String(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); +// String passwordDigest = Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")) + "=="; +// Map header = new LinkedHashMap<>(); +// header.put("Authorization", "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""); +// header.put("X-WSSE", "UsernameToken Username=\"QR5eMVrcW0Md6r634M6tf2i34cvb\",PasswordDigest=\""+passwordDigest+"\",Nonce=\""+nonce+"\",Created=\""+created+"\""); +// JSONObject object = HttpsUtils.doSmsPost("https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1", body,header); +// String code = object.getString("code"); +// if (code.equals("000000")) { +// redisUtil.set(phone,smsCode, 60*10); +// return ResponseMsgUtil.success("发送成功"); +// } +// return ResponseMsgUtil.success(object); +// } catch (Exception e) { +// log.error("CmsContentController --> sendSmsCode() error!", e); +// return ResponseMsgUtil.exception(e); +// } +// } - @RequestMapping(value = "/sendSmsCodeHw", method = RequestMethod.GET) + @RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET) @ApiOperation(value = "发送短信验证码") @ResponseBody public ResponseData sendSmsCodeHw(@RequestParam(value = "phone", required = true) String phone) { @@ -170,7 +170,9 @@ public class SmsContentController { e.printStackTrace(); } } - return ResponseMsgUtil.success("发生成功"); + redisUtil.set(phone,smsCode, 60*10); + return ResponseMsgUtil.success("发送成功"); + } catch (Exception e) { log.error("CmsContentController --> sendSmsCode() error!", e); return ResponseMsgUtil.exception(e);