@@ -225,9 +234,85 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor, * @param takeOverUserid the take over userid * @return wx cp base resp * @throws WxErrorException the wx error exception + * @deprecated 此后续将不再更新维护,建议使用 {@link #transferCustomer(WxCpUserTransferCustomerReq)} */ + @Deprecated WxCpBaseResp transferExternalContact(String externalUserid, String handOverUserid, String takeOverUserid) throws WxErrorException; + /** + * 企业可通过此接口,转接在职成员的客户给其他成员。 + *+ * external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。 + * 在职成员的每位客户最多被分配2次。客户被转接成功后,将有90个自然日的服务关系保护期,保护期内的客户无法再次被分配。 + * + * 权限说明: + * * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。 + * 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限 + * 接替成员必须在此第三方应用或自建应用的可见范围内。 + * 接替成员需要配置了客户联系功能。 + * 接替成员需要在企业微信激活且已经过实名认证。 + * + * @param req 转接在职成员的客户给其他成员请求实体 + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpUserTransferCustomerResp transferCustomer(WxCpUserTransferCustomerReq req) throws WxErrorException; + + /** + * 企业和第三方可通过此接口查询在职成员的客户转接情况。 + *+ * 权限说明: + * + * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。 + * 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限 + * 接替成员必须在此第三方应用或自建应用的可见范围内。 + * + * @param handOverUserid 原添加成员的userid + * @param takeOverUserid 接替成员的userid + * @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页; + * @return 客户转接接口实体 + * @throws WxErrorException the wx error exception + */ + WxCpUserTransferResultResp transferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException; + + /** + * 企业可通过此接口,分配离职成员的客户给其他成员。 + *+ * handover_userid必须是已离职用户。 + * external_userid必须是handover_userid的客户(即配置了客户联系功能的成员所添加的联系人)。 + * 在职成员的每位客户最多被分配2次。客户被转接成功后,将有90个自然日的服务关系保护期,保护期内的客户无法再次被分配。 + * + * 权限说明: + * + * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。 + * 第三方应用需拥有“企业客户权限->客户联系->离职分配”权限 + * 接替成员必须在此第三方应用或自建应用的可见范围内。 + * 接替成员需要配置了客户联系功能。 + * 接替成员需要在企业微信激活且已经过实名认证。 + * + * @param req 转接在职成员的客户给其他成员请求实体 + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpUserTransferCustomerResp resignedTransferCustomer(WxCpUserTransferCustomerReq req) throws WxErrorException; + + /** + * 企业和第三方可通过此接口查询离职成员的客户分配情况。 + *+ * 权限说明: + * + * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。 + * 第三方应用需拥有“企业客户权限->客户联系->在职继承”权限 + * 接替成员必须在此第三方应用或自建应用的可见范围内。 + * + * @param handOverUserid 原添加成员的userid + * @param takeOverUserid 接替成员的userid + * @param cursor 分页查询的cursor,每个分页返回的数据不会超过1000条;不填或为空表示获取第一个分页; + * @return 客户转接接口实体 + * @throws WxErrorException the wx error exception + */ + WxCpUserTransferResultResp resignedTransferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException; + /** ** 该接口用于获取配置过客户群管理的客户群列表。 @@ -260,6 +345,32 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor, */ WxCpUserExternalGroupChatInfo getGroupChat(String chatId) throws WxErrorException; + /** + * + * 企业可通过此接口,将已离职成员为群主的群,分配给另一个客服成员。 + * + *+ * 注意:: + * + * 群主离职了的客户群,才可继承 + * 继承给的新群主,必须是配置了客户联系功能的成员 + * 继承给的新群主,必须有设置实名 + * 继承给的新群主,必须有激活企业微信 + * 同一个人的群,限制每天最多分配300个给新群主 + * + * 权限说明: + * + * 企业需要使用“客户联系”secret或配置到“可调用应用”列表中的自建应用secret所获取的accesstoken来调用(accesstoken如何获取?)。 + * 第三方应用需拥有“企业客户权限->客户联系->分配离职成员的客户群”权限 + * 对于第三方/自建应用,群主必须在应用的可见范围。 + * + * @param chatIds 需要转群主的客户群ID列表。取值范围: 1 ~ 100 + * @param newOwner 新群主ID + * @return 分配结果,主要是分配失败的群列表 + * @throws WxErrorException the wx error exception + */ + WxCpUserExternalGroupChatTransferResp transferGroupChat(String[] chatIds, String newOwner) throws WxErrorException; + /** ** 企业可通过此接口获取成员联系客户的数据,包括发起申请数、新增客户数、聊天数、发送消息数和删除/拉黑成员的客户数等指标。 @@ -397,4 +508,6 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor, * @throws WxErrorException the wx error exception */ WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException; + + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java index fae0a6a0d6..1b66d00c07 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java @@ -1,10 +1,7 @@ package me.chanjar.weixin.cp.api; import me.chanjar.weixin.common.error.WxErrorException; -import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage; -import me.chanjar.weixin.cp.bean.message.WxCpMessage; -import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult; -import me.chanjar.weixin.cp.bean.message.WxCpMessageSendStatistics; +import me.chanjar.weixin.cp.bean.message.*; /** * 消息推送接口. @@ -52,5 +49,5 @@ public interface WxCpMessageService { * @return the wx cp message send result * @throws WxErrorException the wx error exception */ - WxCpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException; + WxCpLinkedCorpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException; } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java index 19e7cdfe79..8065d21980 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java @@ -7,6 +7,8 @@ import me.chanjar.weixin.common.error.WxCpErrorMsgEnum; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxRuntimeException; +import me.chanjar.weixin.common.util.BeanUtils; +import me.chanjar.weixin.common.util.json.GsonParser; import me.chanjar.weixin.cp.api.WxCpExternalContactService; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.WxCpBaseResp; @@ -15,6 +17,7 @@ import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.Date; @@ -106,6 +109,16 @@ public WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorExc return WxCpExternalContactInfo.fromJson(responseContent); } + @Override + public String convertToOpenid(@NotNull String externalUserId) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("external_userid", externalUserId); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CONVERT_TO_OPENID); + String responseContent = this.mainService.post(url, json.toString()); + JsonObject tmpJson = GsonParser.parse(responseContent); + return tmpJson.get("openid").getAsString(); + } + @Override public WxCpExternalContactBatchInfo getContactDetailBatch(String userId, String cursor, @@ -176,6 +189,44 @@ public WxCpBaseResp transferExternalContact(String externalUserid, String handOv return WxCpBaseResp.fromJson(result); } + @Override + public WxCpUserTransferCustomerResp transferCustomer(WxCpUserTransferCustomerReq req) throws WxErrorException { + BeanUtils.checkRequiredFields(req); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(TRANSFER_CUSTOMER); + final String result = this.mainService.post(url, req.toJson()); + return WxCpUserTransferCustomerResp.fromJson(result); + } + + @Override + public WxCpUserTransferResultResp transferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("cursor", cursor); + json.addProperty("handover_userid", handOverUserid); + json.addProperty("takeover_userid", takeOverUserid); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(TRANSFER_RESULT); + final String result = this.mainService.post(url, json.toString()); + return WxCpUserTransferResultResp.fromJson(result); + } + + @Override + public WxCpUserTransferCustomerResp resignedTransferCustomer(WxCpUserTransferCustomerReq req) throws WxErrorException { + BeanUtils.checkRequiredFields(req); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(RESIGNED_TRANSFER_CUSTOMER); + final String result = this.mainService.post(url, req.toJson()); + return WxCpUserTransferCustomerResp.fromJson(result); + } + + @Override + public WxCpUserTransferResultResp resignedTransferResult(@NotNull String handOverUserid, @NotNull String takeOverUserid, String cursor) throws WxErrorException { + JsonObject json = new JsonObject(); + json.addProperty("cursor", cursor); + json.addProperty("handover_userid", handOverUserid); + json.addProperty("takeover_userid", takeOverUserid); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(RESIGNED_TRANSFER_RESULT); + final String result = this.mainService.post(url, json.toString()); + return WxCpUserTransferResultResp.fromJson(result); + } + @Override public WxCpUserExternalGroupChatList listGroupChat(Integer pageIndex, Integer pageSize, int status, String[] userIds, String[] partyIds) throws WxErrorException { JsonObject json = new JsonObject(); @@ -206,6 +257,18 @@ public WxCpUserExternalGroupChatInfo getGroupChat(String chatId) throws WxErrorE return WxCpUserExternalGroupChatInfo.fromJson(result); } + @Override + public WxCpUserExternalGroupChatTransferResp transferGroupChat(String[] chatIds, String newOwner) throws WxErrorException { + JsonObject json = new JsonObject(); + if (ArrayUtils.isNotEmpty(chatIds)) { + json.add("chat_id_list", new Gson().toJsonTree(chatIds).getAsJsonArray()); + } + json.addProperty("new_owner", newOwner); + final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GROUP_CHAT_TRANSFER); + final String result = this.mainService.post(url, json.toString()); + return WxCpUserExternalGroupChatTransferResp.fromJson(result); + } + @Override public WxCpUserExternalUserBehaviorStatistic getUserBehaviorStatistic(Date startTime, Date endTime, String[] userIds, String[] partyIds) throws WxErrorException { JsonObject json = new JsonObject(); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java index 07824c2183..9be2f60dfe 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java @@ -5,10 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpMessageService; import me.chanjar.weixin.cp.api.WxCpService; -import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage; -import me.chanjar.weixin.cp.bean.message.WxCpMessage; -import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult; -import me.chanjar.weixin.cp.bean.message.WxCpMessageSendStatistics; +import me.chanjar.weixin.cp.bean.message.*; import me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Message; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; @@ -40,13 +37,13 @@ public WxCpMessageSendStatistics getStatistics(int timeType) throws WxErrorExcep } @Override - public WxCpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException { + public WxCpLinkedCorpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException { Integer agentId = message.getAgentId(); if (null == agentId) { message.setAgentId(this.cpService.getWxCpConfigStorage().getAgentId()); } - return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage() + return WxCpLinkedCorpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage() .getApiUrl(Message.LINKEDCORP_MESSAGE_SEND), message.toJson())); } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserExternalGroupChatTransferResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserExternalGroupChatTransferResp.java new file mode 100644 index 0000000000..ff6fb82374 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserExternalGroupChatTransferResp.java @@ -0,0 +1,51 @@ +package me.chanjar.weixin.cp.bean.external; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 分配离职成员的客户群结果 + * @author pg + * @date 2021年6月21日 + */ +@Getter +@Setter +public class WxCpUserExternalGroupChatTransferResp extends WxCpBaseResp { + private static final long serialVersionUID = -943124579487821819L; + /** + * 没有成功继承的群列表 + */ + @SerializedName("failed_chat_list") + private ListfailedChatList; + + public static WxCpUserExternalGroupChatTransferResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalGroupChatTransferResp.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + @Getter + @Setter + public static class GroupChatFailedTransfer extends WxCpBaseResp { + private static final long serialVersionUID = -5836775099634587239L; + /** + * 没能成功继承的群ID + */ + private String chatId; + + public static WxCpUserExternalGroupChatTransferResp.GroupChatFailedTransfer fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalGroupChatTransferResp.GroupChatFailedTransfer.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferCustomerReq.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferCustomerReq.java new file mode 100644 index 0000000000..e8b8142cc6 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferCustomerReq.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.cp.bean.external; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.common.annotation.Required; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 转接在职成员的客户给其他成员,请求对象 + * + * @author pg + * @date 2021年6月21日 + */ +@Getter +@Setter +public class WxCpUserTransferCustomerReq implements Serializable { + private static final long serialVersionUID = -309819538677411801L; + /** + * 原跟进成员的userid + */ + @SerializedName("handover_userid") + @Required + private String handOverUserid; + /** + * 接替成员的userid + */ + @SerializedName("takeover_userid") + @Required + private String takeOverUserid; + /** + * 客户的external_userid列表,每次最多分配100个客户 + */ + @SerializedName("external_userid") + @Required + private List externalUserid; + /** + * 转移成功后发给客户的消息,最多200个字符,不填则使用默认文案 + */ + @SerializedName("transfer_success_msg") + private String transferMsg; + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferCustomerResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferCustomerResp.java new file mode 100644 index 0000000000..27d1c0ad4c --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferCustomerResp.java @@ -0,0 +1,60 @@ +package me.chanjar.weixin.cp.bean.external; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 转接在职成员的客户给其他成员,返回对象 + * + * @author pg + * @date 2021年6月21日 + */ +@Getter +@Setter +public class WxCpUserTransferCustomerResp extends WxCpBaseResp { + private static final long serialVersionUID = -8030598756503590089L; + /** + * 客户转移结果列表 + */ + private List customer; + + public static WxCpUserTransferCustomerResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUserTransferCustomerResp.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + /** + * 转接客户结果实体 + */ + @Getter + @Setter + public static class TransferCustomer implements Serializable { + private static final long serialVersionUID = 8720554208727083338L; + /** + * 客户的external_userid + */ + @SerializedName("external_userid") + private String externalUserid; + /** + * 对此客户进行分配的结果, 0表示成功发起接替,待24小时后自动接替,并不代表最终接替成功 + */ + private Integer errcode; + + public static WxCpUserTransferCustomerResp.TransferCustomer fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUserTransferCustomerResp.TransferCustomer.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferResultResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferResultResp.java new file mode 100644 index 0000000000..e1b8cc4591 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpUserTransferResultResp.java @@ -0,0 +1,92 @@ +package me.chanjar.weixin.cp.bean.external; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 在职成员的客户转接情况 + * @author pg + * @date 2021年6月21日 + */ +@Getter +@Setter +public class WxCpUserTransferResultResp extends WxCpBaseResp { + private static final long serialVersionUID = 6897979567174991786L; + @SerializedName("next_cursor") + private String nextCursor; + + public static WxCpUserTransferResultResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUserTransferResultResp.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + /** + * 客户转接结果实体 + */ + @Getter + @Setter + public static class TransferResult implements Serializable { + private static final long serialVersionUID = 2847784363733118393L; + + /** + * 客户的external_userid + */ + @SerializedName("external_userid") + private String externalUserid; + /** + * 接替状态, 1-接替完毕 2-等待接替 3-客户拒绝 4-接替成员客户达到上限 5-无接替记录 + */ + private STATUS status; + /** + * 接替客户的时间,如果是等待接替状态,则为未来的自动接替时间 + */ + @SerializedName("takeover_time") + private Long takeOverTime; + + public static WxCpUserTransferResultResp.TransferResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUserTransferResultResp.TransferResult.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + } + + public enum STATUS { + + /** + * 接替完毕 + */ + @SerializedName("1") + COMPLETE, + + /** + * 等待接替 + */ + @SerializedName("2") + WAITING, + /** + * 客户拒绝 + */ + @SerializedName("3") + REFUSED, + /** + * 接替成员客户达到上限 + */ + @SerializedName("4") + LIMIT, + /** + * 无接替记录 + */ + @SerializedName("5") + NORECORD + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpWelcomeMsg.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpWelcomeMsg.java index ce744b9f24..ade49684ce 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpWelcomeMsg.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpWelcomeMsg.java @@ -2,13 +2,11 @@ import com.google.gson.annotations.SerializedName; import lombok.*; -import me.chanjar.weixin.cp.bean.external.msg.Image; -import me.chanjar.weixin.cp.bean.external.msg.Link; -import me.chanjar.weixin.cp.bean.external.msg.MiniProgram; -import me.chanjar.weixin.cp.bean.external.msg.Text; +import me.chanjar.weixin.cp.bean.external.msg.*; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import java.io.Serializable; +import java.util.List; /** * 新客户欢迎语. @@ -28,11 +26,7 @@ public class WxCpWelcomeMsg implements Serializable { private Text text; - private Image image; - - private Link link; - - private MiniProgram miniprogram; + private List attachments; public String toJson() { return WxCpGsonBuilder.create().toJson(this); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/contact/WxCpExternalContactInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/contact/WxCpExternalContactInfo.java index bd7229384c..468aa53f1e 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/contact/WxCpExternalContactInfo.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/contact/WxCpExternalContactInfo.java @@ -26,6 +26,9 @@ public class WxCpExternalContactInfo implements Serializable { @SerializedName("follow_user") private List followedUsers; + @SerializedName("next_cursor") + private String nextCursor; + public static WxCpExternalContactInfo fromJson(String json) { return WxCpGsonBuilder.create().fromJson(json, WxCpExternalContactInfo.class); } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Attachment.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Attachment.java new file mode 100644 index 0000000000..0c64b9bf63 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Attachment.java @@ -0,0 +1,76 @@ +package me.chanjar.weixin.cp.bean.external.msg; + +import com.google.gson.annotations.SerializedName; +import me.chanjar.weixin.cp.constant.WxCpConsts; + +import java.io.Serializable; + +public class Attachment implements Serializable { + private static final long serialVersionUID = -8078748379570640198L; + + @SerializedName("msgtype") + private String msgType; + + private Image image; + + private Link link; + + private MiniProgram miniprogram; + + private Video video; + + @Override + public String toString() { + return "Attachment{" + + "msgType='" + msgType + '\'' + + ", image=" + image + + ", link=" + link + + ", miniprogram=" + miniprogram + + ", video=" + video + + '}'; + } + + private String getMsgType() { + return msgType; + } + + private void setMsgType(String msgType) { + this.msgType = msgType; + } + + public Image getImage() { + return image; + } + + public void setImage(Image image) { + this.image = image; + this.msgType = WxCpConsts.WelcomeMsgType.IMAGE; + } + + public Link getLink() { + return link; + } + + public void setLink(Link link) { + this.link = link; + this.msgType = WxCpConsts.WelcomeMsgType.LINK; + } + + public MiniProgram getMiniprogram() { + return miniprogram; + } + + public void setMiniprogram(MiniProgram miniprogram) { + this.miniprogram = miniprogram; + this.msgType = WxCpConsts.WelcomeMsgType.MINIPROGRAM; + } + + public Video getVideo() { + return video; + } + + public void setVideo(Video video) { + this.video = video; + this.msgType = WxCpConsts.WelcomeMsgType.VIDEO; + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Video.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Video.java new file mode 100644 index 0000000000..237fb75cfe --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Video.java @@ -0,0 +1,19 @@ +package me.chanjar.weixin.cp.bean.external.msg; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 视频消息 + * + * @author pg + * @date 2021-6-21 + */ +@Data +public class Video implements Serializable { + private static final long serialVersionUID = -6048642921382867138L; + @SerializedName("media_id") + private String mediaId; +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpLinkedCorpMessageSendResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpLinkedCorpMessageSendResult.java new file mode 100644 index 0000000000..2955df54c6 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpLinkedCorpMessageSendResult.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.cp.bean.message; + +import com.google.gson.annotations.SerializedName; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +/** + * 互联企业的消息推送接口返回实体 + * + * @author pg + * @date 2021年6月22日 + */ +@Setter +@Getter +public class WxCpLinkedCorpMessageSendResult extends WxCpBaseResp { + private static final long serialVersionUID = 3990693822996824333L; + + @SerializedName("invaliduser") + private String[] invalidUser; + + @SerializedName("invalidparty") + private String[] invalidParty; + + @SerializedName("invalidtag") + private String[] invalidTag; + + @Override + public String toString() { + return WxCpGsonBuilder.create().toJson(this); + } + + public static WxCpLinkedCorpMessageSendResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpLinkedCorpMessageSendResult.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index bc96269ea8..c60a1bddbd 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -175,13 +175,20 @@ interface ExternalContact { String CLOSE_TEMP_CHAT = "/cgi-bin/externalcontact/close_temp_chat"; String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list"; String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid="; + String CONVERT_TO_OPENID = "/cgi-bin/externalcontact/convert_to_openid"; String GET_CONTACT_DETAIL_BATCH = "/cgi-bin/externalcontact/batch/get_by_user?"; String UPDATE_REMARK = "/cgi-bin/externalcontact/remark"; String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid="; String LIST_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/get_unassigned_list"; + @Deprecated String TRANSFER_UNASSIGNED_CONTACT = "/cgi-bin/externalcontact/transfer"; + String TRANSFER_CUSTOMER = "/cgi-bin/externalcontact/transfer_customer"; + String TRANSFER_RESULT = "/cgi-bin/externalcontact/transfer_result"; + String RESIGNED_TRANSFER_CUSTOMER = "/cgi-bin/externalcontact/resigned/transfer_customer"; + String RESIGNED_TRANSFER_RESULT = "/cgi-bin/externalcontact/resigned/transfer_result"; String GROUP_CHAT_LIST = "/cgi-bin/externalcontact/groupchat/list"; String GROUP_CHAT_INFO = "/cgi-bin/externalcontact/groupchat/get"; + String GROUP_CHAT_TRANSFER = "/cgi-bin/externalcontact/groupchat/transfer"; String LIST_USER_BEHAVIOR_DATA = "/cgi-bin/externalcontact/get_user_behavior_data"; String LIST_GROUP_CHAT_DATA = "/cgi-bin/externalcontact/groupchat/statistic"; String ADD_MSG_TEMPLATE = "/cgi-bin/externalcontact/add_msg_template"; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java index 4a41fa8f71..69db78efbe 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java @@ -334,4 +334,24 @@ public static class WorkBenchType { * */ public static final String WEBVIEW = "webview"; } + + @UtilityClass + public static class WelcomeMsgType { + /** + * 图片消息. + */ + public static final String IMAGE = "image"; + /** + * 图文消息. + */ + public static final String LINK = "link"; + /** + * 视频消息. + */ + public static final String VIDEO = "video"; + /** + * 小程序消息. + */ + public static final String MINIPROGRAM = "miniprogram"; + } } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java index 29089d478d..8869a6a02b 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java @@ -8,11 +8,15 @@ import me.chanjar.weixin.cp.bean.WxCpBaseResp; import me.chanjar.weixin.cp.bean.external.*; import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo; +import me.chanjar.weixin.cp.bean.external.msg.Attachment; +import me.chanjar.weixin.cp.bean.external.msg.Image; +import me.chanjar.weixin.cp.bean.external.msg.Video; import org.apache.commons.lang3.time.DateFormatUtils; import org.testng.annotations.Guice; import org.testng.annotations.Test; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -193,13 +197,62 @@ public void testTransferExternalContact() { } @Test - public void testListGroupChat() { + public void testTransferCustomer() throws WxErrorException { + WxCpUserTransferCustomerReq req = new WxCpUserTransferCustomerReq(); + req.setExternalUserid(Collections.emptyList()); + req.setHandOverUserid("123"); + req.setTakeOverUserid("234"); + WxCpBaseResp result = this.wxCpService.getExternalContactService().transferCustomer(req); + + System.out.println(result); + assertNotNull(result); + } + + @Test + public void testTrnsferResult() throws WxErrorException { + WxCpUserTransferResultResp result = this.wxCpService.getExternalContactService().transferResult("123", "234", ""); + System.out.println(result); + assertNotNull(result); + } + + @Test + public void testresignedTransferCustomer() throws WxErrorException { + WxCpUserTransferCustomerReq req = new WxCpUserTransferCustomerReq(); + req.setExternalUserid(Collections.emptyList()); + req.setHandOverUserid("123"); + req.setTakeOverUserid("234"); + WxCpBaseResp result = this.wxCpService.getExternalContactService().resignedTransferCustomer(req); + + System.out.println(result); + assertNotNull(result); + } + + @Test + public void testresignedTrnsferResult() throws WxErrorException { + WxCpUserTransferResultResp result = this.wxCpService.getExternalContactService().resignedTransferResult("123", "234", ""); + System.out.println(result); + assertNotNull(result); + } + + @Test + public void testListGroupChat() throws WxErrorException { + WxCpUserExternalGroupChatList result = this.wxCpService.getExternalContactService().listGroupChat(0, 100 ,0,new String[1],new String[1]); + System.out.println(result); + assertNotNull(result); } @Test public void testGetGroupChat() { } + @Test + public void testTransferGroupChat() throws WxErrorException { + String[] str = {"wri1_QEAAATfnZl_VJ4hlQda0e4Mgf1A"}; + WxCpUserExternalGroupChatTransferResp result = this.wxCpService.getExternalContactService().transferGroupChat(str, "123"); + System.out.println(result); + assertNotNull(result); + } + @Test public void testGetUserBehaviorStatistic() { } @@ -214,8 +267,22 @@ public void testAddMsgTemplate() { @Test public void testSendWelcomeMsg() throws WxErrorException { + Image image = new Image(); + image.setMediaId("123123"); + Attachment attachment = new Attachment(); + attachment.setImage(image); + + Video video = new Video(); + video.setMediaId("video_media_id"); + Attachment attachment2 = new Attachment(); + attachment2.setVideo(video); + + List attachments = new ArrayList<>(); + attachments.add(attachment); + attachments.add(attachment2); this.wxCpService.getExternalContactService().sendWelcomeMsg(WxCpWelcomeMsg.builder() .welcomeCode("abc") + .attachments(attachments) .build()); } diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java index 26dc2ba7f2..4c7f5b0911 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java @@ -148,7 +148,9 @@ public interface WxOpenComponentService { * * @param appid . * @return . wx fast ma service by appid + * @deprecated 2021-06-23 本接口原有方法并非仅快速创建小程序的专用接口,普通小程序授权到第三方平台皆可使用,所以请使用 {@link WxOpenMaBasicService} 类替代。获取方法: WxOpenMaService.getBasicService() */ + @Deprecated WxOpenFastMaService getWxFastMaServiceByAppid(String appid); /** diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenFastMaService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenFastMaService.java index 8710689cdc..2114d1a816 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenFastMaService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenFastMaService.java @@ -1,11 +1,6 @@ package me.chanjar.weixin.open.api; import cn.binarywang.wx.miniapp.api.WxMaService; -import me.chanjar.weixin.common.error.WxErrorException; -import me.chanjar.weixin.open.bean.ma.WxFastMaCategory; -import me.chanjar.weixin.open.bean.result.*; - -import java.util.List; /** * @@ -16,189 +11,9 @@ * * @author Hipple * @date 2019/01/23 + * @deprecated 2021-06-23 本接口原有方法并非仅快速创建小程序的专用接口,普通小程序授权到第三方平台皆可使用,所以请使用 {@link WxOpenMaBasicService} 类替代。获取方法: WxOpenComponentService.getWxMaServiceByAppid(maApppId).getBasicService() */ -public interface WxOpenFastMaService extends WxMaService { - /** - * 1 获取帐号基本信息. - */ - String OPEN_GET_ACCOUNT_BASIC_INFO = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo"; - - /** - * 2 小程序名称设置及改名. - */ - String OPEN_SET_NICKNAME = "https://api.weixin.qq.com/wxa/setnickname"; - - /** - * 3 小程序改名审核状态查询. - */ - String OPEN_API_WXA_QUERYNICKNAME = "https://api.weixin.qq.com/wxa/api_wxa_querynickname"; - - /** - * 4 微信认证名称检测. - */ - String OPEN_CHECK_WX_VERIFY_NICKNAME = "https://api.weixin.qq.com/cgi-bin/wxverify/checkwxverifynickname"; - - /** - * 5 修改头像. - */ - String OPEN_MODIFY_HEADIMAGE = "https://api.weixin.qq.com/cgi-bin/account/modifyheadimage"; - - /** - * 6修改功能介绍. - */ - String OPEN_MODIFY_SIGNATURE = "https://api.weixin.qq.com/cgi-bin/account/modifysignature"; - - /** - * 7 换绑小程序管理员接口. - */ - String OPEN_COMPONENT_REBIND_ADMIN = "https://api.weixin.qq.com/cgi-bin/account/componentrebindadmin"; - - /** - * 8.1 获取账号可以设置的所有类目 - */ - String OPEN_GET_ALL_CATEGORIES = "https://api.weixin.qq.com/cgi-bin/wxopen/getallcategories"; - /** - * 8.2 添加类目 - */ - String OPEN_ADD_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/addcategory"; - /** - * 8.3 删除类目 - */ - String OPEN_DELETE_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory"; - /** - * 8.4 获取账号已经设置的所有类目 - */ - String OPEN_GET_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/getcategory"; - /** - * 8.5 修改类目 - */ - String OPEN_MODIFY_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory"; - - - /** - * 1.获取小程序的信息 - * - * @return . - * @throws WxErrorException . - */ - WxFastMaAccountBasicInfoResult getAccountBasicInfo() throws WxErrorException; - - /** - * 2.小程序名称设置及改名 - *- * 若接口未返回audit_id,说明名称已直接设置成功,无需审核;若返回audit_id则名称正在审核中。 - *- * - * @param nickname 昵称 - * @param idCard 身份证照片–临时素材mediaid(个人号必填) - * @param license 组织机构代码证或营业执照–临时素材mediaid(组织号必填) - * @param namingOtherStuff1 其他证明材料---临时素材 mediaid - * @param namingOtherStuff2 其他证明材料---临时素材 mediaid - * @return . - * @throws WxErrorException . - */ - WxFastMaSetNickameResult setNickname(String nickname, String idCard, String license, String namingOtherStuff1, - String namingOtherStuff2) throws WxErrorException; - - /** - * 3 小程序改名审核状态查询 - * - * @param auditId 审核单id - * @return . - * @throws WxErrorException . - */ - WxFastMaQueryNicknameStatusResult querySetNicknameStatus(String auditId) throws WxErrorException; - - /** - * 4. 微信认证名称检测 - * - * @param nickname 名称 - * @return . - * @throws WxErrorException . - */ - WxFastMaCheckNickameResult checkWxVerifyNickname(String nickname) throws WxErrorException; - - /** - * 5.修改头像 - *- * 图片格式只支持:BMP、JPEG、JPG、GIF、PNG,大小不超过2M - * 注:实际头像始终为正方形 - *- * - * @param headImgMediaId 头像素材media_id - * @param x1 裁剪框左上角x坐标(取值范围:[0, 1]) - * @param y1 裁剪框左上角y坐标(取值范围:[0, 1]) - * @param x2 裁剪框右下角x坐标(取值范围:[0, 1]) - * @param y2 裁剪框右下角y坐标(取值范围:[0, 1]) - * @return . - * @throws WxErrorException . - */ - WxOpenResult modifyHeadImage(String headImgMediaId, float x1, float y1, float x2, float y2) throws WxErrorException; - - /** - * 6.修改功能介绍 - * - * @param signature 简介:4-120字 - * @return . - * @throws WxErrorException . - */ - WxOpenResult modifySignature(String signature) throws WxErrorException; - - /** - * 7.3 管理员换绑 - * - * @param taskId 换绑管理员任务序列号(公众平台最终点击提交回跳到第三方平台时携带) - * @return . - * @throws WxErrorException . - */ - WxOpenResult componentRebindAdmin(String taskId) throws WxErrorException; - - /** - * 8.1 获取账号可以设置的所有类目 - *- * 因为不同类目含有特定字段 - * 目前没有完整的类目信息数据 - * 为保证兼容性,放弃将response转换为实体 - *- * - * @return . - * @throws WxErrorException . - */ - String getAllCategories() throws WxErrorException; - - /** - * 8.2添加类目 - * - * @param categoryList 类目列表 - * @return . - * @throws WxErrorException . - */ - WxOpenResult addCategory(ListcategoryList) throws WxErrorException; - - /** - * 8.3删除类目 - * - * @param first 一级类目ID - * @param second 二级类目ID - * @return . - * @throws WxErrorException . - */ - WxOpenResult deleteCategory(int first, int second) throws WxErrorException; - - /** - * 8.4获取账号已经设置的所有类目 - * - * @return . - * @throws WxErrorException . - */ - WxFastMaBeenSetCategoryResult getCategory() throws WxErrorException; +@Deprecated +public interface WxOpenFastMaService extends WxOpenMaBasicService, WxMaService { - /** - * 8.5修改类目 - * - * @param category 实体 - * @return . - * @throws WxErrorException . - */ - WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorException; } diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java new file mode 100644 index 0000000000..194da4b9b3 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaBasicService.java @@ -0,0 +1,199 @@ +package me.chanjar.weixin.open.api; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.open.bean.ma.WxFastMaCategory; +import me.chanjar.weixin.open.bean.result.*; + +import java.util.List; + +/** + * 微信第三方平台 小程序基础信息接口 (小程序名称、头像、描述、类目等信息设置) + * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/category/getallcategories.html + * + * @author 广州跨界 + */ +public interface WxOpenMaBasicService { + /** + * 1 获取帐号基本信息. + */ + String OPEN_GET_ACCOUNT_BASIC_INFO = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo"; + + /** + * 2 小程序名称设置及改名. + */ + String OPEN_SET_NICKNAME = "https://api.weixin.qq.com/wxa/setnickname"; + + /** + * 3 小程序改名审核状态查询. + */ + String OPEN_API_WXA_QUERYNICKNAME = "https://api.weixin.qq.com/wxa/api_wxa_querynickname"; + + /** + * 4 微信认证名称检测. + */ + String OPEN_CHECK_WX_VERIFY_NICKNAME = "https://api.weixin.qq.com/cgi-bin/wxverify/checkwxverifynickname"; + + /** + * 5 修改头像. + */ + String OPEN_MODIFY_HEADIMAGE = "https://api.weixin.qq.com/cgi-bin/account/modifyheadimage"; + + /** + * 6修改功能介绍. + */ + String OPEN_MODIFY_SIGNATURE = "https://api.weixin.qq.com/cgi-bin/account/modifysignature"; + + /** + * 7 换绑小程序管理员接口. + */ + String OPEN_COMPONENT_REBIND_ADMIN = "https://api.weixin.qq.com/cgi-bin/account/componentrebindadmin"; + + /** + * 8.1 获取账号可以设置的所有类目 + */ + String OPEN_GET_ALL_CATEGORIES = "https://api.weixin.qq.com/cgi-bin/wxopen/getallcategories"; + /** + * 8.2 添加类目 + */ + String OPEN_ADD_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/addcategory"; + /** + * 8.3 删除类目 + */ + String OPEN_DELETE_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/deletecategory"; + /** + * 8.4 获取账号已经设置的所有类目 + */ + String OPEN_GET_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/getcategory"; + /** + * 8.5 修改类目 + */ + String OPEN_MODIFY_CATEGORY = "https://api.weixin.qq.com/cgi-bin/wxopen/modifycategory"; + + + /** + * 1.获取小程序的信息 + * + * @return . + * @throws WxErrorException . + */ + WxFastMaAccountBasicInfoResult getAccountBasicInfo() throws WxErrorException; + + /** + * 2.小程序名称设置及改名 + * + * 若接口未返回audit_id,说明名称已直接设置成功,无需审核;若返回audit_id则名称正在审核中。 + *+ * + * @param nickname 昵称 + * @param idCard 身份证照片–临时素材mediaid(个人号必填) + * @param license 组织机构代码证或营业执照–临时素材mediaid(组织号必填) + * @param namingOtherStuff1 其他证明材料---临时素材 mediaid + * @param namingOtherStuff2 其他证明材料---临时素材 mediaid + * @return . + * @throws WxErrorException . + */ + WxFastMaSetNickameResult setNickname(String nickname, String idCard, String license, String namingOtherStuff1, + String namingOtherStuff2) throws WxErrorException; + + /** + * 3 小程序改名审核状态查询 + * + * @param auditId 审核单id + * @return . + * @throws WxErrorException . + */ + WxFastMaQueryNicknameStatusResult querySetNicknameStatus(String auditId) throws WxErrorException; + + /** + * 4. 微信认证名称检测 + * + * @param nickname 名称 + * @return . + * @throws WxErrorException . + */ + WxFastMaCheckNickameResult checkWxVerifyNickname(String nickname) throws WxErrorException; + + /** + * 5.修改头像 + *+ * 图片格式只支持:BMP、JPEG、JPG、GIF、PNG,大小不超过2M + * 注:实际头像始终为正方形 + *+ * + * @param headImgMediaId 头像素材media_id + * @param x1 裁剪框左上角x坐标(取值范围:[0, 1]) + * @param y1 裁剪框左上角y坐标(取值范围:[0, 1]) + * @param x2 裁剪框右下角x坐标(取值范围:[0, 1]) + * @param y2 裁剪框右下角y坐标(取值范围:[0, 1]) + * @return . + * @throws WxErrorException . + */ + WxOpenResult modifyHeadImage(String headImgMediaId, float x1, float y1, float x2, float y2) throws WxErrorException; + + /** + * 6.修改功能介绍 + * + * @param signature 简介:4-120字 + * @return . + * @throws WxErrorException . + */ + WxOpenResult modifySignature(String signature) throws WxErrorException; + + /** + * 7.3 管理员换绑 + * + * @param taskId 换绑管理员任务序列号(公众平台最终点击提交回跳到第三方平台时携带) + * @return . + * @throws WxErrorException . + */ + WxOpenResult componentRebindAdmin(String taskId) throws WxErrorException; + + /** + * 8.1 获取账号可以设置的所有类目 + *+ * 因为不同类目含有特定字段 + * 目前没有完整的类目信息数据 + * 为保证兼容性,放弃将response转换为实体 + *+ * + * @return . + * @throws WxErrorException . + */ + String getAllCategories() throws WxErrorException; + + /** + * 8.2添加类目 + * + * @param categoryList 类目列表 + * @return . + * @throws WxErrorException . + */ + WxOpenResult addCategory(ListcategoryList) throws WxErrorException; + + /** + * 8.3删除类目 + * + * @param first 一级类目ID + * @param second 二级类目ID + * @return . + * @throws WxErrorException . + */ + WxOpenResult deleteCategory(int first, int second) throws WxErrorException; + + /** + * 8.4获取账号已经设置的所有类目 + * + * @return . + * @throws WxErrorException . + */ + WxFastMaBeenSetCategoryResult getCategory() throws WxErrorException; + + /** + * 8.5修改类目 + * + * @param category 实体 + * @return . + * @throws WxErrorException . + */ + WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorException; +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaService.java index ccaeeff019..9732e614ac 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenMaService.java @@ -452,6 +452,16 @@ WxOpenMaDomainResult modifyDomain(String action, List requestDomains, Li */ WxOpenResult revertCodeRelease() throws WxErrorException; + /** + * 获取可回退的小程序版本 + * 调用本接口可以获取可回退的小程序版本(最多保存最近发布或回退的5个版本 + * 文档地址: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/get_history_version.html + * + * @return 历史版本信息 + * @throws WxErrorException 如果调用微信接口失败抛出此异常 + */ + WxOpenMaHistoryVersionResult getHistoryVersion() throws WxErrorException; + /** * 15. 小程序审核撤回 * @@ -583,4 +593,11 @@ WxOpenMaDomainResult modifyDomain(String action, List
requestDomains, Li * @throws WxErrorException the wx error exception */ WxOpenResult publishQrcodeJump(String prefix) throws WxErrorException; + + /** + * 小程序基础信息服务 (小程序名称、头像、描述、类目等信息设置) + * + * @return 小程序基础信息服务 + */ + WxOpenMaBasicService getBasicService(); } diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java index 2cea9530bb..f5f2160d21 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenFastMaServiceImpl.java @@ -20,7 +20,9 @@ * * @author Hipple * @since 2019/1/23 15:27 + * @deprecated 请使用 {@link WxOpenMaServiceImpl} 替代 */ +@Deprecated public class WxOpenFastMaServiceImpl extends WxMaServiceImpl implements WxOpenFastMaService { private final WxOpenComponentService wxOpenComponentService; private final WxMaConfig wxMaConfig; diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java new file mode 100644 index 0000000000..4e4db75257 --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaBasicServiceImpl.java @@ -0,0 +1,135 @@ +package me.chanjar.weixin.open.api.impl; + +import cn.binarywang.wx.miniapp.api.WxMaService; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.open.api.WxOpenMaBasicService; +import me.chanjar.weixin.open.bean.ma.WxFastMaCategory; +import me.chanjar.weixin.open.bean.result.*; +import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 微信第三方平台 小程序基础信息接口 + * + * @author 广州跨界 + */ +public class WxOpenMaBasicServiceImpl implements WxOpenMaBasicService { + + private final WxMaService wxMaService; + + public WxOpenMaBasicServiceImpl(WxMaService wxMaService) { + this.wxMaService = wxMaService; + } + + + @Override + public WxFastMaAccountBasicInfoResult getAccountBasicInfo() throws WxErrorException { + String response = wxMaService.get(OPEN_GET_ACCOUNT_BASIC_INFO, ""); + return WxOpenGsonBuilder.create().fromJson(response, WxFastMaAccountBasicInfoResult.class); + } + + @Override + public WxFastMaSetNickameResult setNickname(String nickname, String idCard, String license, String namingOtherStuff1, String namingOtherStuff2) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("nick_name", nickname); + params.addProperty("id_card", idCard); + params.addProperty("license", license); + params.addProperty("naming_other_stuff_1", namingOtherStuff1); + params.addProperty("naming_other_stuff_2", namingOtherStuff2); + String response = wxMaService.post(OPEN_SET_NICKNAME, params); + return WxOpenGsonBuilder.create().fromJson(response, WxFastMaSetNickameResult.class); + } + + @Override + public WxFastMaQueryNicknameStatusResult querySetNicknameStatus(String auditId) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("audit_id", auditId); + String response = wxMaService.post(OPEN_API_WXA_QUERYNICKNAME, params); + return WxOpenGsonBuilder.create().fromJson(response, WxFastMaQueryNicknameStatusResult.class); + } + + @Override + public WxFastMaCheckNickameResult checkWxVerifyNickname(String nickname) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("nick_name", nickname); + String response = wxMaService.post(OPEN_CHECK_WX_VERIFY_NICKNAME, params); + return WxOpenGsonBuilder.create().fromJson(response, WxFastMaCheckNickameResult.class); + } + + @Override + public WxOpenResult modifyHeadImage(String headImgMediaId, float x1, float y1, float x2, float y2) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("head_img_media_id", headImgMediaId); + params.addProperty("x1", x1); + params.addProperty("y1", y1); + params.addProperty("x2", x2); + params.addProperty("y2", y2); + String response = wxMaService.post(OPEN_MODIFY_HEADIMAGE, params); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); + } + + @Override + public WxOpenResult modifySignature(String signature) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("signature", signature); + String response = wxMaService.post(OPEN_MODIFY_SIGNATURE, params); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); + } + + @Override + public WxOpenResult componentRebindAdmin(String taskid) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("taskid", taskid); + String response = wxMaService.post(OPEN_COMPONENT_REBIND_ADMIN, params); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); + } + + @Override + public String getAllCategories() throws WxErrorException { + return wxMaService.get(OPEN_GET_ALL_CATEGORIES, ""); + } + + @Override + public WxOpenResult addCategory(List categoryList) throws WxErrorException { + Map map = new HashMap<>(); + map.put("categories", categoryList); + String response = wxMaService.post(OPEN_ADD_CATEGORY, WxOpenGsonBuilder.create().toJson(map)); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); + } + + @Override + public WxOpenResult deleteCategory(int first, int second) throws WxErrorException { + JsonObject params = new JsonObject(); + params.addProperty("first", first); + params.addProperty("second", second); + String response = wxMaService.post(OPEN_DELETE_CATEGORY, params); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); + } + + @Override + public WxFastMaBeenSetCategoryResult getCategory() throws WxErrorException { + String response = wxMaService.get(OPEN_GET_CATEGORY, ""); + return WxOpenGsonBuilder.create().fromJson(response, WxFastMaBeenSetCategoryResult.class); + } + + @Override + public WxOpenResult modifyCategory(WxFastMaCategory category) throws WxErrorException { + String response = wxMaService.post(OPEN_MODIFY_CATEGORY, category); + return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class); + } + + private JsonArray toJsonArray(List strList) { + JsonArray jsonArray = new JsonArray(); + if (strList != null && !strList.isEmpty()) { + for (String str : strList) { + jsonArray.add(str); + } + } + return jsonArray; + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java index 24d9e23414..9febf639f4 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMaServiceImpl.java @@ -7,8 +7,10 @@ import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import lombok.Getter; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.open.api.WxOpenComponentService; +import me.chanjar.weixin.open.api.WxOpenMaBasicService; import me.chanjar.weixin.open.api.WxOpenMaService; import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo; import me.chanjar.weixin.open.bean.ma.WxMaQrcodeParam; @@ -34,11 +36,14 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ private final WxOpenComponentService wxOpenComponentService; private final WxMaConfig wxMaConfig; private final String appId; + @Getter + private final WxOpenMaBasicService basicService; public WxOpenMaServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) { this.wxOpenComponentService = wxOpenComponentService; this.appId = appId; this.wxMaConfig = wxMaConfig; + this.basicService = new WxOpenMaBasicServiceImpl(this); initHttp(); } @@ -247,6 +252,12 @@ public WxOpenResult revertCodeRelease() throws WxErrorException { return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class); } + @Override + public WxOpenMaHistoryVersionResult getHistoryVersion() throws WxErrorException { + String response = get(API_REVERT_CODE_RELEASE, "action=get_history_version"); + return WxMaGsonBuilder.create().fromJson(response, WxOpenMaHistoryVersionResult.class); + } + @Override public WxOpenResult undoCodeAudit() throws WxErrorException { String response = get(API_UNDO_CODE_AUDIT, null); diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/ma/WxOpenMaHistoryVersion.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/ma/WxOpenMaHistoryVersion.java new file mode 100644 index 0000000000..6ef41c8bef --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/ma/WxOpenMaHistoryVersion.java @@ -0,0 +1,34 @@ +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 广州跨界 + */ +@Data +public class WxOpenMaHistoryVersion implements Serializable { + private static final long serialVersionUID = 98923601148793365L; + + @SerializedName("app_version") + private Integer appVersion; + + @SerializedName("user_version") + private String userVersion; + + @SerializedName("user_desc") + private String userDesc; + + @SerializedName("commit_time") + private Integer commitTime; + + @Override + public String toString() { + return WxOpenGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaHistoryVersionResult.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaHistoryVersionResult.java new file mode 100644 index 0000000000..61b9f5dddf --- /dev/null +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/result/WxOpenMaHistoryVersionResult.java @@ -0,0 +1,29 @@ +package me.chanjar.weixin.open.bean.result; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.open.bean.ma.WxOpenMaHistoryVersion; +import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder; + +import java.util.List; + +/** + * 微信开放平台小程序 可回退的小程序版本 返回 + * + * @author 广州跨界 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxOpenMaHistoryVersionResult extends WxOpenResult { + private static final long serialVersionUID = 4102311851687901079L; + + @SerializedName("template_list") + List templateList; + + @Override + public String toString() { + return WxOpenGsonBuilder.create().toJson(this); + } + +}