Browse Source

优化完善

master
wxc 2 months ago
parent
commit
0e7b926a16
  1. 10
      mailbox-outer/pom.xml
  2. 30
      mailbox-outer/src/main/java/com/biutag/outer/config/CorsConfig.java
  3. 10
      mailbox-outer/src/main/java/com/biutag/outer/config/InterceptorConfig.java
  4. 2
      mailbox-outer/src/main/java/com/biutag/outer/config/XybProperties.java
  5. 38
      mailbox-outer/src/main/java/com/biutag/outer/controller/AuthController.java
  6. 14
      mailbox-outer/src/main/java/com/biutag/outer/enums/RealLvlEnum.java
  7. 1
      mailbox-outer/src/main/java/com/biutag/outer/job/Job.java
  8. 10
      mailbox-outer/src/main/java/com/biutag/outer/service/UserService.java
  9. 6
      mailbox-outer/src/main/java/com/biutag/outer/util/XybApi.java
  10. 11
      mailbox-outer/src/main/resources/application-dev.yml
  11. 5
      mailbox-outer/src/main/resources/application-prod.yml
  12. 4
      mailbox-outer/src/main/resources/application.yml
  13. 38
      mailbox-outer/src/test/java/com/biutag/outer/XybTest.java

10
mailbox-outer/pom.xml

@ -44,9 +44,15 @@
<artifactId>tongweb-spring-boot-starter-3.x</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>Vastbase</groupId>-->
<!-- <artifactId>VastbaseG100_jdbc</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>Vastbase</groupId>
<artifactId>VastbaseG100_jdbc</artifactId>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
</dependency>
<dependency>

30
mailbox-outer/src/main/java/com/biutag/outer/config/CorsConfig.java

@ -0,0 +1,30 @@
package com.biutag.outer.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* @author wxc
* @date 2025/9/30
*/
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOriginPattern("*");
config.addAllowedMethod("*");
config.addAllowedHeader("*");
config.setAllowCredentials(true);
config.setMaxAge(3600L);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

10
mailbox-outer/src/main/java/com/biutag/outer/config/InterceptorConfig.java

@ -1,26 +1,17 @@
package com.biutag.outer.config;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.biutag.exception.AuthException;
import com.biutag.outer.config.annotation.RepeatSubmit;
import com.biutag.outer.domain.bo.AuthUser;
import com.biutag.outer.util.TokenUtil;
import com.biutag.outer.util.UserHelper;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
/**
* @author wxc
* @date 2024/1/8
@ -37,6 +28,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
"/auth/openid",
"/auth/login",
"/auth/wx/faceAuth",
"/auth/xyb",
"/wx/app/login",
"/file/stream/**",
"/api/**",

2
mailbox-outer/src/main/java/com/biutag/outer/config/XybProperties.java

@ -13,6 +13,8 @@ import org.springframework.context.annotation.Configuration;
)
public class XybProperties {
private String url;
private String clinetId;
private String publicKey;

38
mailbox-outer/src/main/java/com/biutag/outer/controller/AuthController.java

@ -5,6 +5,7 @@ import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.biutag.aop.NotLogin;
import com.biutag.core.AjaxResult;
import com.biutag.enums.ErrorEnum;
@ -13,6 +14,8 @@ import com.biutag.exception.BusinessException;
import com.biutag.outer.domain.User;
import com.biutag.outer.domain.bo.AuthUser;
import com.biutag.outer.domain.bo.FaceAuthBo;
import com.biutag.outer.domain.vo.XybUserInfo;
import com.biutag.outer.enums.RealLvlEnum;
import com.biutag.outer.service.FaceAuthService;
import com.biutag.outer.service.UserService;
import com.biutag.outer.util.*;
@ -27,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Validated
@ -142,4 +146,38 @@ public class AuthController {
return AjaxResult.success(UserHelper.getCurrentUser());
}
/**
* 湘易办认证
* @param assessLink
* @return
*/
@PostMapping("xyb")
public AjaxResult<JSONObject> auth(@RequestParam String assessLink) {
XybUserInfo xybUserInfo = XybApi.getXybUserInfo(assessLink);
if (Objects.isNull(xybUserInfo)) {
throw new AuthException();
}
if (RealLvlEnum.RC01.name().equals(xybUserInfo.getRealLvl()) || RealLvlEnum.RC02.name().equals(xybUserInfo.getRealLvl())) {
throw new RuntimeException("尊敬的用户,为确保您的信件的真实性和符合国家法规,我们需要您完成实名认证。认证后即可使用局长信箱的服务与功能。");
}
User user = userService.getByIdCard(xybUserInfo.getCertificateNum());
if (user == null) {
user = new User();
user.setRealName(user.getRealName());
user.setIdCard(user.getIdCard());
user.setPhone(user.getPhone());
user.setCreateTime(LocalDateTime.now());
userService.save(user);
} else {
if (StrUtil.isBlank(user.getRealName()) || StrUtil.isBlank(user.getPhone()) ) {
userService.update(new LambdaUpdateWrapper<User>()
.eq(User::getIdCard, user.getIdCard())
.set(User::getRealName, user.getRealName())
.set(User::getPhone, user.getPhone()));
}
}
log.info("登录用户 身份证:{},姓名:{}", user.getIdCard(), user.getRealName());
user.setOpenid(xybUserInfo.getId());
return AjaxResult.success(JSONObject.of("token", TokenUtil.set(AuthUser.of(user)), "user", user));
}
}

14
mailbox-outer/src/main/java/com/biutag/outer/enums/RealLvlEnum.java

@ -0,0 +1,14 @@
package com.biutag.outer.enums;
/**
* @author wxc
* @date 2025/9/28
*/
public enum RealLvlEnum {
RC01,
RC02,
RC03,
RC04,
RC05;
}

1
mailbox-outer/src/main/java/com/biutag/outer/job/Job.java

@ -349,7 +349,6 @@ public class Job {
if (!httpResponse1.isOk()) {
throw new RuntimeException(String.format("httpCode: %s", httpResponse1.getStatus()));
}
log.info("返回结果:{}", httpResponse1.body());
String responseBody = httpResponse1.body();
JSONObject jsonObject = JSON.parseObject(responseBody);
JSONArray dataArray = jsonObject.getJSONArray("data");

10
mailbox-outer/src/main/java/com/biutag/outer/service/UserService.java

@ -12,6 +12,8 @@ import com.biutag.outer.util.UserHelper;
import com.biutag.outer.validate.UserLoginsValidate;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserService extends ServiceImpl<UserMapper, User> {
@ -19,6 +21,14 @@ public class UserService extends ServiceImpl<UserMapper, User> {
return getOne(new LambdaQueryWrapper<User>().eq(User::getOpenid, openid));
}
public User getByIdCard(String idCard) {
List<User> list = list(new LambdaQueryWrapper<User>().eq(User::getIdCard, idCard));
if (list.isEmpty()) {
return null;
}
return list.get(0);
}
public boolean updatePhoneByCurrent(String phone, String idCard) {
AuthUser currentUser = UserHelper.getCurrentUser();
LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<User>().eq(User::getId, currentUser.getId()).set(User::getPhone, phone);

6
mailbox-outer/src/main/java/com/biutag/outer/util/XybApi.java

@ -23,7 +23,7 @@ public class XybApi {
public static XybUserInfo getXybUserInfo(String accessLink) {
// https://mycs.csbtv.com
String url = String.format("https://mycs.csbtv.com/my-exclusive-api/xyb/getXybUserInfo?accessLink=%s&clientId=%s", accessLink,
String url = String.format("%s/my-exclusive-api/xyb/getXybUserInfo?accessLink=%s&clientId=%s", xybProperties.getUrl(), accessLink,
xybProperties.getClinetId());
log.info(url);
HttpResponse httpResponse = HttpUtil.createGet(url)
@ -34,6 +34,10 @@ public class XybApi {
throw new RuntimeException("湘易办服务异常");
}
JSONObject response = JSON.parseObject(httpResponse.body());
if (!response.getInteger("code").equals(200)) {
log.error("湘易办服务异常: {}", response.toJSONString());
throw new RuntimeException("认证失败,请重试");
}
RSA rsaPri = new RSA(null, xybProperties.getPublicKey());
String jsonStr = rsaPri.decryptStr(response.getString("data"), KeyType.PublicKey);
// String jsonStr = rsaPri.decryptStr("HdLGrWa3fg1hBdYpQHhpG9L1QMi2FnhN6ZsXzEXumXnPnwDauG7t2efZ2eFIM7kifFurXU6DftULecezi2ouUVzWyqMffBfZDzlPrapQgQcAVpV8N8VMEH8FwgiAg0yjP9AwdKpsfOGhiEGkascaj2U99gpqNL4P02Vdz67sbnVmkjD3VWOZkh6P5h1i12ldEZTdoLmYT24V5n4QnK7O63oSIDMzaOH1A8ZhBKpYuG0XqzvklpHpllthqajMsAtXN3RFcXmvzQX8aIm9QHDECHl4syl1SJgegdJuyngbFzOkmUrBLVSRrBBRsHXMTg/Iydb9cC3CkyNlLEHqCgJwGg==", KeyType.PublicKey);

11
mailbox-outer/src/main/resources/application-dev.yml

@ -1,8 +1,8 @@
spring:
datasource:
url: jdbc:postgresql://58.51.152.18:10642/mailbox?currentSchema=mailbox-outer
username: alphay
password: alphay@123
url: jdbc:postgresql://172.31.217.20:30924/mailbox?currentSchema=mailbox_outer
username: pg
password: ip12341234
oss:
minio:
@ -17,3 +17,8 @@ mailbox:
weixin:
url: https://api.weixin.qq.com
xyb:
url: https://mycs.csbtv.com
clinet-id: VON6F9E15L
public-key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFBLOuFMyRN9QR2oqAwaWbrICn83E0JEP5n+8LFet0Dlj11nvzCmJTUCuy0Dx2YDa2lhr/b+CvjWy/qqdb7wbKJSo9z8MvkAAC/uEWaKsludTL8EUWttlwiXJZmMfj5QMOVfCbVCpI91+rBcWRR8Vg5MQGqDh0ZA4ym5j6mGYyRwIDAQAB

5
mailbox-outer/src/main/resources/application-prod.yml

@ -21,3 +21,8 @@ mailbox:
weixin:
url: http://172.24.138.108:6060
xyb:
url: http://172.24.138.108/xyb
clinet-id: VON6F9E15L
public-key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFBLOuFMyRN9QR2oqAwaWbrICn83E0JEP5n+8LFet0Dlj11nvzCmJTUCuy0Dx2YDa2lhr/b+CvjWy/qqdb7wbKJSo9z8MvkAAC/uEWaKsludTL8EUWttlwiXJZmMfj5QMOVfCbVCpI91+rBcWRR8Vg5MQGqDh0ZA4ym5j6mGYyRwIDAQAB

4
mailbox-outer/src/main/resources/application.yml

@ -33,7 +33,3 @@ spring:
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
xyb:
clinet-id: VON6F9E15L
public-key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFBLOuFMyRN9QR2oqAwaWbrICn83E0JEP5n+8LFet0Dlj11nvzCmJTUCuy0Dx2YDa2lhr/b+CvjWy/qqdb7wbKJSo9z8MvkAAC/uEWaKsludTL8EUWttlwiXJZmMfj5QMOVfCbVCpI91+rBcWRR8Vg5MQGqDh0ZA4ym5j6mGYyRwIDAQAB

38
mailbox-outer/src/test/java/com/biutag/outer/XybTest.java

@ -0,0 +1,38 @@
package com.biutag.outer;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.biutag.outer.domain.vo.XybUserInfo;
import com.biutag.outer.util.XybApi;
import org.junit.jupiter.api.Test;
/**
* @author wxc
* @date 2025/9/28
*/
public class XybTest {
@Test
public void test() {
String accessLink = "code_if8dCnu8TgyTk-USgkzH_Q";
String url = String.format("https://mycs.csbtv.com/my-exclusive-api/xyb/getXybUserInfo?accessLink=%s&clientId=%s", accessLink,
"VON6F9E15L");
HttpResponse httpResponse = HttpUtil.createGet(url)
.execute();
if (!httpResponse.isOk()) {
throw new RuntimeException("湘易办服务异常");
}
System.out.println(httpResponse.body());
JSONObject response = JSON.parseObject(httpResponse.body());
RSA rsaPri = new RSA(null, "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFBLOuFMyRN9QR2oqAwaWbrICn83E0JEP5n+8LFet0Dlj11nvzCmJTUCuy0Dx2YDa2lhr/b+CvjWy/qqdb7wbKJSo9z8MvkAAC/uEWaKsludTL8EUWttlwiXJZmMfj5QMOVfCbVCpI91+rBcWRR8Vg5MQGqDh0ZA4ym5j6mGYyRwIDAQAB");
String jsonStr = rsaPri.decryptStr(response.getString("data"), KeyType.PublicKey);
// String jsonStr = rsaPri.decryptStr("HdLGrWa3fg1hBdYpQHhpG9L1QMi2FnhN6ZsXzEXumXnPnwDauG7t2efZ2eFIM7kifFurXU6DftULecezi2ouUVzWyqMffBfZDzlPrapQgQcAVpV8N8VMEH8FwgiAg0yjP9AwdKpsfOGhiEGkascaj2U99gpqNL4P02Vdz67sbnVmkjD3VWOZkh6P5h1i12ldEZTdoLmYT24V5n4QnK7O63oSIDMzaOH1A8ZhBKpYuG0XqzvklpHpllthqajMsAtXN3RFcXmvzQX8aIm9QHDECHl4syl1SJgegdJuyngbFzOkmUrBLVSRrBBRsHXMTg/Iydb9cC3CkyNlLEHqCgJwGg==", KeyType.PublicKey);
XybUserInfo xybUserInfo = JSON.parseObject(jsonStr, XybUserInfo.class);
System.out.println(xybUserInfo);
}
}
Loading…
Cancel
Save