Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(第三方平台):公众号业务相关接口 -小程序管理接口 #2630

Merged
merged 1 commit into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
* 获得小程序的域名配置信息
*
Expand Down Expand Up @@ -645,4 +658,48 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
* @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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ public WxMaAuditMediaUploadResult uploadMedia(File file) throws WxErrorException
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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
}