xujunwei 3 лет назад
Родитель
Сommit
8f10068706

+ 16 - 0
framework-common/src/main/java/com/mrxu/framework/common/weixin/api/ComponentTokenApi.java

@@ -2,6 +2,7 @@ package com.mrxu.framework.common.weixin.api;
 
 import com.alibaba.fastjson.JSONObject;
 import com.mrxu.framework.common.weixin.base.WxHttp;
+import com.mrxu.framework.common.weixin.bean.AuthorizationInfo;
 import com.mrxu.framework.common.weixin.bean.ComponentToken;
 import com.mrxu.framework.common.weixin.bean.Preauthcode;
 
@@ -11,6 +12,8 @@ public class ComponentTokenApi {
 
     private static String createPreauthcode = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=";
 
+    private static String query_auth = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=";
+
     // https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/component_access_token.html
     public static ComponentToken getToken(String componentAppid, String componentAppsecret,String componentVerifyTicket) {
         JSONObject json = new JSONObject();
@@ -32,4 +35,17 @@ public class ComponentTokenApi {
         return rs;
     }
 
+    /**
+     * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/authorization_info.html
+     * 使用授权码获取授权信息
+     */
+    public static AuthorizationInfo queryAuth(String componentAppid, String componentAccessToken, String authorizationCode) {
+        JSONObject json = new JSONObject();
+        json.put("component_appid", componentAppid);
+        json.put("authorization_code", authorizationCode);
+        AuthorizationInfo rs = WxHttp.post(AuthorizationInfo.class,createPreauthcode+componentAccessToken,json);
+        return rs;
+    }
+
+
 }

+ 24 - 0
framework-common/src/main/java/com/mrxu/framework/common/weixin/bean/AuthorizationInfo.java

@@ -0,0 +1,24 @@
+package com.mrxu.framework.common.weixin.bean;
+
+import com.mrxu.framework.common.weixin.base.WxResult;
+import lombok.Data;
+
+@Data
+public class AuthorizationInfo extends WxResult {
+
+    // 授权方 appid
+    private String authorizer_appid;
+
+    // 接口调用令牌(在授权的公众号/小程序具备 API 权限时,才有此返回值)
+    private String authorizer_access_token;
+
+    // authorizer_access_token 的有效期(在授权的公众号/小程序具备 API 权限时,才有此返回值),单位:秒
+    private int expires_in;
+
+    // 刷新令牌(在授权的公众号具备 API 权限时,才有此返回值),刷新令牌主要用于第三方平台获取和刷新已授权用户的 authorizer_access_token。一旦丢失,只能让用户重新授权,才能再次拿到新的刷新令牌。用户重新授权后,之前的刷新令牌会失效
+    private String authorizer_refresh_token;
+
+    // 授权给开发者的权限集列表
+    private String func_info;
+
+}