Browse Source

微信appid适配

wangmh 7 years ago
parent
commit
6f80f53f51

+ 16 - 2
sso-server/src/main/java/com/uas/sso/entity/App.java

@@ -112,6 +112,12 @@ public class App implements Serializable {
     @Column(name = "personal_enable", nullable = false)
     private Integer personalEnable;
 
+    /**
+     * 是否支持个人账号
+     */
+    @Column(name = "wx_appid", length = 20)
+    private String wxAppid;
+
     /**
      * 应用页面样式
      */
@@ -231,14 +237,22 @@ public class App implements Serializable {
         this.defaultUse = defaultUse;
     }
 
-    public int getPersonalEnable() {
+    public Integer getPersonalEnable() {
         return personalEnable;
     }
 
-    public void setPersonalEnable(int personalEnable) {
+    public void setPersonalEnable(Integer personalEnable) {
         this.personalEnable = personalEnable;
     }
 
+    public String getWxAppid() {
+        return wxAppid;
+    }
+
+    public void setWxAppid(String wxAppid) {
+        this.wxAppid = wxAppid;
+    }
+
     @JsonIgnore
     @JSONField(serialize = false)
     public PageStyle getPageStyle() {

+ 19 - 3
sso-server/src/main/java/com/uas/sso/weixin/controller/WeChatController.java

@@ -1,7 +1,9 @@
 package com.uas.sso.weixin.controller;
 
 import com.uas.sso.controller.BaseController;
+import com.uas.sso.entity.App;
 import com.uas.sso.entity.User;
+import com.uas.sso.service.AppService;
 import com.uas.sso.weixin.entity.OAuthInfo;
 import com.uas.sso.entity.Token;
 import com.uas.sso.service.UserService;
@@ -10,6 +12,7 @@ import com.uas.sso.weixin.service.WeChatService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.UnsupportedEncodingException;
@@ -30,7 +33,10 @@ public class WeChatController extends BaseController {
     @Autowired
     private UserService userService;
 
-    private static final String WX_APPID = "wxa14aec4edce8a2d2";
+    @Autowired
+    private AppService appService;
+
+    private static final String DEFAULT_WX_APPID = "wxa14aec4edce8a2d2";
 
     private static final String WX_APPSECRET = "9749d2df03eb161f4d4075df69c2e2c9";
 
@@ -46,14 +52,24 @@ public class WeChatController extends BaseController {
             throw new RuntimeException("程序编码异常");
         }
         String qrUrl = "https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";
-        qrUrl = qrUrl.replace("APPID", WX_APPID).replace("REDIRECT_URI", url).replace("SCOPE", WX_LOGIN_SCOPE).replace("STATE", "");
+        App app = appService.findOne(appId);
+        String wx_appid = DEFAULT_WX_APPID;
+        if (app != null && !StringUtils.isEmpty(app.getWxAppid())) {
+            wx_appid = app.getWxAppid();
+        }
+        qrUrl = qrUrl.replace("APPID", wx_appid).replace("REDIRECT_URI", url).replace("SCOPE", WX_LOGIN_SCOPE).replace("STATE", "");
         return success(qrUrl);
     }
 
     @RequestMapping("/getQrParams")
     public ModelMap getQrParams(String appId) {
         ModelMap params = new ModelMap();
-        params.addAttribute("appid", WX_APPID).addAttribute("state", "");
+        App app = appService.findOne(appId);
+        String wx_appid = DEFAULT_WX_APPID;
+        if (app != null && !StringUtils.isEmpty(app.getWxAppid())) {
+            wx_appid = app.getWxAppid();
+        }
+        params.addAttribute("appid", wx_appid).addAttribute("state", "");
         return params;
     }