Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

lwhhszx 1 gadu atpakaļ
vecāks
revīzija
92dd5890af

+ 11 - 0
pom.xml

@@ -263,6 +263,17 @@
             <version>2.0</version>
         </dependency>
 
+        <!-- 短信接口 -->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-core</artifactId>
+            <version>4.5.16</version>
+        </dependency>
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
+            <version>1.1.0</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/business/common/Response.java

@@ -72,7 +72,7 @@ public class Response {
 
     public static Response error(String message) {
         Response response = new Response();
-        response.setCode(ResponseEnum.ERROR.getCode());
+        response.setCode(ResponseEnum.SYSTEM_ERROR.getCode());
         response.setData(Boolean.FALSE);
         response.setMessage(message);
         return response;

+ 0 - 110
src/main/java/com/example/xiaoshiweixinback/business/common/base/Constants.java

@@ -1,110 +0,0 @@
-package com.example.xiaoshiweixinback.business.common.base;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class Constants {
-
-    public static final String API_XIAO_SHI_WXBACK = "/api/xiaoshi/weixinback";
-    public static final String ADMIN_USERNAME = "admin";
-
-    public static final Integer PATENT_CLASS_NUMBER_IPC = 1;
-    public static final Integer PATENT_CLASS_NUMBER_CPC = 2;
-    public static final Integer PATENT_CLASS_NUMBER_UPC = 3;
-    public static final Integer PATENT_CLASS_NUMBER_LOC = 4;
-    public static final Integer MAX_IMPORT_TASK_COUNT=5;
-    public static final  Integer IMPORT_PATENT_TO=1;
-    /**
-     * 分隔符-竖线
-     */
-    public static final String SEPARATOR_VERTICAL_BAR = " | ";
-
-    /**
-     * 系统字段类型-查询检索
-     */
-    public static final String SYSTEM_FIELD_QUERY = "query";
-
-    /**
-     * 系统字段类型-专利导出
-     */
-    public static final String SYSTEM_FIELD_EXPORT = "export";
-
-    /**
-     * 系统字段类型-专利列表
-     */
-    public static final String SYSTEM_FIELD_PATENT_LIST = "list";
-
-    /**
-     * 系统字段类型-专题库字段
-     */
-    public static final String SYSTEM_FIELD_PROJECT = "project";
-
-    /**
-     * 专题库导入专利任务名称
-     */
-    public static final Integer TASK_IMPORT_PATENT = 1;
-
-    /**
-     * 专利说明书导入任务名称
-     */
-    public static final Integer TASK_IMPORT_PATENT_INSTRUCTION = 3;
-
-    /**
-     * 专利导出任务名称
-     */
-    public static final Integer TASK_EXPORT_PATENT = 2;
-
-    /**
-     * 日期位移值
-     */
-    public static final Map<String, Integer> DATE_OFFSET = new HashMap<String, Integer>() {{
-        put("月", -1);
-        put("季", -3);
-        put("半年", -6);
-        put("年", -12);
-        put("2年", -24);
-        put("3年", -36);
-        put("5年", -60);
-    }};
-
-    /**
-     * 专利类型
-     */
-    public static final String PATENT_TYPE = "PATENT_TYPE";
-
-    /**
-     * 机构类型
-     */
-    public static final String ORGAN_TYPE = "ORGAN_TYPE";
-
-    /**
-     * 许可人/被许可人
-     */
-    public static final String LICENSOR_TYPE = "LICENSOR_TYPE";
-
-    /**
-     * 简单法律状态
-     */
-    public static final String PATENT_SIMPLE_STATUS = "PATENT_SIMPLE_STATUS";
-
-    /**
-     * 国家
-     */
-    public static final String COUNTRIES = "COUNTRIES";
-
-    /**
-     * 法律状态
-     */
-    public static final String PATENT_STATUS = "PATENT_STATUS";
-
-    /**
-     * 企业应用场景
-     */
-    public static final String ENTERPRISE_APPLICATION_SCENARIO = "ENTERPRISE_APPLICATION_SCENARIO";
-
-    /**
-     * 调查类型
-     */
-    public static final String INVESTIGATION_TYPE = "INVESTIGATION_TYPE";
-
-}

+ 5 - 6
src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java

@@ -1,25 +1,27 @@
 package com.example.xiaoshiweixinback.business.exception;
 
 
+import lombok.Getter;
+
 /**
  * @ClassName
  * @Description 业务异常
- * @Author 陈凯裕
- * @Date 2022/6/27 18:02
  * @Version TODO
  **/
+@Getter
 public class BusinessException extends RuntimeException {
 
-	private static final long serialVersionUID = 3200004685293133433L;
 	private String errorCode;// 异常代码
 	private String errorMessage;// 异常信息
 
 	public BusinessException(String errorCode, String errorMessage) {
+		super(errorMessage);
 		this.errorCode = errorCode;
 		this.errorMessage = errorMessage;
 	}
 
 	public BusinessException(ExceptionEnum e) {
+		super(e.getMessage());
 		this.errorMessage = e.getMessage();
 		this.errorCode = e.getCode();
 	}
@@ -41,8 +43,5 @@ public class BusinessException extends RuntimeException {
 		this.errorMessage = errorMessage;
 	}
 
-	public static long getSerialversionuid() {
-		return serialVersionUID;
-	}
 
 }

+ 5 - 2
src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java

@@ -1,5 +1,8 @@
 package com.example.xiaoshiweixinback.business.exception;
 
+import lombok.Getter;
+
+@Getter
 public enum ExceptionEnum {
 
     /*APP端 100000-300000*/
@@ -7,9 +10,9 @@ public enum ExceptionEnum {
     SYSTEM_ERROR("999999", "系统异常"),
     PARAMETER_VERIFICATION_ERROR("000001", "数据参数校验异常"),
     PHONE_FORMAT_ERROR("000002","手机号格式错误"),
-    CODE_WRONG("10002","验证码错误"),
-
 
+    VERIFY_CODE("10001", "校验码失效"),
+    CODE_WRONG("10002","验证码错误"),
     INIT_GENERICITY_BEAN_ERROR("10003","泛型实例化异常"),
     THE_PHONE_CANNOT_BE_EXIST("10004","手机号已存在"),
     THE_CODE_IS_NOT_NULL("10006","验证码不能为空");

+ 2 - 1
src/main/java/com/example/xiaoshiweixinback/business/exception/GlobalExceptionHandler.java

@@ -3,6 +3,7 @@ package com.example.xiaoshiweixinback.business.exception;
 import com.example.xiaoshiweixinback.business.common.log.LogHelper;
 import com.example.xiaoshiweixinback.business.common.response.ResponseData;
 import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.converter.HttpMessageNotReadableException;
@@ -11,7 +12,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 
-
+@Slf4j
 @RestControllerAdvice
 public class GlobalExceptionHandler {
 

+ 15 - 0
src/main/java/com/example/xiaoshiweixinback/business/exception/XiaoShiException.java

@@ -0,0 +1,15 @@
+package com.example.xiaoshiweixinback.business.exception;
+
+/**
+ * 整个项目通用异常类
+ *
+ * @Author chenyu
+ * @Date 2023/3/7
+ */
+public class XiaoShiException extends RuntimeException {
+
+    public XiaoShiException(String message) {
+        super(message);
+    }
+
+}

+ 9 - 7
src/main/java/com/example/xiaoshiweixinback/controller/LoginController.java

@@ -1,8 +1,8 @@
 package com.example.xiaoshiweixinback.controller;
 
 
+import com.example.xiaoshiweixinback.business.common.Constants;
 import com.example.xiaoshiweixinback.business.common.Response;
-import com.example.xiaoshiweixinback.business.common.base.Constants;
 import com.example.xiaoshiweixinback.entity.dto.person.*;
 import com.example.xiaoshiweixinback.entity.vo.person.LoginByWxVO;
 import com.example.xiaoshiweixinback.entity.vo.person.LoginVO;
@@ -21,7 +21,7 @@ import java.util.Map;
  *
  * @author: 高昌奎
  */
-@RequestMapping(Constants.API_XIAO_SHI_WXBACK + "/account")
+@RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/account")
 @RestController
 public class LoginController {
 
@@ -55,11 +55,13 @@ public class LoginController {
     @Operation(summary = "发送验证码")
     @PostMapping("/sendCode")
     public Response sendCode(@RequestBody @Valid SendCodeDTO vo) {
-        boolean b = loginService.sendCode(vo);
-        if (!b) {
-            return Response.error("发送验证码失败");
+        boolean b = false;
+        try {
+            b = loginService.sendCode(vo);
+        } catch (Exception e) {
+            return Response.error(e.getMessage());
         }
-        return Response.success("发送验证码成功");
+        return Response.success(b);
     }
 
     @PostMapping("/verifyCode")
@@ -69,7 +71,7 @@ public class LoginController {
         try {
             map = loginService.verifyCode(vo);
         } catch (Exception e) {
-            return Response.success(e.getMessage());
+            return Response.error(e.getMessage());
         }
         return Response.success(map);
     }

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/entity/vo/person/LoginByWxVO.java

@@ -8,7 +8,7 @@ public class LoginByWxVO {
 
     private String userName;
 
-    private String phone;
+    private String phoneNum;
 
     private String name;
 

+ 43 - 18
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -23,6 +23,7 @@ import com.example.xiaoshiweixinback.entity.vo.person.PersonVO;
 import com.example.xiaoshiweixinback.mapper.PersonMapper;
 import com.example.xiaoshiweixinback.okhttp.RequestManager;
 import com.example.xiaoshiweixinback.okhttp.ResponseManager;
+import com.example.xiaoshiweixinback.service.common.SmsService;
 import org.apache.commons.codec.binary.Base64;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -50,12 +51,16 @@ public class LoginService {
     private RedisService redisService;
 
     @Autowired
-    private RedisUtil redisUtil;
+    private SmsService smsService;
 
     @Autowired
     private PersonMapper personMapper;
 
-
+    /**
+     * 手机号/账号登录
+     * @param dto
+     * @return
+     */
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public LoginVO loginByPhone(LoginDTO dto) {
         LogHelper.log("登录开始");
@@ -178,7 +183,7 @@ public class LoginService {
 
                     wxVO.setIfFirst(true);
                 }
-                wxVO.setPhone(phoneNumber);
+                wxVO.setPhoneNum(phoneNumber);
                 wxVO.setName(name);
                 wxVO.setFileGuid(fileGuid);
             }
@@ -189,23 +194,33 @@ public class LoginService {
         return wxVO;
     }
 
+    /**
+     * 发送验证码
+     * @param vo
+     * @return
+     */
     public boolean sendCode(SendCodeDTO vo) {
+        boolean flag = false;
         if (!RegexUtil.isPhoneLegal(vo.getPhoneNum())) {
             throw new BusinessException(ExceptionEnum.PHONE_FORMAT_ERROR);
         }
-        String checkCode = redisService.get(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum())).toString();
-        if (ToolUtil.isNotEmpty(checkCode) && ToolUtil.equals(checkCode,vo.getCheckCode())) {
+        Object checkCode = redisService.get(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()));
+        if (ToolUtil.isEmpty(checkCode)) {
+            throw new BusinessException(ExceptionEnum.VERIFY_CODE);
+        }
+        if (ToolUtil.isNotEmpty(checkCode.toString()) && ToolUtil.equals(checkCode.toString(),vo.getCheckCode())) {
+            //删除校验码
+            redisService.delete(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()));
             //生成验证码
             String random = RandomUtil.getSixRandom();
-            //手机号和验证码放进缓存 设置过期时间15m
+            //手机号和验证码放进缓存 设置过期时间5min
             redisService. set(AppCacheKeyUtil.getLoginMessageCode(vo.getPhoneNum()), random);
             redisService.expire(AppCacheKeyUtil.getLoginMessageCode(vo.getPhoneNum()), CacheTTLEnum.FIVE_MINUTE);
             //发送短信
-//        smsService.sendMessage(vo.getPhoneNo(), random);
-            return true;
-        } else {
-            return false;
+            smsService.sendMessage(vo.getPhoneNum(), random);
+            flag = true;
         }
+        return flag;
     }
 
     /**
@@ -227,10 +242,15 @@ public class LoginService {
         result.put("captcha", ImgUtil.toBase64DataUri(captcha.getImage(), "png"));
         result.put("uuid", uuid);
         //4.将验证码存放到Redis里面并设置过期时间为 60 单位:秒 KEY值格式为: 验证码:UUID  VALUE值为:验证码生成工具所生成的验证码
-//        redisUtil.setEx(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()), captcha.getCode(), 60, TimeUnit.SECONDS);
+        redisService.set(AppCacheKeyUtil.getCheckCode(vo.getPhoneNum()), captcha.getCode());
         return result;
     }
 
+    /**
+     * 查询个人信息
+     * @param vo
+     * @return
+     */
     public PersonVO selectPerson(PersonIdDTO vo) {
         Person person = personMapper.selectById(vo.getId());
         PersonVO personVO = new PersonVO();
@@ -238,6 +258,11 @@ public class LoginService {
         return personVO;
     }
 
+    /**
+     * 修改个人信息
+     * @param vo
+     * @return
+     */
     @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
     public boolean editPerson(EditPersonDTO vo) {
         if (!RegexUtil.isPhoneLegal(vo.getPhoneNum())) {
@@ -254,13 +279,6 @@ public class LoginService {
         return true;
     }
 
-    public String getToken() {
-        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
-        com.bjbz.common.jwt.JwtUserInfo jwtUserInfo = new com.bjbz.common.jwt.JwtUserInfo();
-        jwtUserInfo.setToken(uuid);
-        return jwtTokenUtil.generateToken(jwtUserInfo.toJsonString(), jwtTokenUtil.getRandomKey());
-    }
-
     /**
      * 退出登录
      *
@@ -278,6 +296,13 @@ public class LoginService {
         return true;
     }
 
+    public String getToken() {
+        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
+        com.bjbz.common.jwt.JwtUserInfo jwtUserInfo = new com.bjbz.common.jwt.JwtUserInfo();
+        jwtUserInfo.setToken(uuid);
+        return jwtTokenUtil.generateToken(jwtUserInfo.toJsonString(), jwtTokenUtil.getRandomKey());
+    }
+
     /**
      * 解密用户数据
      *

+ 45 - 0
src/main/java/com/example/xiaoshiweixinback/service/common/SmsService.java

@@ -0,0 +1,45 @@
+package com.example.xiaoshiweixinback.service.common;
+
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.profile.DefaultProfile;
+import com.google.gson.Gson;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SmsService {
+
+    @Value("${SMS.regionId}")
+    private String regionId;
+
+    @Value("${SMS.accessKeyId}")
+    private String accessKeyId;
+
+    @Value("${SMS.secret}")
+    private String secret;
+
+    public void sendMessage(String phoneNum,String random){
+
+        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
+        IAcsClient client = new DefaultAcsClient(profile);
+        SendSmsRequest request = new SendSmsRequest();
+//        String templateParam = "{\"code\":\"" + random + "\",\"message\":\"" + "为您的登陆验证码" + "\",\"validTime\":\"" + "5分钟" + "\"}";
+        String templateParam = "{\"code\":\"" + random + "\"}";
+        request.setPhoneNumbers(phoneNum);//接收短信的手机号码
+        request.setSignName("小世数字科技");//短信签名名称
+        request.setTemplateCode("SMS_296725687");//短信模板CODE
+        request.setTemplateParam(templateParam);//短信模板变量对应的实际值
+        try {
+            SendSmsResponse response = client.getAcsResponse(request);
+            System.out.println(new Gson().toJson(response));
+        } catch (ClientException e) {
+            System.out.println("ErrCode:" + e.getErrCode());
+            System.out.println("ErrMsg:" + e.getErrMsg());
+            System.out.println("RequestId:" + e.getRequestId());
+        }
+    }
+}

+ 7 - 0
src/main/resources/application-dev.yml

@@ -69,6 +69,13 @@ PASUrl: http://localhost:8877
 FMSUrl: http://localhost:8801
 FileSource: 1
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-dev1.yml

@@ -69,6 +69,13 @@ PASUrl: http://localhost:8877
 FMSUrl: http://localhost:8801
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-prodNetIn.yml

@@ -35,6 +35,13 @@ RMSUrl: http://localhost:8872
 FMSUrl: http://localhost:8801
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-prodNetOut.yml

@@ -33,6 +33,13 @@ RMSUrl: http://localhost:8872
 FMSUrl: http://localhost:8801
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-testNetIn.yml

@@ -69,6 +69,13 @@ PASUrl: http://localhost:8880
 FMSUrl: http://localhost:8885
 FileSource: 3
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application-testNetOut.yml

@@ -25,6 +25,13 @@ spring:
         exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
 authorUrl: http://localhost:8871
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 7 - 0
src/main/resources/application.yml

@@ -47,6 +47,13 @@ mybatis-plus:
   mapper-locations: classpath:mapper/*.xml
 queueName: emailProd.queue
 
+##################  短信 ####################
+SMS:
+  regionId: cn-shanghai
+  accessKeyId: LTAI5tGyG1Q7fKprgg1nWhXj
+  secret: Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN
+
+##################  微信小程序  ####################
 WeChat:
   appId: wxaefb842bd0b93ff0
   appSecret: 89fe0fb96472548d48f63b2f5c956537

+ 5 - 1
src/test/java/com/example/xiaoshiweixinback/XiaoshiWeixinbackApplicationTests.java

@@ -1,6 +1,7 @@
 package com.example.xiaoshiweixinback;
 
 import com.example.xiaoshiweixinback.entity.dto.person.PersonPhoneDTO;
+import com.example.xiaoshiweixinback.entity.dto.person.SendCodeDTO;
 import com.example.xiaoshiweixinback.service.LoginService;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +27,9 @@ class XiaoshiWeixinbackApplicationTests {
         dto.setPhoneNum("123456789");
         Map<String, String> map = loginService.verifyCode(dto);
         System.out.println(map);
-
+//        SendCodeDTO dto = new SendCodeDTO();
+//        dto.setPhoneNum("15705220533");
+//        boolean send = loginService.send(dto);
+//        System.out.println(send);
     }
 }