Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit77e3c8e

Browse files
committed
🆕#1806 开放平台增加第三方平台代公众号实现复用公众号资料快速创建小程序的接口
1 parent7c9e2e4 commit77e3c8e

File tree

5 files changed

+114
-7
lines changed

5 files changed

+114
-7
lines changed

‎weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
importcn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
44
importme.chanjar.weixin.common.error.WxErrorException;
5-
importme.chanjar.weixin.mp.api.WxMpService;
65
importme.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
76
importme.chanjar.weixin.open.bean.WxOpenCreateResult;
87
importme.chanjar.weixin.open.bean.WxOpenGetResult;
@@ -133,7 +132,7 @@ public interface WxOpenComponentService {
133132
* @param appid the appid
134133
* @return the wx mp service by appid
135134
*/
136-
WxMpServicegetWxMpServiceByAppid(Stringappid);
135+
WxOpenMpServicegetWxMpServiceByAppid(Stringappid);
137136

138137
/**
139138
* 获取指定appid的开放平台小程序服务(继承一般小程序服务能力).
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
packageme.chanjar.weixin.open.api;
2+
3+
importme.chanjar.weixin.common.error.WxErrorException;
4+
importme.chanjar.weixin.mp.api.WxMpService;
5+
importme.chanjar.weixin.open.bean.mp.FastRegisterResult;
6+
7+
/**
8+
* <pre>
9+
* 微信开放平台代公众号实现服务能力
10+
* https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1489144594_DhNoV&token=&lang=zh_CN
11+
* </pre>
12+
* <p>
13+
* Created by zpf on 2020/10/15
14+
*/
15+
publicinterfaceWxOpenMpServiceextendsWxMpService {
16+
17+
/**
18+
* 取复用公众号快速注册小程序的授权链接.
19+
*/
20+
StringURL_FAST_REGISTER_AUTH ="https://mp.weixin.qq.com/cgi-bin/fastregisterauth?appid=%s&component_appid=%s&copy_wx_verify=%s&redirect_uri=%s";
21+
22+
/**
23+
* 复用公众号快速注册小程序
24+
*/
25+
StringAPI_FAST_REGISTER ="https://api.weixin.qq.com/cgi-bin/account/fastregister";
26+
27+
/**
28+
* 取复用公众号快速注册小程序的授权链接
29+
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/fast_registration_of_mini_program.html
30+
*
31+
* @param redirectUri 用户扫码授权后,MP 扫码页面将跳转到该地址(注:1.链接需 urlencode 2.Host 需和第三方平台在微信开放平台上面填写的登 录授权的发起页域名一致)
32+
* @param copyWxVerify 是否复用公众号的资质进行微信认证,可空,默认false
33+
* @return 返回授权链接 ,注意:由于微信开放平台限制,此链接直接使用后端301重定向微信会报错,必须是在第三方平台所在域名的页面的html或js触发跳转才能成功
34+
*/
35+
StringgetFastRegisterAuthUrl(StringredirectUri,BooleancopyWxVerify);
36+
37+
/**
38+
* 复用公众号快速注册小程序
39+
* 注意:调用本接口的第三方平台必须是已经全网发布的,否则微信会报-1服务器繁忙错误,然后再报ticket无效错误,并且接口的使用次数会增加,同时还会生成一个废小程序
40+
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/fast_registration_of_mini_program.html
41+
*
42+
* @param ticket 公众号扫码授权的凭证(公众平台扫码页面回跳到第三方平台时携带)
43+
* @return 返回授权码, 然后请使用第三方平台的sdk获得授权, 参考: WxOpenService.getWxOpenComponentService().getQueryAuth( fastRegisterResult.getAuthorizationCode() );
44+
* @throws WxErrorException the wx error exception
45+
*/
46+
FastRegisterResultfastRegister(Stringticket)throwsWxErrorException;
47+
}

‎weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
publicclassWxOpenComponentServiceImplimplementsWxOpenComponentService {
3838

3939
privatestaticfinalMap<String,WxOpenMaService>WX_OPEN_MA_SERVICE_MAP =newConcurrentHashMap<>();
40-
privatestaticfinalMap<String,WxMpService>WX_OPEN_MP_SERVICE_MAP =newConcurrentHashMap<>();
40+
privatestaticfinalMap<String,WxOpenMpService>WX_OPEN_MP_SERVICE_MAP =newConcurrentHashMap<>();
4141
privatestaticfinalMap<String,WxOpenFastMaService>WX_OPEN_FAST_MA_SERVICE_MAP =newConcurrentHashMap<>();
4242

4343
privatefinalWxOpenServicewxOpenService;
4444

4545
@Override
46-
publicWxMpServicegetWxMpServiceByAppid(StringappId) {
47-
WxMpServicewxMpService =WX_OPEN_MP_SERVICE_MAP.get(appId);
46+
publicWxOpenMpServicegetWxMpServiceByAppid(StringappId) {
47+
WxOpenMpServicewxMpService =WX_OPEN_MP_SERVICE_MAP.get(appId);
4848
if (wxMpService ==null) {
4949
synchronized (WX_OPEN_MP_SERVICE_MAP) {
5050
wxMpService =WX_OPEN_MP_SERVICE_MAP.get(appId);
@@ -382,7 +382,7 @@ public String getAuthorizerAccessToken(String appId, boolean forceRefresh) throw
382382

383383
WxOpenAuthorizerAccessTokenwxOpenAuthorizerAccessToken =WxOpenAuthorizerAccessToken.fromJson(responseContent);
384384
config.updateAuthorizerAccessToken(appId,wxOpenAuthorizerAccessToken);
385-
config.updateAuthorizerRefreshToken(appId,wxOpenAuthorizerAccessToken.getAuthorizerRefreshToken());
385+
config.updateAuthorizerRefreshToken(appId,wxOpenAuthorizerAccessToken.getAuthorizerRefreshToken());
386386
returnconfig.getAuthorizerAccessToken(appId);
387387
}catch (InterruptedExceptione) {
388388
thrownewWxRuntimeException(e);

‎weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
packageme.chanjar.weixin.open.api.impl;
22

3+
importcom.google.common.collect.ImmutableMap;
4+
importlombok.SneakyThrows;
35
importme.chanjar.weixin.common.error.WxErrorException;
46
importme.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
57
importme.chanjar.weixin.mp.config.WxMpConfigStorage;
68
importme.chanjar.weixin.open.api.WxOpenComponentService;
9+
importme.chanjar.weixin.open.api.WxOpenMpService;
10+
importme.chanjar.weixin.open.bean.mp.FastRegisterResult;
11+
12+
importjava.net.URLEncoder;
13+
importjava.util.HashMap;
14+
importjava.util.Objects;
715

816
/**
917
* @author <a href="https://github.com/007gzs">007</a>
1018
*/
11-
publicclassWxOpenMpServiceImplextendsWxMpServiceImpl {
19+
publicclassWxOpenMpServiceImplextendsWxMpServiceImplimplementsWxOpenMpService{
1220
privateWxOpenComponentServicewxOpenComponentService;
1321
privateWxMpConfigStoragewxMpConfigStorage;
1422
privateStringappId;
@@ -30,4 +38,18 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
3038
returnwxOpenComponentService.getAuthorizerAccessToken(appId,forceRefresh);
3139
}
3240

41+
@SneakyThrows
42+
@Override
43+
publicStringgetFastRegisterAuthUrl(StringredirectUri,BooleancopyWxVerify) {
44+
StringcopyInfo =Objects.equals(copyWxVerify,false) ?"0" :"1";
45+
StringcomponentAppId =wxOpenComponentService.getWxOpenConfigStorage().getComponentAppId();
46+
Stringencoded =URLEncoder.encode(redirectUri,"UTF-8");
47+
returnString.format(URL_FAST_REGISTER_AUTH,appId,componentAppId,copyInfo,encoded);
48+
}
49+
50+
@Override
51+
publicFastRegisterResultfastRegister(Stringticket)throwsWxErrorException {
52+
Stringjson =post(API_FAST_REGISTER,ImmutableMap.of("ticket",ticket));
53+
returnFastRegisterResult.fromJson(json);
54+
}
3355
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packageme.chanjar.weixin.open.bean.mp;
2+
3+
importcom.google.gson.annotations.SerializedName;
4+
importlombok.Data;
5+
importme.chanjar.weixin.common.util.json.WxGsonBuilder;
6+
7+
importjava.io.Serializable;
8+
9+
/**
10+
* 复用公众号资料快速注册小程序结果
11+
*
12+
* @author someone
13+
*/
14+
@Data
15+
publicclassFastRegisterResultimplementsSerializable {
16+
privatestaticfinallongserialVersionUID =9046726183433147089L;
17+
18+
/**
19+
* 小程序AppId
20+
*/
21+
@SerializedName("appid")
22+
privateStringappId;
23+
24+
/**
25+
* 授权码,然后请使用第三方平台的sdk获得授权, 参考: WxOpenService.getWxOpenComponentService().getQueryAuth( this.getAuthorizationCode() );
26+
*/
27+
@SerializedName("authorization_code")
28+
privateStringauthorizationCode;
29+
30+
/**
31+
* 是否与公众号关联成功
32+
*/
33+
@SerializedName("is_wx_verify_succ")
34+
privateBooleanisWxVerifySucc;
35+
36+
publicstaticFastRegisterResultfromJson(Stringjson) {
37+
returnWxGsonBuilder.create().fromJson(json,FastRegisterResult.class);
38+
}
39+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp