From 001400978663e14d5210045e6871281eb8e7defe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E9=B9=8F=E9=A3=9E?= <178668028@qq.com> Date: Thu, 15 Oct 2020 20:26:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3:=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=B9=B3=E5=8F=B0=E4=BB=A3=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E5=AE=9E=E7=8E=B0=E5=A4=8D=E7=94=A8=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E8=B5=84=E6=96=99=E5=BF=AB=E9=80=9F=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/api/WxOpenComponentService.java | 3 +- .../weixin/open/api/WxOpenMpService.java | 47 +++++++++++++++++++ .../api/impl/WxOpenComponentServiceImpl.java | 8 ++-- .../open/api/impl/WxOpenMpServiceImpl.java | 28 +++++++++-- .../open/bean/mp/FastRegisterResult.java | 37 +++++++++++++++ 5 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMpService.java create mode 100644 weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/mp/FastRegisterResult.java 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 68dfb3d60b..14073cc8f3 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 @@ -2,7 +2,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import me.chanjar.weixin.common.error.WxErrorException; -import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; import me.chanjar.weixin.open.bean.WxOpenCreateResult; import me.chanjar.weixin.open.bean.WxOpenGetResult; @@ -133,7 +132,7 @@ public interface WxOpenComponentService { * @param appid the appid * @return the wx mp service by appid */ - WxMpService getWxMpServiceByAppid(String appid); + WxOpenMpService getWxMpServiceByAppid(String appid); /** * 获取指定appid的开放平台小程序服务(继承一般小程序服务能力). diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMpService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMpService.java new file mode 100644 index 0000000000..1b50f2bcae --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMpService.java @@ -0,0 +1,47 @@ +package me.chanjar.weixin.open.api; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.open.bean.mp.FastRegisterResult; + +/** + *
+ * 微信开放平台代公众号实现服务能力 + * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489144594_DhNoV&token=&lang=zh_CN + *+ *
+ * Created by zpf on 2020/10/15
+ */
+public interface WxOpenMpService extends WxMpService {
+
+ /**
+ * 取复用公众号快速注册小程序的授权链接.
+ */
+ String URL_FAST_REGISTER_AUTH = "https://mp.weixin.qq.com/cgi-bin/fastregisterauth?appid=%s&component_appid=%s©_wx_verify=%s&redirect_uri=%s";
+
+ /**
+ * 复用公众号快速注册小程序
+ */
+ String API_FAST_REGISTER = "https://api.weixin.qq.com/cgi-bin/account/fastregister";
+
+
+ /**
+ * 取复用公众号快速注册小程序的授权链接
+ * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/fast_registration_of_mini_program.html
+ *
+ * @param redirectUri 用户扫码授权后,MP 扫码页面将跳转到该地址(注:1.链接需 urlencode 2.Host 需和第三方平台在微信开放平台上面填写的登 录授权的发起页域名一致)
+ * @param copyWxVerify 是否复用公众号的资质进行微信认证,可空,默认false
+ * @return 返回授权链接,注意:由于微信开放平台限制,此链接直接使用后端301重定向微信会报错,必须是在第三方平台所在域名的页面的html或js触发跳转才能成功
+ */
+ String getFastRegisterAuthUrl(String redirectUri, Boolean copyWxVerify);
+
+ /**
+ * 复用公众号快速注册小程序
+ * 注意:调用本接口的第三方平台必须是已经全网发布的,否则微信会报-1服务器繁忙错误,然后再报ticket无效错误,并且接口的使用次数会增加,同时还会生成一个废小程序
+ * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/fast_registration_of_mini_program.html
+ *
+ * @param ticket 公众号扫码授权的凭证(公众平台扫码页面回跳到第三方平台时携带)
+ * @return 返回授权码, 然后请使用第三方平台的sdk获得授权, 参考: WxOpenService.getWxOpenComponentService().getQueryAuth( fastRegisterResult.getAuthorizationCode() );
+ */
+ FastRegisterResult fastRegister(String ticket) 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 d460152dfa..66ec93e3d9 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
@@ -36,14 +36,14 @@
public class WxOpenComponentServiceImpl implements WxOpenComponentService {
private static final Map