he2802 2 years ago
parent
commit
42ccf2ffd5

+ 54 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/distribution/SellerSmsController.java

@@ -0,0 +1,54 @@
+package com.zhongzheng.controller.distribution;
+
+import com.zhongzheng.common.core.controller.BaseController;
+import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.modules.alisms.bo.SmsAddBo;
+import com.zhongzheng.modules.alisms.service.IAliSmsService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 客户端用户Controller
+ *
+ * @author hjl
+ * @date 2021-06-08
+ */
+@Api(value = "短信控制器", tags = {"短信控制器"})
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/app/common/seller/sms")
+public class SellerSmsController extends BaseController {
+
+    private final IAliSmsService iSmsService;
+
+
+    @ApiOperation("获取业务员注册短信")
+    @PostMapping("/register")
+    public AjaxResult register(@RequestBody SmsAddBo bo) {
+        iSmsService.sendSellerRegisterSms(bo.getTel());
+        return AjaxResult.success();
+    }
+
+
+    @ApiOperation("获取业务员登录短信")
+    @PostMapping("/login")
+    public AjaxResult login(@RequestBody SmsAddBo bo) {
+        iSmsService.sendSellerLoginSms(bo.getTel());
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("获取业务员忘记短信")
+    @PostMapping("/forget")
+    public AjaxResult forget(@RequestBody SmsAddBo bo) {
+        iSmsService.sendSellerForgetSms(bo.getTel());
+        return AjaxResult.success();
+    }
+
+
+}

+ 7 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alisms/service/IAliSmsService.java

@@ -19,4 +19,11 @@ public interface IAliSmsService {
     Boolean sendPwdSms(String tel,String code);
 
     Boolean sendBindNewTelSms(String tel);
+
+
+    Boolean sendSellerRegisterSms(String tel);
+
+    Boolean sendSellerForgetSms(String tel);
+
+    Boolean sendSellerLoginSms(String tel);
 }

+ 102 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alisms/service/impl/AliSmsServiceImpl.java

@@ -17,6 +17,8 @@ import com.zhongzheng.modules.alisms.service.IAliSmsService;
 import com.zhongzheng.modules.alisms.vo.ResultBean;
 import com.zhongzheng.modules.base.bo.SmsAddBo;
 import com.zhongzheng.modules.base.service.ISmsService;
+import com.zhongzheng.modules.distribution.domain.DistributionSeller;
+import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
 import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.service.IUserService;
 import org.slf4j.Logger;
@@ -60,6 +62,9 @@ public class AliSmsServiceImpl implements IAliSmsService {
     @Autowired
     private ISmsService iSmsService;
 
+    @Autowired
+    private IDistributionSellerService iDistributionSellerService;
+
 
     @Override
     public ResultBean sendSms(String tel, String param) {
@@ -239,4 +244,101 @@ public class AliSmsServiceImpl implements IAliSmsService {
         }
         return false;
     }
+
+    @Override
+    public Boolean sendSellerRegisterSms(String tel) {
+        if(tel==null){
+            throw new CustomException("手机号码不能为空");
+        }
+        DistributionSeller seller = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
+        if(Validator.isNotNull(seller)){
+            throw new CustomException("该手机号已注册");
+        }
+        String code = ToolsUtils.getSmsCode();
+        String key = Constants.REGISTER_SMS + tel;
+        redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
+        try{
+            Map<String,Object> param = new HashMap<>();
+            param.put("code",code);
+            SendSmsResponse response = SmsUtils.sendSms(tel,SIGNNAME,REGISTERTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET);
+            System.out.println(response.getBody().getMessage());
+            if(response.getBody().getMessage().equals("OK")){
+                SmsAddBo smsAddBo = new SmsAddBo();
+                smsAddBo.setCode(code);
+                smsAddBo.setTel(tel);
+                smsAddBo.setType(6L);
+                smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+                iSmsService.insertByAddBo(smsAddBo);
+                return true;
+            }
+        }catch (Exception e){
+            throw new CustomException(e.getMessage());
+        }
+        return false;
+    }
+
+    @Override
+    public Boolean sendSellerForgetSms(String tel) {
+        if(tel==null){
+            throw new CustomException("手机号码不能为空");
+        }
+        DistributionSeller user = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
+        if(Validator.isEmpty(user)){
+            throw new CustomException("该手机号未注册");
+        }
+        String code = ToolsUtils.getSmsCode();
+        String key = Constants.FORGET_SMS + tel;
+        redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
+        try{
+            Map<String,Object> param = new HashMap<>();
+            param.put("code",code);
+            SendSmsResponse response = SmsUtils.sendSms(tel,SIGNNAME,FORGETTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET);
+            if(response.getBody().getMessage().equals("OK")){
+                SmsAddBo smsAddBo = new SmsAddBo();
+                smsAddBo.setCode(code);
+                smsAddBo.setTel(tel);
+                smsAddBo.setType(7L);
+                smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+                iSmsService.insertByAddBo(smsAddBo);
+                return true;
+            }
+        }catch (Exception e){
+            throw new CustomException(e.getMessage());
+        }
+        return false;
+    }
+
+    @Override
+    public Boolean sendSellerLoginSms(String tel) {
+        if(tel==null){
+            throw new CustomException("手机号码不能为空");
+        }
+        DistributionSeller user = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>()
+                .eq(DistributionSeller::getTelphone,EncryptHandler.encrypt(tel)).last("limit 1"));
+        if(Validator.isEmpty(user)){
+            throw new CustomException("该手机号未注册");
+        }
+        String code = ToolsUtils.getSmsCode();
+        String key = Constants.LOGIN_SMS + tel;
+        redisCache.setCacheObject(key,code,5, TimeUnit.MINUTES);//5分钟
+        try{
+            Map<String,Object> param = new HashMap<>();
+            param.put("code",code);
+            SendSmsResponse response = SmsUtils.sendSms(tel,SIGNNAME,LOGINTEMPLATECODE, JSON.toJSONString(param),ACCESSKEYID,ACCESSKEYSECRET);
+            if(response.getBody().getMessage().equals("OK")){
+                SmsAddBo smsAddBo = new SmsAddBo();
+                smsAddBo.setCode(code);
+                smsAddBo.setTel(tel);
+                smsAddBo.setType(8L);
+                smsAddBo.setIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+                iSmsService.insertByAddBo(smsAddBo);
+                return true;
+            }
+        }catch (Exception e){
+            throw new CustomException(e.getMessage());
+        }
+        return false;
+    }
 }