From 9cdff1d010b1d20b6dc2d2b848ce41600466df2b Mon Sep 17 00:00:00 2001 From: TonyLuo Date: Mon, 20 Aug 2018 12:03:44 +0800 Subject: [PATCH] =?UTF-8?q?#718=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3getPreAuthUrl=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E5=8F=82=E6=95=B0auth=5Fty?= =?UTF-8?q?pe=20=E5=92=8C=20biz=5Fappid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add new api: getPreAuthUrl https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1453779503&token=67aa8893d9de824541cb2bfc4619098b5ba5f074&lang=zh_CN * add new api: getPreAuthUrl https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1453779503&token=67aa8893d9de824541cb2bfc4619098b5ba5f074&lang=zh_CN --- .../weixin/open/api/WxOpenComponentService.java | 6 ++++++ .../open/api/impl/WxOpenComponentServiceImpl.java | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java index c2e19943c..42273951f 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java @@ -53,6 +53,12 @@ public interface WxOpenComponentService { * 获取用户授权页URL(来路URL和成功跳转URL 的域名都需要为三方平台设置的 登录授权的发起页域名) */ String getPreAuthUrl(String redirectURI) throws WxErrorException; + /** + * authType 要授权的帐号类型:1则商户点击链接后,手机端仅展示公众号、2表示仅展示小程序,3表示公众号和小程序都展示。如果为未指定,则默认小程序和公众号都展示。第三方平台开发者可以使用本字段来控制授权的帐号类型。 + * bizAppid 指定授权唯一的小程序或公众号 + * 注:auth_type、biz_appid两个字段互斥。 + */ + String getPreAuthUrl(String redirectURI,String authType, String bizAppid) throws WxErrorException; String route(WxOpenXmlMessage wxMessage) throws WxErrorException; diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java index 05f3df112..a069ddd97 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java @@ -177,14 +177,26 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { @Override public String getPreAuthUrl(String redirectURI) throws WxErrorException { + return getPreAuthUrl(redirectURI,null, null); + } + @Override + public String getPreAuthUrl(String redirectURI,String authType, String bizAppid) throws WxErrorException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); String responseContent = post(API_CREATE_PREAUTHCODE_URL, jsonObject.toString()); jsonObject = WxGsonBuilder.create().fromJson(responseContent, JsonObject.class); - return String.format(COMPONENT_LOGIN_PAGE_URL, getWxOpenConfigStorage().getComponentAppId(), jsonObject.get("pre_auth_code").getAsString(), URIUtil.encodeURIComponent(redirectURI)); + String preAuthUrl = String.format(COMPONENT_LOGIN_PAGE_URL, getWxOpenConfigStorage().getComponentAppId(), jsonObject.get("pre_auth_code").getAsString(), URIUtil.encodeURIComponent(redirectURI)); + if(StringUtils.isNotEmpty(authType)){ + preAuthUrl = preAuthUrl + "&auth_type=" + authType; + } + if(StringUtils.isNotEmpty(bizAppid)){ + preAuthUrl = preAuthUrl + "&biz_appid=" + bizAppid; + } + return preAuthUrl; } + @Override public String route(final WxOpenXmlMessage wxMessage) throws WxErrorException { if (wxMessage == null) {