8000 🆕 [微信开放平台]-增加半屏小程序管理相关接口 by aimmt918 · Pull Request #3431 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

🆕 [微信开放平台]-增加半屏小程序管理相关接口 #3431

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

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
🆕 [微信开放平台]-增加半屏小程序管理相关接口
  • Loading branch information
Aimkz committed Dec 4, 2024
commit 85adeeb0c4828975cc9a38ca552fce4658d74219
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package me.chanjar.weixin.open.api;

import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.bean.result.WxOpenMaEmbeddedListResult;

/**
* 半屏小程序管理服务
* <pre>
* <a href="https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/addEmbedded.html">半屏小程序管理</a>
* </pre>
*
* @author Yuan
* @version 1.0.0
* @date 2024-12-04 16:55:19
*/
public interface WxOpenMaEmbeddedService {

/**
* 添加半屏小程序
* <pre>
* 本接口用于添加半屏小程序
* </pre>
*/
String API_ADD_EMBEDDED = "https://api.weixin.qq.com/wxaapi/wxaembedded/add_embedded";

/**
* 删除半屏小程序
* <pre>
* 用本接口可以删除已经获得授权调用的半屏小程序
* 说明:通过add_embedded接口添加半屏小程序后,可通过当前接口删除已经添加到半屏小程序列表的小程序
* </pre>
*/
String API_DELETE_EMBEDDED = "https://api.weixin.qq.com/wxaapi/wxaembedded/del_embedded";

/**
* 获取半屏小程序调用列表
* <pre>
* 调用本接口可以获取半屏小程序调用列表
* 说明:通过addEmbedded接口添加半屏小程序后,可通过当前接口获取半屏小程序调用列表
* </pre>
*/
String API_GET_EMBEDDED_LIST = "https://api.weixin.qq.com/wxaapi/wxaembedded/get_list";

/**
* 取消授权小程序
* <pre>
* 调用本接口可以取消已经授权的小程序
* 说明:可通过get_own_list接口获取当前半屏小程序已经授权的小程序列表,可通过当前接口取消对某个小程序的调用权限
* </pre>
*/
String API_DELETE_AUTHORIZED_EMBEDDED = "https://api.weixin.qq.com/wxaapi/wxaembedded/del_authorize";

/**
* 获取半屏小程序授权列表
* <pre>
* 调用本接口可以获取半屏小程序授权列表
* 说明:一个半屏小程序可授权给1000个小程序调用,通过该接口可获取已经授权的小程序列表
* </pre>
*/
String API_GET_OWN_LIST = "https://api.weixin.qq.com/wxaapi/wxaembedded/get_own_list";

/**
* 设置授权方式
*/
String API_SET_AUTHORIZED_EMBEDDED = "https://api.weixin.qq.com/wxaapi/wxaembedded/set_authorize";

/**
* 添加半屏小程序
*
* @param embeddedAppId 半屏小程序appId
* @param applyReason 申请理由
* @author Yuan
* @date 2024-12-04 17:33:33
*/
void addEmbedded(String embeddedAppId, String applyReason) throws WxErrorException;

/**
* 删除半屏小程序
*
* @param embeddedAppId 半屏小程序appId
* @author Yuan
* @date 2024-12-04 17:33:33
*/
void deleteEmbedded(String embeddedAppId) throws WxErrorException;

/**
* 获取半屏小程序调用列表
*
* @return {@link WxOpenMaEmbeddedListResult }
* @author Yuan
* @date 2024-12-04 17:33:33
*/
WxOpenMaEmbeddedListResult getEmbeddedList() throws WxErrorException;

/**
* 取消授权小程序
*
* @param embeddedAppId 半屏小程序appId
* @author Yuan
* @date 2024-12-04 17:33:33
*/
void deleteAuthorizedEmbedded(String embeddedAppId) throws WxErrorException;

/**
* 获取半屏小程序授权列表,默认分页起始值为0,一次拉取最大值为1000
*
* @return {@link WxOpenMaEmbeddedListResult }
* @author Yuan
* @date 2024-12-04 17:33:33
*/
WxOpenMaEmbeddedListResult getOwnList() throws WxErrorException;

/**
* 获取半屏小程序授权列表
*
* @param start 分页起始值 ,默认值为0
* @param num 一次拉取最大值,最大 1000,默认值为10
* @return {@link WxOpenMaEmbeddedListResult }
* @author Yuan
* @date 2024-12-04 17:33:33
*/
WxOpenMaEmbeddedListResult getOwnList(Integer start, Integer num) throws WxErrorException;

/**
* 设置授权方式
*
* @param flag 半屏小程序授权方式。0表示需要管理员验证;1表示自动通过;2表示自动拒绝。
* @author Yuan
* @date 2024-12-04 17:33:33
*/
void setAuthorizedEmbedded(Integer flag) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,15 @@ WxOpenMaDomainResult modifyDomain(String action, List<String> requestDomains, Li
*/
WxOpenMaPrivacyService getPrivacyService();

/**
* 半屏小程序服务
*
* @return {@link WxOpenMaEmbeddedService }
* @author Yuan
* @date 2024-12-04 18:42:21
*/
WxOpenMaEmbeddedService getEmbeddedService();

/**
* 购物订单
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package me.chanjar.weixin.open.api.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenMaEmbeddedService;
import me.chanjar.weixin.open.bean.result.WxOpenMaEmbeddedListResult;
import org.apache.commons.lang3.StringUtils;

/**
* 半屏小程序管理服务
* <pre>
* <a href="https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/embedded-management/addEmbedded.html">半屏小程序管理</a>
* </pre>
*
* @author Yuan
* @version 1.0.0
* @date 2024-12-04 16:55:19
*/
@AllArgsConstructor
public class WxOpenMaEmbeddedServiceImpl implements WxOpenMaEmbeddedService {

private final WxMaService wxMaService;

/**
* 添加半屏小程序
*
* @param embeddedAppId 半屏小程序appId
* @param applyReason 申请理由
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public void addEmbedded(String embeddedAppId, String applyReason) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("appid", embeddedAppId);
if (StringUtils.isNotBlank(applyReason)) {
params.addProperty("apply_reason", applyReason);
}
String response = wxMaService.post(API_ADD_EMBEDDED, params);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
}

/**
* 删除半屏小程序
*
* @param embeddedAppId 半屏小程序appId
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public void deleteEmbedded(String embeddedAppId) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("appid", embeddedAppId);
String response = wxMaService.post(API_DELETE_EMBEDDED, params);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
}

/**
* 获取半屏小程序调用列表
*
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public WxOpenMaEmbeddedListResult getEmbeddedList() throws WxErrorException {
String response = wxMaService.get(API_GET_EMBEDDED_LIST, null);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaEmbeddedListResult.class);
}

/**
* 取消授权小程序
*
* @param embeddedAppId 半屏小程序appId
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public void deleteAuthorizedEmbedded(String embeddedAppId) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("appid", embeddedAppId);
String response = wxMaService.post(API_DELETE_AUTHORIZED_EMBEDDED, params);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
}

/**
* 获取半屏小程序授权列表
*
* @return {@link WxOpenMaEmbeddedListResult }
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public WxOpenMaEmbeddedListResult getOwnList() throws WxErrorException {
String response = wxMaService.get(API_GET_OWN_LIST + "?num=1000", null);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaEmbeddedListResult.class);
}

/**
* 获取半屏小程序授权列表
*
* @param start 分页起始值 ,默认值为0
* @param num 一次拉取最大值,最大 1000,默认值为10
* @return {@link WxOpenMaEmbeddedListResult }
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public WxOpenMaEmbeddedListResult getOwnList(Integer start, Integer num) throws WxErrorException {
if (null == start) {
start = 0;
}
if (null == num) {
num = 10;
}
if (num > 1000) {
num = 1000;
}
String response = wxMaService.get(API_GET_OWN_LIST + "?start=" + start + "&num=" + num, null);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
return WxMaGsonBuilder.create().fromJson(response, WxOpenMaEmbeddedListResult.class);
}

/**
* 设置授权方式
*
* @param flag 半屏小程序授权方式。0表示需要管理员验证;1表示自动通过;2表示自动拒绝。
* @author Yuan
* @date 2024-12-04 17:33:33
*/
@Override
public void setAuthorizedEmbedded(Integer flag) throws WxErrorException {
JsonObject params = new JsonObject();
params.addProperty("flag", flag);
String response = wxMaService.post(API_SET_AUTHORIZED_EMBEDDED, params);
WxError wxError = WxError.fromJson(response, WxType.MiniApp);
if (wxError.getErrorCode() != 0) {
throw new WxErrorException(wxError);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
private final WxOpenMaPrivacyService privacyService;
@Getter
private final WxOpenMaShoppingOrdersService shoppingOrdersService;
@Getter
private final WxOpenMaEmbeddedService embeddedService;

public WxOpenMaServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) {
this.wxOpenComponentService = wxOpenComponentService;
Expand All @@ -64,6 +66,7 @@ public WxOpenMaServiceImpl(WxOpenComponentService wxOpenComponentService, String
this.icpService = new WxOpenMaIcpServiceImpl(this);
this.privacyService = new WxOpenMaPrivacyServiceImpl(this);
this.shoppingOrdersService = new WxOpenMaShoppingOrdersServiceImpl(this);
this.embeddedService = new WxOpenMaEmbeddedServiceImpl(this);
initHttp();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.chanjar.weixin.open.bean.ma;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;

import java.io.Serializable;

/**
* 微信开放平台半屏小程序信息
*
* @author Yuan
* @version 1.0.0
* @date 2024-12-04 17:57:40
*/
@Data
public class WxOpenMaEmbedded implements Serializable {
private static final long serialVersionUID = -7319330493157204072L;

/**
* 半屏小程序appid
*/
@SerializedName("appid")
private String appId;
/**
* 添加时间
*/
@SerializedName("create_time")
private Long createTime;
/**
* 头像url
*/
@SerializedName("headimg")
private String headImg;
/**
* 半屏小程序昵称
*/
@SerializedName("nickname")
private String nickName;
/**
* 申请理由
*/
@SerializedName("reason")
private String reason;
/**
* 申请状态,1-待验证,2-已通过,3-已拒绝,4-已超时,5-已撤销,6-已取消授权
*/
@SerializedName("status")
private String status;

@Override
public String toString() {
return WxOpenGsonBuilder.create().toJson(this);
}

public String toJson() {
return WxOpenGsonBuilder.create().toJson(this);
}
}
Loading
0