Skip to content

Commit fcb0bc8

Browse files
authored
🆕 #2597 【开放平台】增加公众号业务相关的小程序管理接口
1 parent 946f693 commit fcb0bc8

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

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

+57
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,19 @@ public interface WxOpenMaService extends WxMaService {
238238
*/
239239
String API_AUDIT_UPLOAD_MEDIA = "https://api.weixin.qq.com/wxa/uploadmedia";
240240

241+
/**
242+
* 小程序管理-获取公众号关联的小程序
243+
*/
244+
String API_WX_AMP_LINK_GET = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget";
245+
/**
246+
* 小程序管理-关联小程序
247+
*/
248+
String API_WX_AMP_LINK_CREATE = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink";
249+
/**
250+
* 小程序管理-解除已关联的小程序
251+
*/
252+
String API_WX_AMP_LINK_UN = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink";
253+
241254
/**
242255
* 获得小程序的域名配置信息
243256
*
@@ -645,4 +658,48 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
645658
* @return
646659
*/
647660
WxMaAuditMediaUploadResult uploadMedia(File file) throws WxErrorException;
661+
662+
/**
663+
* <pre>
664+
* 获取公众号关联的小程序
665+
* 请求方式:POST(HTTPS)
666+
* 请求地址:<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>
667+
* 文档地址:<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>
668+
* <pre>
669+
* @return 公众号关联的小程序
670+
*/
671+
WxAmpLinkResult getWxAmpLink() throws WxErrorException;
672+
673+
/**
674+
* <pre>
675+
* 关联小程序
676+
* 关联流程(需要公众号和小程序管理员双方确认):
677+
* 1、第三方平台调用接口发起关联
678+
* 2、公众号管理员收到模板消息,同意关联小程序。
679+
* 3、小程序管理员收到模板消息,同意关联公众号。
680+
* 4、关联成功
681+
* 等待管理员同意的中间状态可使用“获取公众号关联的小程序”接口进行查询。
682+
* 请求方式:POST(HTTPS)
683+
* 请求地址:<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>
684+
* 文档地址:<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>
685+
* <pre>
686+
* @param appid 小程序 appid
687+
* @param notifyUsers 是否发送模板消息通知公众号粉丝
688+
* @param showProfile 是否展示公众号主页中
689+
* @return 响应结果
690+
*/
691+
WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException;
692+
693+
/**
694+
* <pre>
695+
* 解除已关联的小程序
696+
* 请求方式:POST(HTTPS)
697+
* 请求地址:<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>
698+
* 文档地址:<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>
699+
* <pre>
700+
* @param appid 小程序 appid
701+
* @return 响应结果
702+
*/
703+
WxOpenResult wxAmpUnLink(String appid) throws WxErrorException;
704+
648705
}

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

+24
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,30 @@ public WxMaAuditMediaUploadResult uploadMedia(File file) throws WxErrorException
406406
return (WxMaAuditMediaUploadResult) this.execute(AuditMediaUploadRequestExecutor.create(getRequestHttp()), API_AUDIT_UPLOAD_MEDIA, file);
407407
}
408408

409+
@Override
410+
public WxAmpLinkResult getWxAmpLink() throws WxErrorException {
411+
String response = post(API_WX_AMP_LINK_GET, "{}");
412+
return WxMaGsonBuilder.create().fromJson(response, WxAmpLinkResult.class);
413+
}
414+
415+
@Override
416+
public WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException {
417+
JsonObject params = new JsonObject();
418+
params.addProperty("appid", appid);
419+
params.addProperty("notify_users", notifyUsers);
420+
params.addProperty("show_profile", showProfile);
421+
String response = post(API_WX_AMP_LINK_CREATE, GSON.toJson(params));
422+
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
423+
}
424+
425+
@Override
426+
public WxOpenResult wxAmpUnLink(String appid) throws WxErrorException {
427+
JsonObject params = new JsonObject();
428+
params.addProperty("appid", appid);
429+
String response = post(API_WX_AMP_LINK_UN, GSON.toJson(params));
430+
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
431+
}
432+
409433
private JsonArray toJsonArray(List<String> strList) {
410434
JsonArray jsonArray = new JsonArray();
411435
if (strList != null && !strList.isEmpty()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package me.chanjar.weixin.open.bean.result;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
import java.util.List;
10+
11+
/**
12+
* 公众号关联的小程序
13+
*
14+
* @author zhongjun
15+
* @date 2022/4/29
16+
**/
17+
18+
@Data
19+
@EqualsAndHashCode(callSuper = true)
20+
public class WxAmpLinkResult extends WxOpenResult{
21+
22+
/**
23+
* 关联的小程序列表,具有 items 字段,内带有参数
24+
*/
25+
@SerializedName("wxopens")
26+
private WxOpen wxOpen;
27+
28+
@Getter
29+
@Setter
30+
public static class WxOpen{
31+
@SerializedName("items")
32+
private List<Item> items;
33+
}
34+
35+
@Getter
36+
@Setter
37+
public static class Item{
38+
39+
/**
40+
* 关联状态
41+
* 1:已关联;
42+
* 2:等待小程序管理员确认中;
43+
* 3:小程序管理员拒绝关联
44+
* 12:等待公众号管理员确认中;
45+
*/
46+
private Integer status;
47+
48+
/**
49+
* 小程序appid
50+
*/
51+
private String appid;
52+
53+
/**
54+
* 小程序 gh_id
55+
*/
56+
private String username;
57+
58+
/**
59+
* 小程序名称
60+
*/
61+
private String nickname;
62+
63+
/**
64+
* 是否在公众号管理页展示中
65+
*/
66+
private Integer selected;
67+
68+
/**
69+
* 是否展示在附近的小程序中
70+
*/
71+
@SerializedName("nearby_display_status")
72+
private Integer nearbyDisplayStatus;
73+
74+
/**
75+
* 是否已经发布
76+
*/
77+
private Integer released;
78+
79+
/**
80+
* 头像 url
81+
*/
82+
@SerializedName("headimg_url")
83+
private String headImgUrl;
84+
85+
/**
86+
* 小程序邮箱
87+
*/
88+
private String email;
89+
90+
/**
91+
* 微信认证及支付信息
92+
*/
93+
@SerializedName("func_info")
94+
private List<FuncInfo> funcInfo;
95+
96+
}
97+
98+
@Getter
99+
@Setter
100+
public static class FuncInfo{
101+
/**
102+
* 微信认证及支付信息,0 表示未开通,1 表示开通
103+
*/
104+
private Integer status;
105+
106+
private String name;
107+
108+
private Long id;
109+
110+
}
111+
}

0 commit comments

Comments
 (0)