xiongchao 3 years ago
parent
commit
9639acfa0e

+ 24 - 1
platform-rest/src/main/java/com/platform/rest/controller/wechat/WechatController.java

@@ -132,6 +132,7 @@ public class WechatController {
         // 获取用户的openid和access_token
         JsonOauthAccessTokenResponse wechatResponse = WeChatConnectService.getOauthAccessToken(code);
         String openId = wechatResponse.getOpenid();
+        log.info("微信的openId: " + openId);
         SysUser searchUser = new SysUser();
         searchUser.setWxOpenId(openId);
         SysUser sysUser = sysUserService.getModelByModel(searchUser);
@@ -141,7 +142,29 @@ public class WechatController {
             searchUser.setUserId(userInfo.getUserId());
             sysUserService.modModelByPrimaryKey(searchUser);
         }
-        response.sendRedirect("https://rl.m.litian2017.com/#/pages/setting/wechat-oauth");
+        response.sendRedirect("https://rl.m.litian2017.com/#/pages/setting/wechat-oauth?openId=" + openId);
+    }
+
+    /**
+     * 保存openid和用戶信息,带着code
+     * 后台再跟进这个code去获取用户openid
+     *
+     * @param request
+     * @param openId
+     * @return
+     */
+    @RequestMapping(value = "bind", method = RequestMethod.PUT)
+    public R bind(HttpServletRequest request, HttpServletResponse response, @RequestParam String openId) throws IOException {
+        log.info("微信的openId: " + openId);
+        SysUser searchUser = new SysUser();
+        searchUser.setWxOpenId(openId);
+        SysUser sysUser = sysUserService.getModelByModel(searchUser);
+        if (sysUser == null) {
+            UserInfo userInfo = SecurityUtils.getUser().getUserInfo();
+            searchUser.setUserId(userInfo.getUserId());
+            sysUserService.modModelByPrimaryKey(searchUser);
+        }
+        return R.success("微信授权成功");
     }
 
 //    /**

+ 2 - 1
platform-rest/src/main/resources/application-dev.yml

@@ -79,7 +79,8 @@ ignore:
     - /static/**
     - /service/**
     - /ignores/**
-    - /wechat/**
+    - /wechat/token
+    - /wechat/redirect
 upload:
   root-dir: D://data//xian
 

+ 2 - 1
platform-rest/src/main/resources/application-prod.yml

@@ -64,7 +64,8 @@ ignore:
     - /static/**
     - /service/**
     - /ignores/**
-    - /wechat/**
+    - /wechat/token
+    - /wechat/redirect
 upload:
   root-dir: /home/data/sb-base/FileData
 

+ 2 - 1
platform-rest/src/main/resources/application-test.yml

@@ -59,7 +59,8 @@ ignore:
     - /static/**
     - /service/**
     - /ignores/**
-    - /wechat/**
+    - /wechat/token
+    - /wechat/redirect
 upload:
   root-dir: /home/data/XiAnConstructionAsset/FileData