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

+ 9 - 0
framework-common/src/main/java/com/mrxu/framework/common/util/HttpUtil.java

@@ -485,4 +485,13 @@ public class HttpUtil {
         return null;
     }
 
+    public static String getDomain(HttpServletRequest req) {
+        String domain = req.getScheme() + "://" + req.getServerName();
+        int port = req.getLocalPort();
+        if(port != 80 && port != 443) {
+            domain = domain+":"+port;
+        }
+        return domain;
+    }
+
 }

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

@@ -3,11 +3,14 @@ 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.ComponentToken;
+import com.mrxu.framework.common.weixin.bean.Preauthcode;
 
 public class ComponentTokenApi {
 
     private static String token = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
 
+    private static String createPreauthcode = "https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?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();
@@ -18,4 +21,15 @@ public class ComponentTokenApi {
         return rs;
     }
 
+    /**
+     * 预授权码(pre_auth_code)是第三方平台方实现授权托管的必备信息,每个预授权码有效期为 1800秒。
+     * 需要先获取令牌才能调用。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。
+     */
+    public static Preauthcode createPreauthcode(String componentAppid, String componentAccessToken) {
+        JSONObject json = new JSONObject();
+        json.put("component_appid", componentAppid);
+        Preauthcode rs = WxHttp.post(Preauthcode.class,createPreauthcode+componentAccessToken,json);
+        return rs;
+    }
+
 }

+ 14 - 0
framework-common/src/main/java/com/mrxu/framework/common/weixin/bean/Preauthcode.java

@@ -0,0 +1,14 @@
+package com.mrxu.framework.common.weixin.bean;
+
+import com.mrxu.framework.common.weixin.base.WxResult;
+import lombok.Data;
+
+@Data
+public class Preauthcode extends WxResult {
+
+    // 第三方平台 预授权码
+    private String pre_auth_code;
+
+    // 有效期,单位:秒
+    private int expires_in;
+}