🎨 移动公众号关联小程序接口到 WxOpenMpService

This commit is contained in:
zhongjun 2022-10-25 10:55:02 +08:00 committed by GitHub
parent 2eb6180567
commit 62490c77b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 85 deletions

View File

@ -236,18 +236,6 @@ 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";
/**
* 小程序管理-查询小程序版本信息
@ -677,55 +665,6 @@ public interface WxOpenMaService extends WxMaService {
*/
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

@ -3,6 +3,8 @@ package me.chanjar.weixin.open.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.open.bean.mp.FastRegisterResult;
import me.chanjar.weixin.open.bean.result.WxAmpLinkResult;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
/**
* <pre>
@ -24,6 +26,19 @@ public interface WxOpenMpService extends WxMpService {
*/
String API_FAST_REGISTER = "https://api.weixin.qq.com/cgi-bin/account/fastregister";
/**
* 小程序管理-获取公众号关联的小程序
*/
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";
/**
* 取复用公众号快速注册小程序的授权链接
* 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 {
* @throws WxErrorException the wx error exception
*/
FastRegisterResult fastRegister(String ticket) 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

@ -407,30 +407,6 @@ 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

@ -1,6 +1,8 @@
package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonObject;
import lombok.SneakyThrows;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
@ -8,6 +10,8 @@ import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.open.api.WxOpenComponentService;
import me.chanjar.weixin.open.api.WxOpenMpService;
import me.chanjar.weixin.open.bean.mp.FastRegisterResult;
import me.chanjar.weixin.open.bean.result.WxAmpLinkResult;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
import java.net.URLEncoder;
import java.util.Objects;
@ -53,4 +57,30 @@ public class WxOpenMpServiceImpl extends WxMpServiceImpl implements WxOpenMpServ
String json = post(API_FAST_REGISTER, ImmutableMap.of("ticket", ticket));
return FastRegisterResult.fromJson(json);
}
@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, params.toString());
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, params.toString());
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
}