|
|
@@ -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;
|
|
|
}
|
|
|
|