2 Commits d972db296e ... 3586baac0e

Auteur SHA1 Message Date
  wuhongshuang 3586baac0e Merge remote-tracking branch 'origin/master' il y a 2 ans
  wuhongshuang 371b42faf7 优化微信绑定 il y a 2 ans

+ 13 - 12
src/main/java/com/szwl/controller/TWechatController.java

@@ -1,6 +1,7 @@
 package com.szwl.controller;
 
 
+import cn.com.crbank.ommo.exception.MyException;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -18,6 +19,7 @@ import com.szwl.service.TWechatService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -33,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.view.RedirectView;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -56,9 +59,10 @@ import java.util.*;
  * @author wuhs
  * @since 2023-05-19
  */
+@Slf4j
 @Api(value = "/WeChatController", tags = {"微信绑定接口"})
 @RestController
-@RequestMapping("/tWechat")
+    @RequestMapping("/tWechat")
 public class TWechatController {
 
     @Autowired
@@ -74,17 +78,14 @@ public class TWechatController {
     @Value("${oauth.wx.appsecret}")
     private String appsecret;
 
-    @Value("${oauth.callback.http}")
+    @Value("${oauth.callback.http:http://szwltest.sunzee.com.cn:49002}")
     private String http;
 
-
     @ApiOperation(value = "绑定微信")
-    @CrossOrigin(value = "https://open.weixin.qq.com/")
     @GetMapping("/bindWechat")
-    public R oauth(HttpServletResponse response, @RequestParam Long adminId) throws IOException {
-
+    public R bindWechat(@RequestParam Long adminId) throws Exception {
         if (adminId==null) {
-            return R.fail(ResponseCodesEnum.A0001, "参数为空");
+            throw new MyException("参数为空");
         }
         TAdmin tAdmin = tAdminService.getById(adminId);
         TWechat tWechat = new TWechat();
@@ -101,7 +102,7 @@ public class TWechatController {
                 tWechatService.save(tWechat);
             }
         } else {
-            return R.fail("用户不存在!");
+            throw new MyException("用户不存在!");
         }
         String path = http + "/tWechat/callback?";
 
@@ -112,16 +113,16 @@ public class TWechatController {
         }
 
         // 第一步:用户同意授权,获取code
-        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
+        String url = "http://szwltest.sunzee.com.cn/openWeixin/connect/oauth2/authorize?"
+//        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?"
                 + "appid=" + appid
                 + "&redirect_uri=" + path
                 + "&response_type=code"
                 + "&scope=snsapi_userinfo"
                 + "&state=" + adminId +
                 "#wechat_redirect";
-        response.sendRedirect(url);
-
-        return R.ok();
+//        response.sendRedirect(url);
+        return R.ok(url);
     }
 
 

+ 1 - 1
src/main/java/com/szwl/controller/WxLoginController.java

@@ -40,7 +40,7 @@ public class WxLoginController {
     @Value("${oauth.wx.appsecret}")
     private String appsecret;
 
-    @Value("${oauth.callback.http}")
+    @Value("${oauth.callback.http:http://szwltest.sunzee.com.cn:49002}")
     private String http;
 
     @ApiOperation(value = "用户默认授权")

+ 1 - 1
src/main/resources/bootstrap.yml

@@ -73,7 +73,7 @@ eureka:
     register-with-eureka: true
 #  instance:
 #    prefer-ip-address: true
-#    ip-address: 120.25.151.99
+#    ip-address: 112.96.106.247
 
 ---
 ##正式环境