|
@@ -1,11 +1,11 @@
|
|
|
package com.huyi.service.util.impl;
|
|
|
|
|
|
-import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.huyi.service.base.entity.PubVerifyCode;
|
|
|
import com.huyi.service.base.service.IPubVerifyCodeService;
|
|
|
-import com.huyi.service.constant.MessageConstants;
|
|
|
import com.huyi.service.util.IMessageUtilsService;
|
|
|
+import com.tianhu.common.core.aliyun.SendSms;
|
|
|
import com.tianhu.common.core.exception.BaseException;
|
|
|
import com.tianhu.common.core.utils.CommonUtil;
|
|
|
import com.tianhu.common.core.utils.DateUtils;
|
|
@@ -14,13 +14,8 @@ import com.tianhu.common.redis.common.RedisUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpSession;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.GregorianCalendar;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -39,16 +34,18 @@ public class MessageUtilsServiceImpl implements IMessageUtilsService
|
|
|
//验证码状态(未校验)
|
|
|
static final String NO_CHECK = "00";
|
|
|
|
|
|
+ private static final String accessKeyId = "";
|
|
|
+ private static final String accessKeySecret = "";
|
|
|
+ private static final String signName = "";
|
|
|
/**
|
|
|
* 发送短信验证码
|
|
|
- * @param mobileNo 手机号码
|
|
|
- * @param verificationCode 模板id
|
|
|
- * @param request
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
+ * @param mobileNo 手机号
|
|
|
+ * @param templateCode 手机模板
|
|
|
+ * @param param 参数
|
|
|
+ * @param random 验证码 验证类短息需要传
|
|
|
*/
|
|
|
@Override
|
|
|
- public void sendMessageCode(String mobileNo, String verificationCode, HttpServletRequest request)
|
|
|
+ public void sendMessageCode(String mobileNo, String templateCode, Map<String, String> param, String random)
|
|
|
{
|
|
|
if (CommonUtil.isEmpty(mobileNo)) {
|
|
|
throw new BaseException("手机号不能为空!");
|
|
@@ -61,9 +58,6 @@ public class MessageUtilsServiceImpl implements IMessageUtilsService
|
|
|
throw new BaseException("手机号格式错误");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 验证是否已经发送验证码
|
|
|
- HttpSession httpSession = request.getSession();
|
|
|
//查询验证码
|
|
|
LambdaQueryWrapper<PubVerifyCode> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(PubVerifyCode::getPvcPhone,mobileNo);
|
|
@@ -84,19 +78,9 @@ public class MessageUtilsServiceImpl implements IMessageUtilsService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 获取随机数
|
|
|
- String random = genRandomNum(6);
|
|
|
//调试模式
|
|
|
boolean isTest = true;
|
|
|
- // 获取验证码时间
|
|
|
- httpSession.setAttribute(MessageConstants.LAST_MOBILE_TIME, DateUtils.getNowDate());
|
|
|
- // 验证码
|
|
|
- httpSession.setAttribute(MessageConstants.MOBILE_RANDOM, random);
|
|
|
- // 手机号
|
|
|
- httpSession.setAttribute(MessageConstants.MOBILE_NO, mobileNo);
|
|
|
- String regVal = RedisUtils.getDictValue("pub_verification_code", verificationCode);
|
|
|
- // 发送短信
|
|
|
- String msg = regVal.replaceAll("@", random);
|
|
|
+ String regVal = RedisUtils.getDictValue("pub_verification_code", templateCode);
|
|
|
|
|
|
PubVerifyCode pubVerifyCode = new PubVerifyCode();
|
|
|
pubVerifyCode.setPvcId(IdUtils.fastSimpleUUID());
|
|
@@ -106,18 +90,8 @@ public class MessageUtilsServiceImpl implements IMessageUtilsService
|
|
|
pubVerifyCode.setPvcState("00");
|
|
|
iPubVerifyCodeService.createPubVerifyCode(pubVerifyCode);
|
|
|
if(!isTest) {
|
|
|
- System.out.println("mobileNo:"+mobileNo+"====ccc======msg:"+msg);
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- sb.append("mobile=");
|
|
|
- sb.append(mobileNo);
|
|
|
- sb.append("&content=");
|
|
|
- sb.append(msg);
|
|
|
- sb.append("&appkey=");
|
|
|
- String appKey = RedisUtils.getDictValue("pub_jisu_app_key", "000000_app_key");
|
|
|
- sb.append(appKey);
|
|
|
try {
|
|
|
- System.out.println("======sb:"+ sb.toString());
|
|
|
- HttpUtil.get("http://api.jisuapi.com/sms/send?" + sb.toString());
|
|
|
+ SendSms.sendMessage(accessKeyId, accessKeySecret, mobileNo, signName, regVal, JSONObject.toJSONString(param));
|
|
|
} catch (Exception ex) {
|
|
|
System.out.println("获取短信验证码失败");
|
|
|
throw new BaseException("获取短信验证码失败");
|
|
@@ -125,7 +99,8 @@ public class MessageUtilsServiceImpl implements IMessageUtilsService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String genRandomNum(int card_len){
|
|
|
+ @Override
|
|
|
+ public String genRandomNum(int card_len){
|
|
|
//35是因为数组是从0开始的,26个字母+10个数字
|
|
|
final int maxNum = 36;
|
|
|
//生成的随机数
|