Skip to content

Commit 62490c7

Browse files
authored
🎨 移动公众号关联小程序接口到 WxOpenMpService
1 parent 2eb6180 commit 62490c7

File tree

4 files changed

+94
-85
lines changed

4 files changed

+94
-85
lines changed

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaService.java

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,6 @@ public interface WxOpenMaService extends WxMaService {
236236
*/
237237
String API_AUDIT_UPLOAD_MEDIA = "https://api.weixin.qq.com/wxa/uploadmedia";
238238

239-
/**
240-
* 小程序管理-获取公众号关联的小程序
241-
*/
242-
String API_WX_AMP_LINK_GET = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget";
243-
/**
244-
* 小程序管理-关联小程序
245-
*/
246-
String API_WX_AMP_LINK_CREATE = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink";
247-
/**
248-
* 小程序管理-解除已关联的小程序
249-
*/
250-
String API_WX_AMP_LINK_UN = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink";
251239

252240
/**
253241
* 小程序管理-查询小程序版本信息
@@ -677,55 +665,6 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
677665
*/
678666
WxMaAuditMediaUploadResult uploadMedia(File file) throws WxErrorException;
679667

680-
/**
681-
* <pre>
682-
* 获取公众号关联的小程序
683-
* 请求方式:POST(HTTPS)
684-
* 请求地址:
685-
* <a href="https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=TOKEN">https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=TOKEN</a>
686-
* 文档地址:
687-
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html">https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html</a>
688-
* <pre>
689-
* @return 公众号关联的小程序
690-
*/
691-
WxAmpLinkResult getWxAmpLink() throws WxErrorException;
692-
693-
/**
694-
* <pre>
695-
* 关联小程序
696-
* 关联流程(需要公众号和小程序管理员双方确认):
697-
* 1、第三方平台调用接口发起关联
698-
* 2、公众号管理员收到模板消息,同意关联小程序。
699-
* 3、小程序管理员收到模板消息,同意关联公众号。
700-
* 4、关联成功
701-
* 等待管理员同意的中间状态可使用“获取公众号关联的小程序”接口进行查询。
702-
* 请求方式:POST(HTTPS)
703-
* 请求地址:
704-
* <a href="https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=TOKEN">https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=TOKEN</a>
705-
* 文档地址:
706-
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html">https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html</a>
707-
* <pre>
708-
* @param appid 小程序 appid
709-
* @param notifyUsers 是否发送模板消息通知公众号粉丝
710-
* @param showProfile 是否展示公众号主页中
711-
* @return 响应结果
712-
*/
713-
WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException;
714-
715-
/**
716-
* <pre>
717-
* 解除已关联的小程序
718-
* 请求方式:POST(HTTPS)
719-
* 请求地址:
720-
* <a href="https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=TOKEN">https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=TOKEN</a>
721-
* 文档地址:
722-
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html">https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html</a>
723-
* <pre>
724-
* @param appid 小程序 appid
725-
* @return 响应结果
726-
*/
727-
WxOpenResult wxAmpUnLink(String appid) throws WxErrorException;
728-
729668
/**
730669
* 查询小程序版本信息
731670
*

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMpService.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import me.chanjar.weixin.common.error.WxErrorException;
44
import me.chanjar.weixin.mp.api.WxMpService;
55
import me.chanjar.weixin.open.bean.mp.FastRegisterResult;
6+
import me.chanjar.weixin.open.bean.result.WxAmpLinkResult;
7+
import me.chanjar.weixin.open.bean.result.WxOpenResult;
68

79
/**
810
* <pre>
@@ -24,6 +26,19 @@ public interface WxOpenMpService extends WxMpService {
2426
*/
2527
String API_FAST_REGISTER = "https://api.weixin.qq.com/cgi-bin/account/fastregister";
2628

29+
/**
30+
* 小程序管理-获取公众号关联的小程序
31+
*/
32+
String API_WX_AMP_LINK_GET = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget";
33+
/**
34+
* 小程序管理-关联小程序
35+
*/
36+
String API_WX_AMP_LINK_CREATE = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink";
37+
/**
38+
* 小程序管理-解除已关联的小程序
39+
*/
40+
String API_WX_AMP_LINK_UN = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink";
41+
2742
/**
2843
* 取复用公众号快速注册小程序的授权链接
2944
* https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/fast_registration_of_mini_program.html
@@ -44,4 +59,53 @@ public interface WxOpenMpService extends WxMpService {
4459
* @throws WxErrorException the wx error exception
4560
*/
4661
FastRegisterResult fastRegister(String ticket) throws WxErrorException;
62+
63+
/**
64+
* <pre>
65+
* 获取公众号关联的小程序
66+
* 请求方式:POST(HTTPS)
67+
* 请求地址:
68+
* <a href="https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=TOKEN">https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=TOKEN</a>
69+
* 文档地址:
70+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html">https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html</a>
71+
* <pre>
72+
* @return 公众号关联的小程序
73+
*/
74+
WxAmpLinkResult getWxAmpLink() throws WxErrorException;
75+
76+
/**
77+
* <pre>
78+
* 关联小程序
79+
* 关联流程(需要公众号和小程序管理员双方确认):
80+
* 1、第三方平台调用接口发起关联
81+
* 2、公众号管理员收到模板消息,同意关联小程序。
82+
* 3、小程序管理员收到模板消息,同意关联公众号。
83+
* 4、关联成功
84+
* 等待管理员同意的中间状态可使用“获取公众号关联的小程序”接口进行查询。
85+
* 请求方式:POST(HTTPS)
86+
* 请求地址:
87+
* <a href="https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=TOKEN">https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=TOKEN</a>
88+
* 文档地址:
89+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html">https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html</a>
90+
* <pre>
91+
* @param appid 小程序 appid
92+
* @param notifyUsers 是否发送模板消息通知公众号粉丝
93+
* @param showProfile 是否展示公众号主页中
94+
* @return 响应结果
95+
*/
96+
WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException;
97+
98+
/**
99+
* <pre>
100+
* 解除已关联的小程序
101+
* 请求方式:POST(HTTPS)
102+
* 请求地址:
103+
* <a href="https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=TOKEN">https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=TOKEN</a>
104+
* 文档地址:
105+
* <a href="https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html">https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Official__Accounts/Mini_Program_Management_Permission.html</a>
106+
* <pre>
107+
* @param appid 小程序 appid
108+
* @return 响应结果
109+
*/
110+
WxOpenResult wxAmpUnLink(String appid) throws WxErrorException;
47111
}

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -407,30 +407,6 @@ public WxMaAuditMediaUploadResult uploadMedia(File file) throws WxErrorException
407407
return (WxMaAuditMediaUploadResult) this.execute(AuditMediaUploadRequestExecutor.create(getRequestHttp()), API_AUDIT_UPLOAD_MEDIA, file);
408408
}
409409

410-
@Override
411-
public WxAmpLinkResult getWxAmpLink() throws WxErrorException {
412-
String response = post(API_WX_AMP_LINK_GET, "{}");
413-
return WxMaGsonBuilder.create().fromJson(response, WxAmpLinkResult.class);
414-
}
415-
416-
@Override
417-
public WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException {
418-
JsonObject params = new JsonObject();
419-
params.addProperty("appid", appid);
420-
params.addProperty("notify_users", notifyUsers);
421-
params.addProperty("show_profile", showProfile);
422-
String response = post(API_WX_AMP_LINK_CREATE, GSON.toJson(params));
423-
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
424-
}
425-
426-
@Override
427-
public WxOpenResult wxAmpUnLink(String appid) throws WxErrorException {
428-
JsonObject params = new JsonObject();
429-
params.addProperty("appid", appid);
430-
String response = post(API_WX_AMP_LINK_UN, GSON.toJson(params));
431-
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
432-
}
433-
434410
private JsonArray toJsonArray(List<String> strList) {
435411
JsonArray jsonArray = new JsonArray();
436412
if (strList != null && !strList.isEmpty()) {

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package me.chanjar.weixin.open.api.impl;
22

3+
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
34
import com.google.common.collect.ImmutableMap;
5+
import com.google.gson.JsonObject;
46
import lombok.SneakyThrows;
57
import me.chanjar.weixin.common.error.WxErrorException;
68
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
79
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
810
import me.chanjar.weixin.open.api.WxOpenComponentService;
911
import me.chanjar.weixin.open.api.WxOpenMpService;
1012
import me.chanjar.weixin.open.bean.mp.FastRegisterResult;
13+
import me.chanjar.weixin.open.bean.result.WxAmpLinkResult;
14+
import me.chanjar.weixin.open.bean.result.WxOpenResult;
1115

1216
import java.net.URLEncoder;
1317
import java.util.Objects;
@@ -53,4 +57,30 @@ public FastRegisterResult fastRegister(String ticket) throws WxErrorException {
5357
String json = post(API_FAST_REGISTER, ImmutableMap.of("ticket", ticket));
5458
return FastRegisterResult.fromJson(json);
5559
}
60+
61+
62+
@Override
63+
public WxAmpLinkResult getWxAmpLink() throws WxErrorException {
64+
String response = post(API_WX_AMP_LINK_GET, "{}");
65+
return WxMaGsonBuilder.create().fromJson(response, WxAmpLinkResult.class);
66+
}
67+
68+
@Override
69+
public WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException {
70+
JsonObject params = new JsonObject();
71+
params.addProperty("appid", appid);
72+
params.addProperty("notify_users", notifyUsers);
73+
params.addProperty("show_profile", showProfile);
74+
String response = post(API_WX_AMP_LINK_CREATE, params.toString());
75+
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
76+
}
77+
78+
@Override
79+
public WxOpenResult wxAmpUnLink(String appid) throws WxErrorException {
80+
JsonObject params = new JsonObject();
81+
params.addProperty("appid", appid);
82+
String response = post(API_WX_AMP_LINK_UN, params.toString());
83+
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
84+
}
85+
5686
}

0 commit comments

Comments
 (0)