孙永军 2 éve
szülő
commit
0233a0fe18

+ 23 - 2
src/main/java/com/sxtvs/open/api/odata/controller/OauthRestController.java

@@ -5,7 +5,9 @@ import com.alibaba.fastjson.JSON;
 import com.sxtvs.open.api.odata.dto.RedirectDto;
 import com.sxtvs.open.api.odata.dto.weibo.WeiboCallbackDto;
 import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeResponse;
+import com.sxtvs.open.api.odata.entity.WxTicket;
 import com.sxtvs.open.api.odata.service.OauthService;
+import com.sxtvs.open.api.odata.service.WxTicketService;
 import com.sxtvs.open.api.odata.wxutil.WxCrypt;
 import com.sxtvs.open.api.odata.wxutil.WxXmlUtil;
 import com.sxtvs.open.core.advice.NoAPIResponse;
@@ -20,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Date;
+
 @RestController
 @RequestMapping("oauth")
 public class OauthRestController {
@@ -33,9 +37,9 @@ public class OauthRestController {
     @Autowired
     private OauthService oauthService;
 
-    @RequestMapping("weixin/auth")
+    @RequestMapping("weixin/auth/v2")
     @NoAPIResponse
-    public String auth(@RequestBody String body) {
+    public String authV2(@RequestBody String body) {
         logger.info("body", body, "key", "oauth/weixin/auth");
         var encrypt = WxXmlUtil.getEncrypt(body);
         logger.debug("data", encrypt);
@@ -47,6 +51,23 @@ public class OauthRestController {
         return "success";
     }
 
+    @Autowired
+    private WxTicketService wxTicketService;
+
+    @RequestMapping("weixin/auth")
+    @NoAPIResponse
+    public String auth(@RequestBody String body) {
+        logger.info("body {} ", body);
+        String xml = WxCrypt.decrypt(WxXmlUtil.getEncrypt(body));
+        String componentVerifyTicket = WxXmlUtil.getComponentVerifyTicket(xml);
+        WxTicket wxTicket = new WxTicket();
+        wxTicket.setId(1);
+        wxTicket.setTicket(componentVerifyTicket);
+        wxTicket.setUpdateTime(new Date());
+        wxTicketService.updateById(wxTicket);
+        return "success";
+    }
+
     @RequestMapping("douyin/code")
     @LoginRequired
     public RedirectDto douyinQrCode() {

+ 2 - 1
src/main/java/com/sxtvs/open/api/odata/service/OauthService.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeRequest;
 import com.sxtvs.open.api.odata.dto.wx.WxApiCreatePreAuthCodeResponse;
 import com.sxtvs.open.api.youmei.service.YoumeiAccountServiceImpl;
+import com.sxtvs.open.core.conf.Constant;
 import com.sxtvs.open.core.conf.OauthConfig;
 import com.sxtvs.open.core.sls.AliyunLogger;
 import lombok.SneakyThrows;
@@ -55,7 +56,7 @@ public class OauthService {
         authCodeRequest.setComponentAccessToken(ticket);
         var body = Request.post("https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?" +
                         "component_access_token=" + ticket)
-                .bodyString(objectMapper.writeValueAsString(Map.of("component_access_token", ticket, "component_appid", OauthConfig.wxClientKey)),
+                .bodyString(objectMapper.writeValueAsString(Map.of("component_appid", OauthConfig.wxClientKey)),
                         ContentType.APPLICATION_JSON)
                 .execute()
                 .returnContent()

+ 2 - 1
src/main/java/com/sxtvs/open/api/odata/service/WxRestService.java

@@ -15,6 +15,7 @@ import com.sxtvs.open.api.odata.entity.WxAccount;
 import com.sxtvs.open.api.odata.entity.WxAccountV2;
 import com.sxtvs.open.core.conf.Constant;
 import com.sxtvs.open.core.http.RequestUtil;
+import jakarta.annotation.Resource;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,7 +45,7 @@ public class WxRestService {
     @Autowired
     private WxAccountService wxAccountService;
 
-    @Autowired
+    @Resource
     private ObjectMapper objectMapper;
 
     @Autowired

+ 2 - 2
src/main/java/com/sxtvs/open/core/conf/OauthConfig.java

@@ -14,8 +14,8 @@ public class OauthConfig {
     public static String wxClientSecret = "934c2b93115ae6ec8472cf153e584124";
 
 
-    public static String weixinZhiHuiRongMeiAppId = "wx5e1699e1707030ac";
-    public static String weixinZhiHuiRongMeiSecret = "65c4f421f2bba4cd5d7f1219123e0fd9";
+    public static String weixinZhiHuiRongMeiAppId = "wx7040933fd0e4b0e8";
+    public static String weixinZhiHuiRongMeiSecret = "934c2b93115ae6ec8472cf153e584124";
 
     public static String bilibiliClientId = "e79e6fdef9d446d7";
     public static String bilibiliSecret = "70d40a332aa54132a72239efba022450";