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
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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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);

Loading…
Cancel
Save