浏览代码

4.0.27 添加通用secret区别于通讯录secret - 中建八局

zero 6 月之前
父节点
当前提交
bd306fdafc

+ 1 - 1
platomix-gmetry-system-api/pom.xml

@@ -8,7 +8,7 @@
         <version>1.0.0</version>
     </parent>
     <artifactId>platomix-gmetry-system-api</artifactId>
-    <version>4.0.26</version>
+    <version>4.0.27</version>
     <dependencies>
         <dependency>
             <groupId>com.platomix</groupId>

+ 21 - 1
platomix-gmetry-system-api/src/main/java/org/springblade/wecom/controller/WeComController.java

@@ -75,6 +75,9 @@ public class WeComController {
 	@Value("${weCom.corpSecret}")
 	private String corpSecret;
 
+	@Value("${weCom.loginCorpSecret}")
+	private String loginCorpSecret;
+
 	@Value("${weCom.redirectUrl}")
 	private String redirectUrl;
 
@@ -83,7 +86,7 @@ public class WeComController {
 	@GetMapping("/codeToToken")
 	@ApiOperation(value = "PC企业微信登录code换取token")
 	public Kv codeToToken(String code, String state) throws Exception {
-		String accessToken = getAccessToken();
+		String accessToken = getLoginAccessToken();
 		System.out.println("企业微信 codeToToken = " + code + "===============" + state);
 		UserInfo userInfo = new UserInfo();
 		Map<String, Object> formMap = new HashMap<>();
@@ -125,6 +128,23 @@ public class WeComController {
 		throw new RuntimeException("企业微信|获取accessToken失败|res=" + res);
 	}
 
+	/**
+	 * 企业微信登录获取AccessToken(八局需单独获取)
+	 * @return
+	 * @throws Exception
+	 */
+	private String getLoginAccessToken() throws Exception {
+		Map<String, Object> formMap = new HashMap<>();
+		formMap.put("corpid", corpId);
+		formMap.put("corpsecret", loginCorpSecret);
+		String res = HttpUtil.createGet(domainName+GET_ACCESS_TOKEN_URL).form(formMap).execute().body();
+		JSONObject jsonObject = JSONObject.parseObject(res);
+		if (Objects.nonNull(jsonObject.get("errcode")) && jsonObject.getInteger("errcode") == 0) {
+			return jsonObject.getString("access_token");
+		}
+		throw new RuntimeException("企业微信|获取accessToken失败|res=" + res);
+	}
+
 
 	/**
 	 * 获取部门信息

+ 1 - 0
platomix-gmetry-system-api/src/main/resources/application-demo.yml

@@ -87,5 +87,6 @@ weCom:
    userinfoUrl: https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo
    corpId: ww70971991bf0840bc
    corpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
+   loginCorpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
    # 企业微信授权调用地址用来获取code
    redirectUrl: http://windata.platomix.net/api/wecom/getCode

+ 2 - 0
platomix-gmetry-system-api/src/main/resources/application-dev.yml

@@ -83,6 +83,7 @@ datasource:
    #userinfoUrl: https://qw.cscec8b.com.cn/cgi-bin/user/getuserinfo
    #corpId: ww7c2d63f53983256d
    #corpSecret: taOSTYmRzVmg0zbQNaNF9QuIbnZf-o-9BfHYVcoa6yk
+   #loginCorpSecret: KlNMCxAzWXTdgYz4F1EeLLw3jySm3f9319PujRV9Fxg
    # 企业微信授权调用地址用来获取code
    #redirectUrl: http://hr.cscec8st.com.cn:50021/api/wecom/getCode
 weCom:
@@ -90,5 +91,6 @@ weCom:
    userinfoUrl: https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo
    corpId: ww70971991bf0840bc
    corpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
+   loginCorpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
    # 企业微信授权调用地址用来获取code
    redirectUrl: http://windata.platomix.net/api/wecom/getCode

+ 1 - 0
platomix-gmetry-system-api/src/main/resources/application-docker.yml

@@ -89,5 +89,6 @@ weCom:
   userinfoUrl: https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo
   corpId: ww70971991bf0840bc
   corpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
+  loginCorpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
   # 企业微信授权调用地址用来获取code
   redirectUrl: http://windata.platomix.net/api/wecom/getCode

+ 1 - 0
platomix-gmetry-system-api/src/main/resources/application-test.yml

@@ -91,5 +91,6 @@ weCom:
   userinfoUrl: https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo
   corpId: ww70971991bf0840bc
   corpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
+  loginCorpSecret: a6RW9VjXWq-sQX1WyDfBlphNGW6B8SQ0Ksvx58nXZFs
   # 企业微信授权调用地址用来获取code
   redirectUrl: http://windata.platomix.net/api/wecom/getCode