🆕 #2597 【开放平台】增加公众号业务相关的小程序管理接口

This commit is contained in:
zhongjun 2022-05-05 11:45:08 +08:00 committed by GitHub
parent 946f693bd0
commit fcb0bc8c35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 192 additions and 0 deletions

View File

@ -238,6 +238,19 @@ public interface WxOpenMaService extends WxMaService {
*/
String API_AUDIT_UPLOAD_MEDIA = "https://api.weixin.qq.com/wxa/uploadmedia";
/**
* 小程序管理-获取公众号关联的小程序
*/
String API_WX_AMP_LINK_GET = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget";
/**
* 小程序管理-关联小程序
*/
String API_WX_AMP_LINK_CREATE = "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink";
/**
* 小程序管理-解除已关联的小程序
*/
String API_WX_AMP_LINK_UN = "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink";
/**
* 获得小程序的域名配置信息
*
@ -645,4 +658,48 @@ public interface WxOpenMaService extends WxMaService {
* @return
*/
WxMaAuditMediaUploadResult uploadMedia(File file) throws WxErrorException;
/**
* <pre>
* 获取公众号关联的小程序
* 请求方式POST(HTTPS)
* 请求地址<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>
* 文档地址<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>
* <pre>
* @return 公众号关联的小程序
*/
WxAmpLinkResult getWxAmpLink() throws WxErrorException;
/**
* <pre>
* 关联小程序
* 关联流程需要公众号和小程序管理员双方确认
* 1第三方平台调用接口发起关联
* 2公众号管理员收到模板消息同意关联小程序
* 3小程序管理员收到模板消息同意关联公众号
* 4关联成功
* 等待管理员同意的中间状态可使用获取公众号关联的小程序接口进行查询
* 请求方式POST(HTTPS)
* 请求地址<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>
* 文档地址<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>
* <pre>
* @param appid 小程序 appid
* @param notifyUsers 是否发送模板消息通知公众号粉丝
* @param showProfile 是否展示公众号主页中
* @return 响应结果
*/
WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException;
/**
* <pre>
* 解除已关联的小程序
* 请求方式POST(HTTPS)
* 请求地址<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>
* 文档地址<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>
* <pre>
* @param appid 小程序 appid
* @return 响应结果
*/
WxOpenResult wxAmpUnLink(String appid) throws WxErrorException;
}

View File

@ -406,6 +406,30 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return (WxMaAuditMediaUploadResult) this.execute(AuditMediaUploadRequestExecutor.create(getRequestHttp()), API_AUDIT_UPLOAD_MEDIA, file);
}
@Override
public WxAmpLinkResult getWxAmpLink() throws WxErrorException {
String response = post(API_WX_AMP_LINK_GET, "{}");
return WxMaGsonBuilder.create().fromJson(response, WxAmpLinkResult.class);
}
@Override
public WxOpenResult wxAmpLink(String appid, String notifyUsers, String showProfile) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("appid", appid);
params.addProperty("notify_users", notifyUsers);
params.addProperty("show_profile", showProfile);
String response = post(API_WX_AMP_LINK_CREATE, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult wxAmpUnLink(String appid) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("appid", appid);
String response = post(API_WX_AMP_LINK_UN, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
private JsonArray toJsonArray(List<String> strList) {
JsonArray jsonArray = new JsonArray();
if (strList != null && !strList.isEmpty()) {

View File

@ -0,0 +1,111 @@
package me.chanjar.weixin.open.bean.result;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* 公众号关联的小程序
*
* @author zhongjun
* @date 2022/4/29
**/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxAmpLinkResult extends WxOpenResult{
/**
* 关联的小程序列表具有 items 字段内带有参数
*/
@SerializedName("wxopens")
private WxOpen wxOpen;
@Getter
@Setter
public static class WxOpen{
@SerializedName("items")
private List<Item> items;
}
@Getter
@Setter
public static class Item{
/**
* 关联状态
* 1已关联
* 2等待小程序管理员确认中
* 3小程序管理员拒绝关联
* 12等待公众号管理员确认中
*/
private Integer status;
/**
* 小程序appid
*/
private String appid;
/**
* 小程序 gh_id
*/
private String username;
/**
* 小程序名称
*/
private String nickname;
/**
* 是否在公众号管理页展示中
*/
private Integer selected;
/**
* 是否展示在附近的小程序中
*/
@SerializedName("nearby_display_status")
private Integer nearbyDisplayStatus;
/**
* 是否已经发布
*/
private Integer released;
/**
* 头像 url
*/
@SerializedName("headimg_url")
private String headImgUrl;
/**
* 小程序邮箱
*/
private String email;
/**
* 微信认证及支付信息
*/
@SerializedName("func_info")
private List<FuncInfo> funcInfo;
}
@Getter
@Setter
public static class FuncInfo{
/**
* 微信认证及支付信息0 表示未开通1 表示开通
*/
private Integer status;
private String name;
private Long id;
}
}