dev-discount
袁野 3 years ago
parent ca688182f3
commit 748118dc1f
  1. 74
      hai-cweb/src/main/java/com/cweb/controller/SmsContentController.java

@ -54,42 +54,42 @@ public class SmsContentController {
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
@RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET) // @RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET)
@ApiOperation(value = "发送短信验证码") // @ApiOperation(value = "发送短信验证码")
@ResponseBody // @ResponseBody
public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone) { // public ResponseData sendSmsCode(@RequestParam(value = "phone", required = true) String phone) {
try { // try {
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); // VerifyCode verifyCode = VerifyCodeStorage.getDate(phone);
String smsCode; // String smsCode;
if (verifyCode != null){ // if (verifyCode != null){
smsCode = verifyCode.getObject(); // smsCode = verifyCode.getObject();
}else{ // }else{
// 生成随机6位验证码 // // 生成随机6位验证码
smsCode = String.valueOf(new Random().nextInt(899999) + 100000); // smsCode = String.valueOf(new Random().nextInt(899999) + 100000);
} // }
String param = "88200409698&to="+phone+"&templateId=f42261f78d54488391f1d1ac4bd5bd3f&templateParas=[\"" + smsCode +"\"]"; // String param = "88200409698&to="+phone+"&templateId=f42261f78d54488391f1d1ac4bd5bd3f&templateParas=[\"" + smsCode +"\"]";
Map<String,Object> body = new LinkedHashMap<>(); // Map<String,Object> body = new LinkedHashMap<>();
body.put("from", param); // body.put("from", param);
String nonce = UUID.randomUUID().toString(); // String nonce = UUID.randomUUID().toString();
String created = DateUtil.date2String(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); // String created = DateUtil.date2String(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'");
String passwordDigest = Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")) + "=="; // String passwordDigest = Base64Util.encode(encodeBySHA256(nonce + created + "9CWFv4NlaRX49n43VPA6eucZ8xeQ")) + "==";
Map<String,Object> header = new LinkedHashMap<>(); // Map<String,Object> header = new LinkedHashMap<>();
header.put("Authorization", "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\""); // header.put("Authorization", "WSSE realm=\"SDP\",profile=\"UsernameToken\",type=\"Appkey\"");
header.put("X-WSSE", "UsernameToken Username=\"QR5eMVrcW0Md6r634M6tf2i34cvb\",PasswordDigest=\""+passwordDigest+"\",Nonce=\""+nonce+"\",Created=\""+created+"\""); // 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); // JSONObject object = HttpsUtils.doSmsPost("https://rtcsms.cn-north-1.myhuaweicloud.com:10743/sms/batchSendSms/v1", body,header);
String code = object.getString("code"); // String code = object.getString("code");
if (code.equals("000000")) { // if (code.equals("000000")) {
redisUtil.set(phone,smsCode, 60*10); // redisUtil.set(phone,smsCode, 60*10);
return ResponseMsgUtil.success("发送成功"); // return ResponseMsgUtil.success("发送成功");
} // }
return ResponseMsgUtil.success(object); // return ResponseMsgUtil.success(object);
} catch (Exception e) { // } catch (Exception e) {
log.error("CmsContentController --> sendSmsCode() error!", e); // log.error("CmsContentController --> sendSmsCode() error!", e);
return ResponseMsgUtil.exception(e); // return ResponseMsgUtil.exception(e);
} // }
} // }
@RequestMapping(value = "/sendSmsCodeHw", method = RequestMethod.GET) @RequestMapping(value = "/sendSmsCode", method = RequestMethod.GET)
@ApiOperation(value = "发送短信验证码") @ApiOperation(value = "发送短信验证码")
@ResponseBody @ResponseBody
public ResponseData sendSmsCodeHw(@RequestParam(value = "phone", required = true) String phone) { public ResponseData sendSmsCodeHw(@RequestParam(value = "phone", required = true) String phone) {
@ -170,7 +170,9 @@ public class SmsContentController {
e.printStackTrace(); e.printStackTrace();
} }
} }
return ResponseMsgUtil.success("发生成功"); redisUtil.set(phone,smsCode, 60*10);
return ResponseMsgUtil.success("发送成功");
} catch (Exception e) { } catch (Exception e) {
log.error("CmsContentController --> sendSmsCode() error!", e); log.error("CmsContentController --> sendSmsCode() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);

Loading…
Cancel
Save