ソースを参照

修改appid配置问题

PLF 5 年 前
コミット
a9182465c8

+ 5 - 7
src/main/java/com/caimei/controller/order/OrderController.java

@@ -12,7 +12,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -36,10 +36,8 @@ public class OrderController {
     private OrderService orderService;
     private OrderService orderService;
     @Autowired
     @Autowired
     private LoginService loginService;
     private LoginService loginService;
-    @Value("${miniprogram.AppId}")
-    private String AppId;
-    @Value("${miniprogram.AppSecret}")
-    private String AppSecret;
+    @Autowired
+    private Environment env;
 
 
     /**
     /**
      * 确认订单信息
      * 确认订单信息
@@ -86,8 +84,8 @@ public class OrderController {
         map.put("referer", referer);
         map.put("referer", referer);
         String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
         String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
         Map<String, String> requestUrlParam = new HashMap<String, String>();
         Map<String, String> requestUrlParam = new HashMap<String, String>();
-        requestUrlParam.put("appid", AppId);//小程序appId
-        requestUrlParam.put("secret", AppSecret);//小程序appsecret
+        requestUrlParam.put("appid", env.getProperty("AppId" + organizeID));//小程序appId
+        requestUrlParam.put("secret", env.getProperty("AppSecret") + organizeID);//小程序appsecret
         requestUrlParam.put("js_code", code);//小程序端返回的code
         requestUrlParam.put("js_code", code);//小程序端返回的code
         requestUrlParam.put("grant_type", "authorization_code");//默认参数
         requestUrlParam.put("grant_type", "authorization_code");//默认参数
         //发送post请求读取调用微信接口获取openid用户唯一标识
         //发送post请求读取调用微信接口获取openid用户唯一标识

+ 8 - 9
src/main/java/com/caimei/controller/user/LoginController.java

@@ -11,6 +11,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -35,12 +36,10 @@ public class LoginController {
     private LoginService loginService;
     private LoginService loginService;
     @Value("${miniprogram.ValidTime}")
     @Value("${miniprogram.ValidTime}")
     private Integer ValidTime;
     private Integer ValidTime;
-    @Value("${miniprogram.AppId}")
-    private String AppId;
-    @Value("${miniprogram.AppSecret}")
-    private String AppSecret;
+    @Autowired
+    private Environment env;
 
 
-    public WxJsonModel login(String code, HttpServletRequest request) {
+    public WxJsonModel login(String code, HttpServletRequest request, Integer organizeID) {
         logger.info("Start get SessionKey");
         logger.info("Start get SessionKey");
         WxJsonModel res = WxJsonModel.newInstance();
         WxJsonModel res = WxJsonModel.newInstance();
         Map<String, Object> map = new HashMap<>();
         Map<String, Object> map = new HashMap<>();
@@ -49,8 +48,8 @@ public class LoginController {
         map.put("referer", referer);
         map.put("referer", referer);
         String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
         String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
         Map<String, String> requestUrlParam = new HashMap<String, String>();
         Map<String, String> requestUrlParam = new HashMap<String, String>();
-        requestUrlParam.put("appid", AppId);//小程序appId
-        requestUrlParam.put("secret", AppSecret);//小程序appsecret
+        requestUrlParam.put("appid", env.getProperty("AppId" + organizeID));//小程序appId
+        requestUrlParam.put("secret", env.getProperty("AppSecret") + organizeID);//小程序appsecret
         requestUrlParam.put("js_code", code);//小程序端返回的code
         requestUrlParam.put("js_code", code);//小程序端返回的code
         requestUrlParam.put("grant_type", "authorization_code");//默认参数
         requestUrlParam.put("grant_type", "authorization_code");//默认参数
         //发送post请求读取调用微信接口获取openid用户唯一标识
         //发送post请求读取调用微信接口获取openid用户唯一标识
@@ -92,7 +91,7 @@ public class LoginController {
                                @RequestParam(value = "userOrganizeID") Integer userOrganizeID,
                                @RequestParam(value = "userOrganizeID") Integer userOrganizeID,
                                HttpServletRequest request) {
                                HttpServletRequest request) {
         WxJsonModel res = WxJsonModel.newInstance();
         WxJsonModel res = WxJsonModel.newInstance();
-        WxJsonModel model = login(code, request);
+        WxJsonModel model = login(code, request, userOrganizeID);
         if (model.getCode().equals("-1")) {
         if (model.getCode().equals("-1")) {
             return model;
             return model;
         }
         }
@@ -163,7 +162,7 @@ public class LoginController {
     @ResponseBody
     @ResponseBody
     public WxJsonModel register(@RequestParam(value = "code", required = true) String code,
     public WxJsonModel register(@RequestParam(value = "code", required = true) String code,
                                 CmOperationUser operationUser, HttpServletRequest request) {
                                 CmOperationUser operationUser, HttpServletRequest request) {
-        WxJsonModel model = login(code, request);
+        WxJsonModel model = login(code, request, operationUser.getUserOrganizeID());
         if (model.getCode().equals("-1")) {
         if (model.getCode().equals("-1")) {
             return model;
             return model;
         }
         }

+ 7 - 2
src/main/resources/dev/application-dev.yml

@@ -41,8 +41,13 @@ logging:
   level: debug
   level: debug
 
 
 miniprogram:
 miniprogram:
-  AppId: wx5a5cda32926f55ac
-  AppSecret: 1c371e72aba710949dd74bb184a3a774
   #邀请码有效时长  /天
   #邀请码有效时长  /天
   ValidTime: 7
   ValidTime: 7
   domain: https://www.caimei365.com
   domain: https://www.caimei365.com
+  #组织appid1....2....3,星范组织
+  AppId1: wx5a5cda32926f55ac
+  AppSecret1: 1c371e72aba710949dd74bb184a3a774
+  #采美组织
+  AppId2: wxf3cd4ae0cdd11c36
+  AppSecret2: 9bdb37d28c5e74ad3694c09c205e9bd2
+

+ 7 - 3
src/main/resources/prod/application-prod.yml

@@ -43,8 +43,12 @@ logging:
   level: debug
   level: debug
 
 
 miniprogram:
 miniprogram:
-  AppId: wx5a5cda32926f55ac
-  AppSecret: 1c371e72aba710949dd74bb184a3a774
   #邀请码有效时长  /天
   #邀请码有效时长  /天
   ValidTime: 7
   ValidTime: 7
-  domain: https://www.caimei365.com
+  domain: https://www.caimei365.com
+  #组织appid1....2....3,星范组织
+  AppId: wx5a5cda32926f55ac
+  AppSecret: 1c371e72aba710949dd74bb184a3a774
+  #采美组织
+  AppId2: wxf3cd4ae0cdd11c36
+  AppSecret2: 9bdb37d28c5e74ad3694c09c205e9bd2

+ 1 - 0
src/main/resources/public/7qBjQ4SKBd.txt

@@ -0,0 +1 @@
+9bb0efd407ab28213a0e187a96644b17

+ 7 - 3
src/main/resources/test/application-test.yml

@@ -42,8 +42,12 @@ logging:
   level: debug
   level: debug
 
 
 miniprogram:
 miniprogram:
-  AppId: wx5a5cda32926f55ac
-  AppSecret: 1c371e72aba710949dd74bb184a3a774
   #邀请码有效时长  /天
   #邀请码有效时长  /天
   ValidTime: 7
   ValidTime: 7
-  domain: https://www-b.caimei365.com
+  domain: https://www-b.caimei365.com
+  #组织appid1....2....3,星范组织
+  AppId: wx5a5cda32926f55ac
+  AppSecret: 1c371e72aba710949dd74bb184a3a774
+  #采美组织
+  AppId2: wxf3cd4ae0cdd11c36
+  AppSecret2: 9bdb37d28c5e74ad3694c09c205e9bd2