Browse Source

app登录使用拖拽验证发短信码

FengChaoYu 6 months ago
parent
commit
ba0cb18831

+ 34 - 21
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/common/CommonController.java

@@ -41,7 +41,7 @@ import java.util.UUID;
 
 @Slf4j
 @RestController
-@Api(value = "公共API", tags ={"公共API"} )
+@Api(value = "公共API", tags = {"公共API"})
 @RequestMapping(value = "/common", produces = "application/json; charset=utf-8")
 public class CommonController {
 
@@ -102,7 +102,7 @@ public class CommonController {
             @ApiParam(required = true, value = "附件") @RequestParam(required = true) String logisticsNo,
             @ApiParam(required = true, value = "物流公司code") @RequestParam(required = true) String companyCode
     ) throws IOException, RemoteServiceException {
-        List<ExpressInfo> expressInfos = expressLogic.queryExpress(logisticsNo,companyCode);
+        List<ExpressInfo> expressInfos = expressLogic.queryExpress(logisticsNo, companyCode);
         return ResponseHelper.success(expressInfos);
     }
 
@@ -110,9 +110,9 @@ public class CommonController {
     @GetMapping("/street")
     @ApiOperation(value = "街道")
     public ResponseHelper<List<Map>> street(
-            @ApiParam(value = "省",required = true) @RequestParam(required = true) String province,
-            @ApiParam(value = "市",required = true) @RequestParam(required = true) String city,
-            @ApiParam(value = "区",required = true) @RequestParam(required = true) String area
+            @ApiParam(value = "省", required = true) @RequestParam(required = true) String province,
+            @ApiParam(value = "市", required = true) @RequestParam(required = true) String city,
+            @ApiParam(value = "区", required = true) @RequestParam(required = true) String area
     ) throws RemoteServiceException {
         List<Map> street = commonLogic.street(province, city, area);
         return ResponseHelper.success(street);
@@ -123,12 +123,12 @@ public class CommonController {
     @ApiOperation(value = "轮播图列表")
     public ResponseHelper<Page<CarouselMap>> page(
             HttpServletRequest request,
-            @ApiParam(value = "状态(true:启用 false:禁用",required = false) @RequestParam(required = false) Boolean state,
-            @ApiParam(value = "轮播图类型 SHOP=商城 ESHOP=二手商城 YJHX=以旧换新入口",required = false) @RequestParam(required = false) String port,
-            @ApiParam(value = "页号",required = true) @RequestParam(required = true) Integer pageNum,
-            @ApiParam(value = "页大小",required = true) @RequestParam(required = true) Integer pageSize
+            @ApiParam(value = "状态(true:启用 false:禁用", required = false) @RequestParam(required = false) Boolean state,
+            @ApiParam(value = "轮播图类型 SHOP=商城 ESHOP=二手商城 YJHX=以旧换新入口", required = false) @RequestParam(required = false) String port,
+            @ApiParam(value = "页号", required = true) @RequestParam(required = true) Integer pageNum,
+            @ApiParam(value = "页大小", required = true) @RequestParam(required = true) Integer pageSize
     ) throws RemoteServiceException {
-        IPage<CarouselMap> page = carouselMapLogic.page(request,state,port,pageNum, pageSize);
+        IPage<CarouselMap> page = carouselMapLogic.page(request, state, port, pageNum, pageSize);
         return ResponseHelper.success(page);
     }
 
@@ -150,7 +150,7 @@ public class CommonController {
     @GetMapping("/scene")
     @ApiOperation(value = "获取微信scene参数")
     public ResponseHelper<String> page(
-            @ApiParam(value = "微信scene",required = true) @RequestParam(required = true) String scene
+            @ApiParam(value = "微信scene", required = true) @RequestParam(required = true) String scene
     ) throws RemoteServiceException {
         String sceneValue = commonLogic.getSceneValue(scene);
         return ResponseHelper.success(sceneValue);
@@ -172,12 +172,12 @@ public class CommonController {
 
     //企业微信回调
     @ApiNotAuth
-    @RequestMapping(value = "/callback",method = {RequestMethod.POST})
+    @RequestMapping(value = "/callback", method = {RequestMethod.POST})
     public String recePost(
-            @RequestParam(name="msg_signature",required = false) String msgSignature,
-            @RequestParam(name="timestamp",required = false) String timestamp,
-            @RequestParam(name="nonce",required = false) String nonce,
-            @RequestParam(name="echostr",required = false) String echostr
+            @RequestParam(name = "msg_signature", required = false) String msgSignature,
+            @RequestParam(name = "timestamp", required = false) String timestamp,
+            @RequestParam(name = "nonce", required = false) String nonce,
+            @RequestParam(name = "echostr", required = false) String echostr
     ) throws AesException {
         //String s = new WXBizJsonMsgCrypt(workToken, encodingAesKey,corpId).VerifyURL(msgSignature, timestamp, nonce, echostr);
         return "success";
@@ -185,20 +185,33 @@ public class CommonController {
 
     @GetMapping("/getVerifi")
     @ApiOperation(value = "获取拖拽式验证码")
-    public ResponseHelper<Map<String, Object>> getVerifi(){
+    public ResponseHelper<Map<String, Object>> getVerifi() {
         Map<String, Object> map = VerifiUtils.getVerifi();
         Integer xWidth = (Integer) map.get("xWidth");
         String key = UUID.randomUUID().toString();
-        redisUtil.set(Constant.RedisPrefix.VERIFICATION + ":" + key,xWidth,2*60);
+        redisUtil.set(Constant.RedisPrefix.VERIFICATION + ":" + key, xWidth, 2 * 60);
         map.remove("xWidth");
-        map.put("key",key);
+        map.put("key", key);
+        return ResponseHelper.success(map);
+    }
+
+    @ApiNotAuth
+    @GetMapping("/not/auth/getVerifi")
+    @ApiOperation(value = "无授权获取拖拽式验证码")
+    public ResponseHelper<Map<String, Object>> notAuthGetVerifi() {
+        Map<String, Object> map = VerifiUtils.getVerifi();
+        Integer xWidth = (Integer) map.get("xWidth");
+        String key = UUID.randomUUID().toString();
+        redisUtil.set(Constant.RedisPrefix.VERIFICATION + ":" + key, xWidth, 2 * 60);
+        map.remove("xWidth");
+        map.put("key", key);
         return ResponseHelper.success(map);
     }
 
     @ApiNotAuth
     @GetMapping("/config/get")
     @ApiOperation("获取小程序配置")
-    public ResponseHelper<AdminCompanyWechat> getConfig(HttpServletRequest request){
+    public ResponseHelper<AdminCompanyWechat> getConfig(HttpServletRequest request) {
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
         //剔除不返回的内容
         currentCompanyWechat.setAppId(null);
@@ -227,7 +240,7 @@ public class CommonController {
 
     @ApiNotAuth
     @GetMapping("/getfile")
-    public ResponseHelper<String> getfile(@RequestParam(required = true) String id){
+    public ResponseHelper<String> getfile(@RequestParam(required = true) String id) {
         OrderTax orderTax = orderTaxService.getById(id);
         String taxLink = orderTax.getTaxLink();
         return ResponseHelper.success(taxLink);

+ 4 - 2
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/user/UserController.java

@@ -357,9 +357,11 @@ public class UserController {
     @GetMapping("/send/message/code")
     @ApiOperation(value = "发送短信验证码")
     public ResponseHelper messageCode(
-            @ApiParam(value = "手机码",required = true) @RequestParam String mobile
+            @ApiParam(value = "手机码",required = true) @RequestParam String mobile,
+            @ApiParam(value = "滑动验证key",required = false) @RequestParam(required = false) String key,
+            @ApiParam(value = "滑动验证数值",required = false) @RequestParam(required = false) String vrifyCode
     ) throws Exception {
-        userLogic.sendMessageCode(mobile);
+        userLogic.sendMessageCode(mobile, key, vrifyCode);
         return ResponseHelper.success();
     }
 

+ 37 - 31
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/common/SMSLogic.java

@@ -38,15 +38,15 @@ public class SMSLogic {
     @Value("${spring.profiles.active}")
     private String active;
 
-    private  static String accessKeyId = "LTAI5tDHiEGKuwzNhW2gLPyc";
-    private  static String accessKeySecret = "NVXSx3Gj7fHv6unGwWgalJh49uMZOI";
-    private  static String SIGN_NAME = "售修宝";
+    private static String accessKeyId = "LTAI5tDHiEGKuwzNhW2gLPyc";
+    private static String accessKeySecret = "NVXSx3Gj7fHv6unGwWgalJh49uMZOI";
+    private static String SIGN_NAME = "售修宝";
     //短信验证码
-    private  static String TEMPLATE_SMS_CODE = "SMS_465295106";
+    private static String TEMPLATE_SMS_CODE = "SMS_465295106";
 
     @PostConstruct
-    public void init(){
-        if(StringUtils.equals(active,"prdjx")){
+    public void init() {
+        if (StringUtils.equals(active, "prdjx")) {
             accessKeyId = "LTAI5tBYgEPwxHyYeafvqJxW";
             accessKeySecret = "NRQyHnrYTx65HeMb1TaNKM7e8BTqVf";
             SIGN_NAME = "匠心服务社区";
@@ -69,14 +69,15 @@ public class SMSLogic {
 
     /**
      * 发送优惠申请通知
-     * @param mobile 手机号
-     * @param orderNo  订单号
+     *
+     * @param mobile      手机号
+     * @param orderNo     订单号
      * @param totalAmount 当前金额
-     * @param discunt 优惠金额
-     * @param name 申请人
-     * @param user 收货人
+     * @param discunt     优惠金额
+     * @param name        申请人
+     * @param user        收货人
      */
-    public void sendDiscountNotice(String mobile, String orderNo, BigDecimal totalAmount,BigDecimal discunt,String name,String user){
+    public void sendDiscountNotice(String mobile, String orderNo, BigDecimal totalAmount, BigDecimal discunt, String name, String user) {
         try {
             String orderNo2 = orderNo.substring(orderNo.length() - 6, orderNo.length());
             Map<String, Object> map = new HashMap<>();
@@ -86,16 +87,17 @@ public class SMSLogic {
             map.put("name", name);
             map.put("user", user);
             this.send(mobile, this.TEMPLATE_SMS_DISCOUNT, map);
-        }catch(Exception e){
-            log.error("发送优惠申请通知失败",e);
+        } catch (Exception e) {
+            log.error("发送优惠申请通知失败", e);
         }
     }
 
 
     /**
      * 发送短信验证码
-     * @param mobile 手机号
-     * @param key 拖拽式验证码的key
+     *
+     * @param mobile    手机号
+     * @param key       拖拽式验证码的key
      * @param vrifyCode 拖拽式验证码的x轴值
      * @throws Exception
      */
@@ -129,17 +131,17 @@ public class SMSLogic {
         smsRecord.insert();
 
         //记录发送的code
-        redisUtil.set(Constant.RedisPrefix.SMS + ":" + mobile,code,5*60);
+        redisUtil.set(Constant.RedisPrefix.SMS + ":" + mobile, code, 5 * 60);
     }
 
 
     /**
      * 校验短信验证码的正确性
      */
-    public void checkSmsCode(String mobile,String code) throws RemoteServiceException {
+    public void checkSmsCode(String mobile, String code) throws RemoteServiceException {
         String redisKey = Constant.RedisPrefix.SMS + ":" + mobile;
-        String value = (String)redisUtil.get(redisKey);
-        if(!StringUtils.equals(value,code)){
+        String value = (String) redisUtil.get(redisKey);
+        if (!StringUtils.equals(value, code)) {
             throw new RemoteServiceException("短信验证失败");
         }
         redisUtil.del(redisKey);
@@ -154,7 +156,7 @@ public class SMSLogic {
      */
     private void checkSendTime(String mobile) throws RemoteServiceException {
         String key = Constant.RedisPrefix.SMS + ":" + mobile;
-        if(redisUtil.hasKey(key)){
+        if (redisUtil.hasKey(key)) {
             throw new RemoteServiceException("发送短信间隔时间太短,请耐心等候");
         }
     }
@@ -168,7 +170,7 @@ public class SMSLogic {
      * @return
      */
     private boolean checkVrifyCode(String key, String vrifyCode) throws RemoteServiceException {
-        Object serverCode = redisUtil.get(Constant.RedisPrefix.VERIFICATION +":"+key);
+        Object serverCode = redisUtil.get(Constant.RedisPrefix.VERIFICATION + ":" + key);
         if (serverCode == null) {
             throw new RemoteServiceException("验证码超时");
         }
@@ -176,7 +178,7 @@ public class SMSLogic {
         int code = (int) serverCode;
         int code2 = Integer.parseInt(vrifyCode);
         if (code >= (code2 - 15) && code <= (code2 + 15)) {
-            redisUtil.del(Constant.RedisPrefix.VERIFICATION +":"+key);
+            redisUtil.del(Constant.RedisPrefix.VERIFICATION + ":" + key);
             return true;
         } else {
             throw new RemoteServiceException("验证码校验不通过");
@@ -184,9 +186,7 @@ public class SMSLogic {
     }
 
 
-
-
-    private String send(String mobile,String templateCode,Map<String,Object> param) throws ClientException, com.aliyuncs.exceptions.ClientException {
+    private String send(String mobile, String templateCode, Map<String, Object> param) throws ClientException, com.aliyuncs.exceptions.ClientException {
 
         DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
         IAcsClient client = new DefaultAcsClient(profile);
@@ -209,22 +209,28 @@ public class SMSLogic {
         log.info("短信验证返回数据 :" + response.getData());
 
         String dateRes = response.getData();
-        Map<String,Object> smsRsp = JSON.parseObject(dateRes);
+        Map<String, Object> smsRsp = JSON.parseObject(dateRes);
         //获取数据
         String codeRes = smsRsp.get("Code").toString();
-        if(!codeRes.equals("OK")) {
-            log.error("短信发送失败,mobile:{}",mobile);
+        if (!codeRes.equals("OK")) {
+            log.error("短信发送失败,mobile:{}", mobile);
         }
         return content;
     }
 
 
-    public void sendSms(String mobile) throws Exception {
+    public void sendSms2(String mobile, String key, String vrifyCode) throws Exception {
+        if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(vrifyCode)) {
+            boolean b = this.checkVrifyCode(key, vrifyCode);
+            if (!b) {
+                throw new RemoteServiceException("验证码不通过");
+            }
+        }
         //限制不能频繁发送
         this.checkSendTime(mobile);
 
         //6位随机数
-        if(!active.equals("prd")){
+        if (!active.equals("prd")) {
             //记录发送的code
             redisUtil.set(Constant.RedisPrefix.SMS + ":" + mobile, "000000", 2 * 60);
         } else {

+ 5 - 5
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/user/UserLogic.java

@@ -1207,10 +1207,10 @@ public class UserLogic {
         this.addUserLog(user);
     }
 
-    public void sendMessageCode(String mobile) throws Exception {
-//        if (StringUtils.isEmpty(mobile) || mobile.length() < 11) {
-//            throw new RemoteServiceException("请输入正确手机号");
-//        }
+    public void sendMessageCode(String mobile, String key, String vrifyCode) throws Exception {
+        if (StringUtils.isEmpty(mobile) || mobile.length() < 11) {
+            throw new RemoteServiceException("请输入正确手机号");
+        }
 
         // 查询师傅手机号
         UserWait userWait = userWaitService.lambdaQuery()
@@ -1223,7 +1223,7 @@ public class UserLogic {
         }
 
         // 向手机号发送验证码
-        smsLogic.sendSms(mobile);
+        smsLogic.sendSms2(mobile, key, vrifyCode);
     }
 
     public UserWxBean workerMobileLogin(String mobile, String messageCode) {