From a12fa556012d18eceb94a749abcb047b1305ccdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=8D=E8=B2=93?= <1219974319@qq.com> Date: Tue, 28 Jun 2022 11:21:23 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2718=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E8=AE=B8=E5=8F=AF=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/bean/license/WxCpTpLicenseAccount.java | 32 ++ .../license/WxCpTpLicenseAccountCount.java | 31 ++ .../license/WxCpTpLicenseAccountDuration.java | 24 + .../license/WxCpTpLicenseActiveAccount.java | 39 ++ .../license/WxCpTpLicenseActiveCodeInfo.java | 39 ++ .../license/WxCpTpLicenseBaseAccount.java | 38 ++ .../license/WxCpTpLicenseCorpAccount.java | 30 ++ .../license/WxCpTpLicenseInvalidAccount.java | 28 ++ .../cp/bean/license/WxCpTpLicenseOrder.java | 52 ++ .../license/WxCpTpLicenseSimpleOrder.java | 33 ++ .../bean/license/WxCpTpLicenseTransfer.java | 46 ++ .../WxCpTpLicenseActiveInfoByUserResp.java | 35 ++ .../WxCpTpLicenseBatchActiveResultResp.java | 34 ++ .../WxCpTpLicenseBatchCodeInfoResp.java | 34 ++ .../WxCpTpLicenseBatchTransferResp.java | 32 ++ .../account/WxCpTpLicenseCodeInfoResp.java | 29 ++ .../WxCpTpLicenseCorpAccountListResp.java | 37 ++ .../order/WxCpTpLicenseCreateOrderResp.java | 31 ++ .../order/WxCpTpLicenseNewOrderRequest.java | 60 +++ .../WxCpTpLicenseOrderAccountListResp.java | 39 ++ .../order/WxCpTpLicenseOrderInfoResp.java | 30 ++ .../order/WxCpTpLicenseOrderListResp.java | 39 ++ .../WxCpTpLicenseRenewOrderJobRequest.java | 49 ++ .../order/WxCpTpLicenseRenewOrderJobResp.java | 43 ++ .../order/WxCpTpLicenseRenewOrderRequest.java | 38 ++ .../weixin/cp/constant/WxCpApiPathConsts.java | 16 + .../weixin/cp/constant/WxCpTpConsts.java | 17 + .../cp/tp/service/WxCpTpLicenseService.java | 212 ++++++++ .../weixin/cp/tp/service/WxCpTpService.java | 15 + .../service/impl/BaseWxCpTpServiceImpl.java | 13 + .../impl/WxCpTpLicenseServiceImpl.java | 193 ++++++++ .../impl/WxCpTpLicenseServiceImplTest.java | 457 ++++++++++++++++++ 32 files changed, 1845 insertions(+) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccount.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountCount.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountDuration.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveAccount.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveCodeInfo.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseBaseAccount.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseCorpAccount.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseInvalidAccount.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseOrder.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseSimpleOrder.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseTransfer.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseActiveInfoByUserResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchActiveResultResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchCodeInfoResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchTransferResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCodeInfoResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCorpAccountListResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseCreateOrderResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseNewOrderRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderAccountListResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderInfoResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderListResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobResp.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpLicenseService.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImpl.java create mode 100644 weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccount.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccount.java new file mode 100644 index 0000000000..41d5564ad4 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccount.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + + +/** + * 订单账号信息 + * @author Totoro + * @date 2022/6/27 14:04 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseAccount extends WxCpTpLicenseBaseAccount { + private static final long serialVersionUID = 8225061160406054730L; + + /** + * 激活码 + */ + @SerializedName("active_code") + private String activeCode; + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountCount.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountCount.java new file mode 100644 index 0000000000..ba16e4da90 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountCount.java @@ -0,0 +1,31 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * @author Totoro + * @date 2022/6/27 11:54 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseAccountCount implements Serializable { + private static final long serialVersionUID = 8521389670723004989L; + + @SerializedName("base_count") + private Integer baseCount; + @SerializedName("external_contact_count") + private Integer externalContactCount; + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountDuration.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountDuration.java new file mode 100644 index 0000000000..0da8c50d16 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseAccountDuration.java @@ -0,0 +1,24 @@ +package me.chanjar.weixin.cp.bean.license; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * + * @author Totoro + * @date 2022-6-27 11:22:53 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseAccountDuration implements Serializable { + private static final long serialVersionUID = 7960912263908286975L; + + private Integer months; + + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveAccount.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveAccount.java new file mode 100644 index 0000000000..d65e3473c3 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveAccount.java @@ -0,0 +1,39 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author Totoro + * @date 2022-6-27 16:26:35 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseActiveAccount implements Serializable { + private static final long serialVersionUID = -2382681430861137803L; + + /** + * 用户ID + */ + private String userid; + + /** + * 激活码 + */ + @SerializedName("active_code") + private String activeCode; + + /** + * 激活状态 0为成功 + * 此值在请求激活时无需传入 + */ + @SerializedName("errcode") + private Integer errCode; +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveCodeInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveCodeInfo.java new file mode 100644 index 0000000000..26e107ccf7 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseActiveCodeInfo.java @@ -0,0 +1,39 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +/** + * 激活码信息 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95553 + * @author Totoro + * @date 2022/6/27 14:34 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseActiveCodeInfo extends WxCpTpLicenseBaseAccount { + private static final long serialVersionUID = 7696395903786956694L; + + @SerializedName("active_code") + private String activeCode; + + private Integer status; + + @SerializedName("create_time") + private Long createTime; + + @SerializedName("active_time") + private Long activeTime; + + @SerializedName("expire_time") + private Long expireTime; + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseBaseAccount.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseBaseAccount.java new file mode 100644 index 0000000000..4d02f6d324 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseBaseAccount.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.cp.bean.license; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 许可证账号基础类 + * @author Totoro + * @date 2022/6/27 14:39 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseBaseAccount implements Serializable { + private static final long serialVersionUID = 7075253491688740047L; + + + /** + * 用户ID + */ + private String userid; + + /** + * 类型 + */ + private Integer type; + + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseCorpAccount.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseCorpAccount.java new file mode 100644 index 0000000000..246253bdd8 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseCorpAccount.java @@ -0,0 +1,30 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +/** + * @author Totoro + * @date 2022/6/27 15:21 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseCorpAccount extends WxCpTpLicenseBaseAccount { + + private static final long serialVersionUID = -5856054486686123753L; + + @SerializedName("active_time") + private Long activeTime; + + @SerializedName("expire_time") + private Long expireTime; + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseInvalidAccount.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseInvalidAccount.java new file mode 100644 index 0000000000..3fba253bfd --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseInvalidAccount.java @@ -0,0 +1,28 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +/** + * @author Totoro + * @date 2022-6-27 15:35:30 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseInvalidAccount extends WxCpTpLicenseBaseAccount { + private static final long serialVersionUID = -3706481243147500720L; + + @SerializedName("errcode") + private Integer errorCode; + @SerializedName("errmsg") + private String errMsg; + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseOrder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseOrder.java new file mode 100644 index 0000000000..a7ac6186fd --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseOrder.java @@ -0,0 +1,52 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 详细的订单信息 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95648 + * @author Totoro + * @date 2022/6/27 11:38 + */ +@Data +public class WxCpTpLicenseOrder implements Serializable { + + private static final long serialVersionUID = -4094302825442292644L; + + @SerializedName("order_id") + private String orderId; + + @SerializedName("order_type") + private Integer orderType; + + @SerializedName("order_status") + private Integer orderStatus; + + @SerializedName("corpid") + private String corpId; + + @SerializedName("price") + private Long price; + + @SerializedName("account_count") + private WxCpTpLicenseAccountCount accountCount; + + @SerializedName("account_duration") + private WxCpTpLicenseAccountDuration accountDuration; + + @SerializedName("create_time") + private Long createTime; + + @SerializedName("pay_time") + private Long payTime; + + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseSimpleOrder.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseSimpleOrder.java new file mode 100644 index 0000000000..54e1f0c01f --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseSimpleOrder.java @@ -0,0 +1,33 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * @author Totoro + * @date 2022/6/27 11:38 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseSimpleOrder implements Serializable { + + private static final long serialVersionUID = -4094302825442292644L; + + @SerializedName("order_id") + private String orderId; + @SerializedName("order_type") + private Integer orderType; + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseTransfer.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseTransfer.java new file mode 100644 index 0000000000..f50c3cb5f6 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/WxCpTpLicenseTransfer.java @@ -0,0 +1,46 @@ +package me.chanjar.weixin.cp.bean.license; + +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 基础的信息 + * @author Totoro + * @date 2022/6/27 15:50 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseTransfer implements Serializable { + private static final long serialVersionUID = -5194757640985570778L; + + + /** + * 转移成员加密的userid + */ + @SerializedName("handover_userid") + private String handoverUserId; + + /** + * 接收成员加密的userid + */ + @SerializedName("takeover_userid") + private String takeoverUserId; + + /** + * 基础成功标识符,在请求继承的时候无需传入该参数,参数为企业微信返回 + * 0为成功 + */ + @SerializedName("errcode") + private Integer errCode; + + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseActiveInfoByUserResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseActiveInfoByUserResp.java new file mode 100644 index 0000000000..c9e42650d3 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseActiveInfoByUserResp.java @@ -0,0 +1,35 @@ +package me.chanjar.weixin.cp.bean.license.account; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseActiveCodeInfo; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 某个企业成员的激活情况 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95555 + * @author Totoro + * @date 2022-6-27 14:51:19 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseActiveInfoByUserResp extends WxCpBaseResp { + private static final long serialVersionUID = -5172901191911873330L; + + + @SerializedName("active_status") + private Integer activeStatus; + + @SerializedName("active_info_list") + private List activeInfoList; + + + public static WxCpTpLicenseActiveInfoByUserResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseActiveInfoByUserResp.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchActiveResultResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchActiveResultResp.java new file mode 100644 index 0000000000..4f394af621 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchActiveResultResp.java @@ -0,0 +1,34 @@ +package me.chanjar.weixin.cp.bean.license.account; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseActiveAccount; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 批量激活帐号结果 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95553 + * @author Totoro + * @date 2022-6-27 16:19:21 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseBatchActiveResultResp extends WxCpBaseResp { + + private static final long serialVersionUID = 8799524570217687659L; + + @SerializedName("active_result") + private List activeResults; + + + + + public static WxCpTpLicenseBatchActiveResultResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseBatchActiveResultResp.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchCodeInfoResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchCodeInfoResp.java new file mode 100644 index 0000000000..08a12d1785 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchCodeInfoResp.java @@ -0,0 +1,34 @@ +package me.chanjar.weixin.cp.bean.license.account; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseActiveCodeInfo; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 批量查询的激活码详情 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95553 + * @author Totoro + * @date 2022-6-27 14:51:19 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseBatchCodeInfoResp extends WxCpBaseResp { + private static final long serialVersionUID = 1327038464020790843L; + + @SerializedName("active_info_list") + private List activeCodeInfoList; + + @SerializedName("invalid_active_code_list") + private List invalidActiveCodeList; + + + public static WxCpTpLicenseBatchCodeInfoResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseBatchCodeInfoResp.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchTransferResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchTransferResp.java new file mode 100644 index 0000000000..737f891e47 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseBatchTransferResp.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.cp.bean.license.account; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseTransfer; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 基础结果返回信息 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95673 + * @author Totoro + * @date 2022/6/27 15:49 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseBatchTransferResp extends WxCpBaseResp { + private static final long serialVersionUID = 5443977430756597486L; + + @SerializedName("transfer_result") + private List transferResult; + + public static WxCpTpLicenseBatchTransferResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseBatchTransferResp.class); + } + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCodeInfoResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCodeInfoResp.java new file mode 100644 index 0000000000..9c1c72402d --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCodeInfoResp.java @@ -0,0 +1,29 @@ +package me.chanjar.weixin.cp.bean.license.account; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseActiveCodeInfo; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +/** + * 查询的激活码详情 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95553 + * @author Totoro + * @date 2022/6/27 14:28 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseCodeInfoResp extends WxCpBaseResp { + private static final long serialVersionUID = 8058798194938243361L; + + @SerializedName("active_info") + private WxCpTpLicenseActiveCodeInfo activeCodeInfo; + + + public static WxCpTpLicenseCodeInfoResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseCodeInfoResp.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCorpAccountListResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCorpAccountListResp.java new file mode 100644 index 0000000000..623a8e1945 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/account/WxCpTpLicenseCorpAccountListResp.java @@ -0,0 +1,37 @@ +package me.chanjar.weixin.cp.bean.license.account; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseCorpAccount; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 企业的帐号列表(已激活) + * 文档地址:https://developer.work.weixin.qq.com/document/path/95544 + * @author Totoro + * @date 2022/6/27 15:15 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseCorpAccountListResp extends WxCpBaseResp { + private static final long serialVersionUID = -7976008813041959375L; + + @SerializedName("next_cursor") + private String nextCursor; + + @SerializedName("has_more") + private Integer hasMore; + + @SerializedName("account_list") + private List orderList; + + + public static WxCpTpLicenseCorpAccountListResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseCorpAccountListResp.class); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseCreateOrderResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseCreateOrderResp.java new file mode 100644 index 0000000000..d5d0d14e0c --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseCreateOrderResp.java @@ -0,0 +1,31 @@ +package me.chanjar.weixin.cp.bean.license.order; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +/** + * 订单创建结果 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95644 + * @author Totoro + * @date 2022-6-27 11:26:36 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseCreateOrderResp extends WxCpBaseResp { + private static final long serialVersionUID = 6644560301282598903L; + + @SerializedName("order_id") + private String orderId; + + + public static WxCpTpLicenseCreateOrderResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseCreateOrderResp.class); + } + + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseNewOrderRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseNewOrderRequest.java new file mode 100644 index 0000000000..447fefd105 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseNewOrderRequest.java @@ -0,0 +1,60 @@ +package me.chanjar.weixin.cp.bean.license.order; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseAccountCount; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseAccountDuration; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 下单购买帐号 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95644 + * @author Totoro + * @date 2022/6/27 10:52 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseNewOrderRequest implements Serializable { + private static final long serialVersionUID = 6644560301282598903L; + + /** + * 企业ID + */ + @SerializedName("corpid") + private String corpId; + + /** + * 购买者ID + */ + @SerializedName("buyer_userid") + private String buyerUserId; + + /** + * 账号个数 + */ + @SerializedName("account_count") + private WxCpTpLicenseAccountCount accountCount; + + /** + * 购买市场 + */ + @SerializedName("account_duration") + private WxCpTpLicenseAccountDuration accountDuration; + + + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderAccountListResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderAccountListResp.java new file mode 100644 index 0000000000..bab3aeab47 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderAccountListResp.java @@ -0,0 +1,39 @@ +package me.chanjar.weixin.cp.bean.license.order; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseAccount; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 获取订单中的帐号列表 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95649 + * @author Totoro + * @date 2022-6-27 14:14:40 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxCpTpLicenseOrderAccountListResp extends WxCpBaseResp { + private static final long serialVersionUID = 470154227651487230L; + + @SerializedName("next_cursor") + private String nextCursor; + + @SerializedName("has_more") + private Integer hasMore; + + @SerializedName("account_list") + private List accountList; + + + public static WxCpTpLicenseOrderAccountListResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseOrderAccountListResp.class); + } + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderInfoResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderInfoResp.java new file mode 100644 index 0000000000..2d570896f0 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderInfoResp.java @@ -0,0 +1,30 @@ +package me.chanjar.weixin.cp.bean.license.order; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseOrder; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +/** + * 订单详情结果 + * 文档:https://developer.work.weixin.qq.com/document/path/95648 + * @author Totoro + * @date 2022/06/27 11:56:03 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseOrderInfoResp extends WxCpBaseResp { + + private static final long serialVersionUID = 7000171280773370910L; + + private WxCpTpLicenseOrder order; + + + public static WxCpTpLicenseOrderInfoResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseOrderInfoResp.class); + } + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderListResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderListResp.java new file mode 100644 index 0000000000..51dc7d8da1 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseOrderListResp.java @@ -0,0 +1,39 @@ +package me.chanjar.weixin.cp.bean.license.order; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseSimpleOrder; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 获取订单列表详情 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95647 + * @author Totoro + * @date 2022/6/27 11:39 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class WxCpTpLicenseOrderListResp extends WxCpBaseResp { + private static final long serialVersionUID = 1878909432164961275L; + + @SerializedName("next_cursor") + private String nextCursor; + + @SerializedName("has_more") + private Integer hasMore; + + @SerializedName("order_list") + private List orderList; + + + public static WxCpTpLicenseOrderListResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseOrderListResp.class); + } + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobRequest.java new file mode 100644 index 0000000000..c50c35f772 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobRequest.java @@ -0,0 +1,49 @@ +package me.chanjar.weixin.cp.bean.license.order; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseBaseAccount; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 创建下单续期帐号任务 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95646 + * @author Totoro + * @date 2022/6/27 11:12 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseRenewOrderJobRequest implements Serializable { + + private static final long serialVersionUID = 8074896339359557034L; + /** + * 对应的企业ID + */ + @SerializedName("corpid") + private String corpId; + /** + * 续费的用户UserId + */ + @SerializedName("account_list") + private List accountList; + /** + * 任务id,若不传则默认创建一个新任务。若指定第一次调用后拿到jobid,可以通过该接口将jobid关联多个userid + */ + @SerializedName("jobid") + private String jobId; + + + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobResp.java new file mode 100644 index 0000000000..4ec63ec46e --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderJobResp.java @@ -0,0 +1,43 @@ +package me.chanjar.weixin.cp.bean.license.order; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseInvalidAccount; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.util.List; + +/** + * 创建下单购买帐号任务返回结果 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95646 + * @author Totoro + * @date 2022-6-27 11:15:20 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class WxCpTpLicenseRenewOrderJobResp extends WxCpBaseResp { + + private static final long serialVersionUID = -4469875729545594102L; + /** + * 任务ID + */ + @SerializedName("jobid") + private String jobId; + /** + * 有效的续费账号列表 + */ + @SerializedName("invalid_account_list") + private List invalidAccountList; + + + + public static WxCpTpLicenseRenewOrderJobResp fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpTpLicenseRenewOrderJobResp.class); + } + + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderRequest.java new file mode 100644 index 0000000000..a4607f5689 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/license/order/WxCpTpLicenseRenewOrderRequest.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.cp.bean.license.order; +import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseAccountDuration; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 续期帐号订单 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95646 + * @author Totoro + * @date 2022-6-27 11:21:51 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WxCpTpLicenseRenewOrderRequest implements Serializable { + private static final long serialVersionUID = 8709132346969663049L; + + @SerializedName("buyer_userid") + private String buyerUserId; + @SerializedName("jobid") + private String jobId; + @SerializedName("account_duration") + private WxCpTpLicenseAccountDuration accountDuration; + + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + +} 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 2215e1096a..26f9edaf31 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 @@ -271,6 +271,22 @@ interface Tp { } + interface License { + String CREATE_NEW_ORDER = "/cgi-bin/license/create_new_order"; + String CREATE_RENEW_ORDER_JOB = "/cgi-bin/license/create_renew_order_job"; + String SUBMIT_ORDER_JOB = "/cgi-bin/license/submit_order_job"; + String LIST_ORDER = "/cgi-bin/license/list_order"; + String GET_ORDER = "/cgi-bin/license/get_order"; + String LIST_ORDER_ACCOUNT = "/cgi-bin/license/list_order_account"; + String ACTIVE_ACCOUNT = "/cgi-bin/license/active_account"; + String BATCH_ACTIVE_ACCOUNT = "/cgi-bin/license/batch_active_account"; + String GET_ACTIVE_INFO_BY_CODE = "/cgi-bin/license/get_active_info_by_code"; + String BATCH_GET_ACTIVE_INFO_BY_CODE = "/cgi-bin/license/batch_get_active_info_by_code"; + String LIST_ACTIVED_ACCOUNT = "/cgi-bin/license/list_actived_account"; + String GET_ACTIVE_INFO_BY_USER = "/cgi-bin/license/get_active_info_by_user"; + String BATCH_TRANSFER_LICENSE = "/cgi-bin/license/batch_transfer_license"; + } + interface User { String USER_AUTHENTICATE = "/cgi-bin/user/authsucc?userid="; String USER_CREATE = "/cgi-bin/user/create"; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpTpConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpTpConsts.java index aed02d92f0..e050c21155 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpTpConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpTpConsts.java @@ -72,6 +72,23 @@ public static class InfoType { */ public static final String CHANGE_EDITION = "change_editon"; + + /** + * 接口许可失效通知 + */ + public static final String UNLICENSED_NOTIFY = "unlicensed_notify"; + + /** + * 支付成功通知 + */ + public static final String LICENSE_PAY_SUCCESS = "license_pay_success"; + + /** + * 退款结果通知 + */ + public static final String LICENSE_REFUND = "license_refund"; + + } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpLicenseService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpLicenseService.java new file mode 100644 index 0000000000..8f25e5e5e8 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpLicenseService.java @@ -0,0 +1,212 @@ +package me.chanjar.weixin.cp.tp.service; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseActiveAccount; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseTransfer; +import me.chanjar.weixin.cp.bean.license.account.*; +import me.chanjar.weixin.cp.bean.license.order.*; + +import java.util.Collection; +import java.util.Date; +import java.util.List; + +/** + *
+ * 服务商接口调用许可相关接口
+ * 文档地址:https://developer.work.weixin.qq.com/document/path/95652
+ * 
+ * @author Totoro + * @date 2022/6/27 10:57 + */ +public interface WxCpTpLicenseService { + + + /** + * 下单购买帐号 + * 服务商下单为企业购买新的帐号,可以同时购买基础帐号与互通帐号。 + * 下单之后,需要到服务商管理端发起支付,支付完成之后,订单才能生效。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95644 + * @param licenseNewOrderRequest 订单信息 + * @return 订单ID + * @throws WxErrorException; + */ + WxCpTpLicenseCreateOrderResp createNewOrder(WxCpTpLicenseNewOrderRequest licenseNewOrderRequest) throws WxErrorException; + + + /** + * 创建下单续期帐号任务 + *
+   *  可以下单为一批已激活帐号的成员续期,续期下单分为两个步骤:
+   * 传入userid列表创建一个任务,创建之后,可以往同一个任务继续追加待续期的userid列表;
+   * 根据步骤1得到的jobid提交订单。
+   * 
+ * @param licenseRenewOrderJobRequest 续费订单信息 + * @return 返回JobId + * @throws WxErrorException; + */ + WxCpTpLicenseRenewOrderJobResp createRenewOrderJob(WxCpTpLicenseRenewOrderJobRequest licenseRenewOrderJobRequest) throws WxErrorException; + + + + /** + * 提交续期订单 + * 创建续期任务之后,需要调用该接口,以提交订单任务。 + * 注意,提交之后,需要到服务商管理端发起支付,支付完成之后,订单才能生效。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95646 + * @param licenseRenewOrderRequest 订单信息 + * @return 订单ID + * @throws WxErrorException; + */ + WxCpTpLicenseCreateOrderResp submitRenewOrder(WxCpTpLicenseRenewOrderRequest licenseRenewOrderRequest) throws WxErrorException; + + + /** + * 获取订单列表 + * 服务商查询自己某段时间内的平台能力服务订单列表 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95647 + * @param corpId 企业ID + * @param startTime 开始时间,下单时间。可不填。但是不能单独指定该字段,start_time跟end_time必须同时指定。 + * @param endTime 结束时间,下单时间。起始时间跟结束时间不能超过31天。可不填。但是不能单独指定该字段,start_time跟end_time必须同时指定。 + * @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填 + * @param limit 返回的最大记录数,整型,最大值1000,默认值500 + * @return 订单列表 + * @throws WxErrorException; + */ + WxCpTpLicenseOrderListResp getOrderList(String corpId, Date startTime, Date endTime, String cursor, int limit) throws WxErrorException; + + + /** + * 获取订单详情 + * 查询某个订单的详情,包括订单的状态、基础帐号个数、互通帐号个数、帐号购买时长等。 + * 注意,该接口不返回订单中的帐号激活码列表或者续期的帐号成员列表,请调用获取订单中的帐号列表接口以获取帐号列表。 + * @param orderId 订单ID + * @return 单条订单信息 + * @throws WxErrorException; + */ + WxCpTpLicenseOrderInfoResp getOrderInfo(String orderId) throws WxErrorException; + + + /** + * 查询指定订单下的平台能力服务帐号列表。 + * 若为购买帐号的订单或者存量企业的版本付费迁移订单,则返回帐号激活码列表; + * 若为续期帐号的订单,则返回续期帐号的成员列表。注意,若是购买帐号的订单, + * 则仅订单支付完成时,系统才会生成帐号,故支付完成之前,该接口不会返回帐号激活码。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95649 + * @param orderId 订单ID + * @param limit 大小 + * @param cursor 分页游标 + * @return 订单账号列表 + * @throws WxErrorException; + */ + WxCpTpLicenseOrderAccountListResp getOrderAccountList(String orderId, int limit, String cursor) throws WxErrorException; + + + /** + * 激活帐号 + * 下单购买帐号并支付完成之后,先调用获取订单中的帐号列表接口获取到帐号激活码, + * 然后可以调用该接口将激活码绑定到某个企业员工,以对其激活相应的平台服务能力。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95553 + * @param code 激活码 + * @param corpId 企业ID + * @param userId 用户ID + * @return 激活结果 + * @throws WxErrorException; + */ + WxCpBaseResp activeCode(String code, String corpId, String userId) throws WxErrorException; + + + /** + * 批量激活帐号 + * 可在一次请求里为一个企业的多个成员激活许可帐号,便于服务商批量化处理。 + * 一个userid允许激活一个基础帐号以及一个互通帐号。 + * 单次激活的员工数量不超过1000 + * @param corpId 企业ID + * @param activeAccountList 激活列表 + * @return 激活结果 + * @throws WxErrorException; + */ + WxCpTpLicenseBatchActiveResultResp batchActiveCode(String corpId, List activeAccountList) throws WxErrorException; + + + /** + * 获取激活码详情 + * 查询某个帐号激活码的状态以及激活绑定情况。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95552 + * @param code 激活码 + * @param corpId 企业ID + * @return 激活码信息 + * @throws WxErrorException; + */ + WxCpTpLicenseCodeInfoResp getActiveInfoByCode(String code, String corpId) throws WxErrorException; + + + /** + * 获取激活码详情 + * 查询某个帐号激活码的状态以及激活绑定情况。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95552 + * @param codes 激活码 + * @param corpId 企业ID + * @return 激活码信息 + * @throws WxErrorException; + */ + WxCpTpLicenseBatchCodeInfoResp batchGetActiveInfoByCode(Collection codes, String corpId) throws WxErrorException; + + + /** + * 获取企业的帐号列表 + * 查询指定企业下的平台能力服务帐号列表。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95544 + * @param corpId 企业ID + * @param limit 大小 + * @param cursor 游标 + * @return 已激活列表 + * @throws WxErrorException + */ + WxCpTpLicenseCorpAccountListResp getCorpAccountList(String corpId, int limit, String cursor) throws WxErrorException; + + + /** + * 获取成员的激活详情 + * 查询某个企业成员的激活情况。 + * 文档地址:https://developer.work.weixin.qq.com/document/path/95555 + * @param corpId 企业ID + * @param userId 用户ID + * @return 激活情况 + * @throws WxErrorException; + */ + WxCpTpLicenseActiveInfoByUserResp getActiveInfoByUser(String corpId, String userId) throws WxErrorException; + + + /** + * 帐号继承 + * 在企业员工离职或者工作范围的有变更时,允许将其许可帐号继承给其他员工。 + * @param corpId 企业ID + * @param transferList 转移列表 + * @return 转移结果 + * @throws WxErrorException; + */ + WxCpTpLicenseBatchTransferResp batchTransferLicense(String corpId, List transferList) throws WxErrorException; + + + + + + + + + + + + + + + + + + + + + + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java index 37405b2e92..8c7615d8d5 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java @@ -474,6 +474,21 @@ public interface WxCpTpService { */ void setWxCpTpUserService(WxCpTpUserService wxCpTpUserService); + /** + * set license service + * + * @param wxCpTpLicenseService the oa service + */ + void setWxCpTpLicenseService(WxCpTpLicenseService wxCpTpLicenseService); + + + /** + * get license service + * + * @return getCpTPLicenseService wx cp tp license service + */ + WxCpTpLicenseService getWxCpTpLicenseService(); + /** * 获取应用的管理员列表 * diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java index a4dbd12480..768164096f 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java @@ -50,6 +50,7 @@ public abstract class BaseWxCpTpServiceImpl implements WxCpTpService, Requ private WxCpTpUserService wxCpTpUserService = new WxCpTpUserServiceImpl(this); private WxCpTpOrderService wxCpTpOrderService = new WxCpTpOrderServiceImpl(this); private WxCpTpEditionService wxCpTpEditionService = new WxCpTpEditionServiceImpl(this); + private WxCpTpLicenseService wxCpTpLicenseService = new WxCpTpLicenseServiceImpl(this); /** * 全局的是否正在刷新access token的锁. @@ -547,6 +548,18 @@ public void setWxCpTpOAService(WxCpTpOAService wxCpTpOAService) { this.wxCpTpOAService = wxCpTpOAService; } + + @Override + public WxCpTpLicenseService getWxCpTpLicenseService() { + return wxCpTpLicenseService; + } + + + @Override + public void setWxCpTpLicenseService(WxCpTpLicenseService wxCpTpLicenseService) { + this.wxCpTpLicenseService = wxCpTpLicenseService; + } + @Override public void setWxCpTpUserService(WxCpTpUserService wxCpTpUserService) { this.wxCpTpUserService = wxCpTpUserService; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImpl.java new file mode 100644 index 0000000000..ea4d3d9c8a --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImpl.java @@ -0,0 +1,193 @@ +package me.chanjar.weixin.cp.tp.service.impl; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import lombok.RequiredArgsConstructor; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseActiveAccount; +import me.chanjar.weixin.cp.bean.license.WxCpTpLicenseTransfer; +import me.chanjar.weixin.cp.bean.license.account.*; +import me.chanjar.weixin.cp.bean.license.order.*; +import me.chanjar.weixin.cp.config.WxCpTpConfigStorage; +import me.chanjar.weixin.cp.tp.service.WxCpTpLicenseService; +import me.chanjar.weixin.cp.tp.service.WxCpTpService; + +import java.util.*; + +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.License.*; + +/** + * @author Totoro + * @date 2022/6/27 11:03 + */ +@RequiredArgsConstructor +public class WxCpTpLicenseServiceImpl implements WxCpTpLicenseService { + + private final WxCpTpService mainService; + + @Override + public WxCpTpLicenseCreateOrderResp createNewOrder(WxCpTpLicenseNewOrderRequest licenseNewOrderRequest) throws WxErrorException { + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(CREATE_NEW_ORDER) + + getProviderAccessToken(), licenseNewOrderRequest.toJson()); + return WxCpTpLicenseCreateOrderResp.fromJson(resultText); + } + + + @Override + public WxCpTpLicenseRenewOrderJobResp createRenewOrderJob(WxCpTpLicenseRenewOrderJobRequest licenseRenewOrderJobRequest) throws WxErrorException { + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(CREATE_RENEW_ORDER_JOB) + + getProviderAccessToken(), licenseRenewOrderJobRequest.toJson()); + return WxCpTpLicenseRenewOrderJobResp.fromJson(resultText); + } + + + @Override + public WxCpTpLicenseCreateOrderResp submitRenewOrder(WxCpTpLicenseRenewOrderRequest licenseRenewOrderRequest) throws WxErrorException { + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(SUBMIT_ORDER_JOB) + + getProviderAccessToken(), licenseRenewOrderRequest.toJson()); + return WxCpTpLicenseCreateOrderResp.fromJson(resultText); + } + + + @Override + public WxCpTpLicenseOrderListResp getOrderList(String corpId, Date startTime, Date endTime, String cursor, int limit) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("corpid", corpId); + jsonObject.addProperty("cursor", cursor); + jsonObject.addProperty("limit", limit); + if(startTime != null) { + jsonObject.addProperty("start_time", startTime.getTime() / 1000); + } + if(endTime != null) { + jsonObject.addProperty("end_time", endTime.getTime() / 1000); + } + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(LIST_ORDER) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseOrderListResp.fromJson(resultText); + } + + + @Override + public WxCpTpLicenseOrderInfoResp getOrderInfo(String orderId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("order_id", orderId); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(GET_ORDER) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseOrderInfoResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseOrderAccountListResp getOrderAccountList(String orderId, int limit, String cursor) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("order_id", orderId); + jsonObject.addProperty("cursor", cursor); + jsonObject.addProperty("limit", limit); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(LIST_ORDER_ACCOUNT) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseOrderAccountListResp.fromJson(resultText); + } + + @Override + public WxCpBaseResp activeCode(String code, String corpId, String userId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("active_code", code); + jsonObject.addProperty("corpid", corpId); + jsonObject.addProperty("userid", userId); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(ACTIVE_ACCOUNT) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpBaseResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseBatchActiveResultResp batchActiveCode(String corpId, List activeAccountList) throws WxErrorException { + Map map = new HashMap<>(2); + map.put("corpid", corpId); + map.put("active_list", activeAccountList); + GsonBuilder gsonBuilder = new GsonBuilder(); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(BATCH_ACTIVE_ACCOUNT) + + getProviderAccessToken(), gsonBuilder.create().toJson(map)); + return WxCpTpLicenseBatchActiveResultResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseCodeInfoResp getActiveInfoByCode(String code, String corpId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("active_code", code); + jsonObject.addProperty("corpid", corpId); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(GET_ACTIVE_INFO_BY_CODE) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseCodeInfoResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseBatchCodeInfoResp batchGetActiveInfoByCode(Collection codes, String corpId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + JsonArray list = new JsonArray(); + for (String code : codes) { + list.add(new JsonPrimitive(code)); + } + jsonObject.add("active_code_list", list); + jsonObject.addProperty("corpid", corpId); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(BATCH_GET_ACTIVE_INFO_BY_CODE) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseBatchCodeInfoResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseCorpAccountListResp getCorpAccountList(String corpId, int limit, String cursor) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("corpid", corpId); + jsonObject.addProperty("cursor", cursor); + jsonObject.addProperty("limit", limit); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(LIST_ACTIVED_ACCOUNT) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseCorpAccountListResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseActiveInfoByUserResp getActiveInfoByUser(String corpId, String userId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("corpid", corpId); + jsonObject.addProperty("userid", userId); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(GET_ACTIVE_INFO_BY_USER) + + getProviderAccessToken(), jsonObject.toString()); + return WxCpTpLicenseActiveInfoByUserResp.fromJson(resultText); + } + + @Override + public WxCpTpLicenseBatchTransferResp batchTransferLicense(String corpId, List transferList) throws WxErrorException { + Map map = new HashMap<>(2); + map.put("corpid", corpId); + map.put("transfer_list", transferList); + GsonBuilder gsonBuilder = new GsonBuilder(); + String resultText = mainService.post(getWxCpTpConfigStorage().getApiUrl(BATCH_TRANSFER_LICENSE) + + getProviderAccessToken(), gsonBuilder.create().toJson(map)); + return WxCpTpLicenseBatchTransferResp.fromJson(resultText); + } + + + /** + * 获取服务商token的拼接参数 + * @return url + * @throws WxErrorException / + */ + private String getProviderAccessToken() throws WxErrorException { + return "?provider_access_token=" + mainService.getWxCpProviderToken(); + } + + + /** + * 获取tp参数配置 + * @return config + */ + private WxCpTpConfigStorage getWxCpTpConfigStorage() { + return mainService.getWxCpTpConfigStorage(); + } + + + + +} diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java new file mode 100644 index 0000000000..00772ad6bb --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java @@ -0,0 +1,457 @@ +package me.chanjar.weixin.cp.tp.service.impl; + +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.license.*; +import me.chanjar.weixin.cp.bean.license.account.*; +import me.chanjar.weixin.cp.bean.license.order.*; +import me.chanjar.weixin.cp.config.WxCpTpConfigStorage; +import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; +import me.chanjar.weixin.cp.tp.service.WxCpTpLicenseService; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.*; + +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.License.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * 许可证账号服务测试 + * @author Totoro + * @date 2022/6/27 16:34 + */ +public class WxCpTpLicenseServiceImplTest { + + @Mock + private WxCpTpServiceApacheHttpClientImpl wxCpTpService; + + private WxCpTpConfigStorage configStorage; + + private WxCpTpLicenseService wxCpTpLicenseService; + + @BeforeClass + public void setUp() { + MockitoAnnotations.initMocks(this); + configStorage = new WxCpTpDefaultConfigImpl(); + when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); + wxCpTpLicenseService = new WxCpTpLicenseServiceImpl(wxCpTpService); + } + + + @Test + public void testCrateNewOrder() throws WxErrorException { + String orderId = "OASFNAISFASFA252462"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"order_id\": \"OASFNAISFASFA252462\"\n" + + "}"; + String url = configStorage.getApiUrl(CREATE_NEW_ORDER) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseNewOrderRequest orderRequest = WxCpTpLicenseNewOrderRequest.builder() + .accountCount(WxCpTpLicenseAccountCount.builder().baseCount(5).externalContactCount(6).build()) + .buyerUserId("test") + .corpId("test") + .accountDuration(WxCpTpLicenseAccountDuration.builder().months(5).build()) + .build(); + final WxCpTpLicenseCreateOrderResp newOrder = wxCpTpLicenseService.createNewOrder(orderRequest); + assertNotNull(newOrder); + assertEquals(newOrder.getOrderId(), orderId); + } + + + @Test + public void testCreateRenewOrderJob() throws WxErrorException { + String jobId = "test123456"; + String result = "{\n" + + " \"errcode\":0,\n" + + " \"errmsg\":\"ok\",\n" + + " \"jobid\":\"test123456\",\n" + + " \"invalid_account_list\":[\n" + + " {\n" + + " \"errcode\":1,\n" + + " \"errmsg\":\"error\",\n" + + " \"userid\":\"userid1\",\n" + + " \"type\":1\n" + + " },\n" + + " {\n" + + " \"errcode\":0,\n" + + " \"errmsg\":\"ok\",\n" + + " \"userid\":\"userid2\",\n" + + " \"type\":1\n" + + " }\n" + + " ]\n" + + "}"; + String url = configStorage.getApiUrl(CREATE_RENEW_ORDER_JOB) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + List accountList = new ArrayList<>(); + accountList.add(WxCpTpLicenseBaseAccount.builder().type(1).userid("userid1").build()); + accountList.add(WxCpTpLicenseBaseAccount.builder().type(1).userid("userid2").build()); + WxCpTpLicenseRenewOrderJobRequest orderJobRequest = WxCpTpLicenseRenewOrderJobRequest.builder() + .jobId("test123456") + .accountList(accountList).build(); + final WxCpTpLicenseRenewOrderJobResp renewOrderJob = wxCpTpLicenseService.createRenewOrderJob(orderJobRequest); + assertNotNull(renewOrderJob); + + assertEquals(renewOrderJob.getJobId(), jobId); + + assertEquals(renewOrderJob.getInvalidAccountList().size(), accountList.size()); + } + + @Test + public void testSubmitRenewOrderJob() throws WxErrorException { + String orderId = "test5915231"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"order_id\": \"test5915231\"\n" + + "}"; + String url = configStorage.getApiUrl(SUBMIT_ORDER_JOB) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseRenewOrderRequest renewOrderRequest = WxCpTpLicenseRenewOrderRequest.builder() + .jobId("test123456") + .accountDuration(WxCpTpLicenseAccountDuration.builder().months(5).build()) + .buyerUserId("test") + .build(); + WxCpTpLicenseCreateOrderResp createOrderResp = wxCpTpLicenseService.submitRenewOrder(renewOrderRequest); + assertNotNull(createOrderResp); + + assertEquals(createOrderResp.getOrderId(), orderId); + } + + @Test + public void testGetOrderList() throws WxErrorException { + String nextCursor = "DSGAKAFA4524"; + String orderId = "test123"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"next_cursor\":\"DSGAKAFA4524\",\n" + + "\t\"has_more\":1,\n" + + "\t\"order_list\":[\n" + + "\t\t{\n" + + "\t\t\t\"order_id\":\"test123\",\n" + + "\t\t\t\"order_type\":1\n" + + "\t\t}\n" + + "\t]\n" + + "}"; + + String url = configStorage.getApiUrl(LIST_ORDER) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseOrderListResp orderList = wxCpTpLicenseService.getOrderList("test", new Date(), new Date(), null, 10); + assertNotNull(orderList); + + assertEquals(orderList.getNextCursor(), nextCursor); + + assertEquals(orderList.getOrderList().get(0).getOrderId(), orderId); + + } + @Test + public void testGetOrder() throws WxErrorException { + String corpId = "ASFASF4254"; + String orderId = "FASASIFJ9W125234"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"order\":{\n" + + "\t\t\"order_id\":\"FASASIFJ9W125234\",\n" + + "\t\t\"order_type\":1,\n" + + "\t\t\"order_status\":1,\n" + + "\t\t\"corpid\":\"ASFASF4254\",\n" + + "\t\t\"price\":10000,\n" + + "\t\t\"account_count\":{\n" + + "\t \t \"base_count\":100,\n" + + " \t \"external_contact_count\":100\n" + + "\t },\n" + + "\t\t \"account_duration\":\n" + + " \t\t {\n" + + "\t \t \t\"months\":2\n" + + " \t \t \t},\n" + + "\t\t\"create_time\":150000000,\n" + + "\t \"pay_time\":1550000000\n" + + "\t}\n" + + "}"; + String url = configStorage.getApiUrl(GET_ORDER) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseOrderInfoResp orderInfo = wxCpTpLicenseService.getOrderInfo(orderId); + assertNotNull(orderInfo); + + assertNotNull(orderInfo.getOrder()); + + assertEquals(orderInfo.getOrder().getOrderId(), orderId); + + assertEquals(orderInfo.getOrder().getCorpId(), corpId); + + + } + + + @Test + public void testGetOrderAccount() throws WxErrorException { + String orderId = "ASFASF4254"; + String activeCode = "FASASIFJ9W125234"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"next_cursor\": \"ASFASF4254\",\n" + + "\t\"has_more\":1,\n" + + "\t\"account_list\":[\n" + + "\t\t{\n" + + "\t\t\t\"active_code\": \"FASASIFJ9W125234\",\n" + + "\t\t\t\"userid\":\"XXX\",\n" + + "\t\t\t\"type\": 1\n" + + "\t\t},\n" + + "\t\t{\n" + + "\t\t\t\"active_code\": \"code2\",\n" + + "\t\t\t\"userid\":\"XXX\",\n" + + "\t\t\t\"type\": 2\n" + + "\t\t}\n" + + "\t]\n" + + "}"; + + String url = configStorage.getApiUrl(LIST_ORDER_ACCOUNT) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseOrderAccountListResp orderAccountList = wxCpTpLicenseService.getOrderAccountList(orderId, 10, null); + assertNotNull(orderAccountList); + + assertNotNull(orderAccountList.getAccountList()); + + assertEquals(orderAccountList.getAccountList().get(0).getActiveCode(), activeCode); + + + } + + + @Test + public void testActiveAccount() throws WxErrorException { + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\"\n" + + "}"; + + String url = configStorage.getApiUrl(ACTIVE_ACCOUNT) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpBaseResp wxCpBaseResp = wxCpTpLicenseService.activeCode("123456", "123456", "123456"); + assertNotNull(wxCpBaseResp); + } + + @Test + public void testBatchActiveAccount() throws WxErrorException { + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"active_result\":[\n" + + "\t{\n" + + "\t\t\"active_code\" : \"aASFINAJOFASF\",\n" + + "\t\t\"userid\": \"SAGASGSD\",\n" + + "\t\t\"errcode\":0\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"active_code\" : \"ASDEGAFAd\",\n" + + "\t\t\"userid\": \"dsfafD\",\n" + + "\t\t\"errcode\":0\n" + + "\t}]\n" + + "}"; + String url = configStorage.getApiUrl(BATCH_ACTIVE_ACCOUNT) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + List accountList = new ArrayList<>(); + accountList.add(WxCpTpLicenseActiveAccount.builder().userid("SAGASGSD").activeCode("aASFINAJOFASF").build()); + accountList.add(WxCpTpLicenseActiveAccount.builder().userid("dsfafD").activeCode("ASDEGAFAd").build()); + WxCpTpLicenseBatchActiveResultResp wxCpTpLicenseBatchActiveResultResp = wxCpTpLicenseService.batchActiveCode("123456", accountList); + assertNotNull(wxCpTpLicenseBatchActiveResultResp); + + assertEquals(wxCpTpLicenseBatchActiveResultResp.getActiveResults().size(), accountList.size()); + + assertEquals(wxCpTpLicenseBatchActiveResultResp.getActiveResults().get(0).getActiveCode(), "aASFINAJOFASF"); + } + + + @Test + public void testGetActiveInfoByCode() throws WxErrorException { + String activeCode = "asgasfasfa"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"active_info\": {\n" + + "\t\t\"active_code\": \"asgasfasfa\",\n" + + "\t\t\"type\": 1,\n" + + "\t\t\"status\": 1,\n" + + "\t\t\"userid\": \"asfasgasg\",\n" + + "\t\t\"create_time\":1640966400,\n" + + "\t\t\"active_time\": 1640966400,\n" + + "\t\t\"expire_time\":1640966400\n" + + "\t}\n" + + "}"; + + String url = configStorage.getApiUrl(GET_ACTIVE_INFO_BY_CODE) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseCodeInfoResp activeInfoByCode = wxCpTpLicenseService.getActiveInfoByCode("123456", "safasg"); + assertNotNull(activeInfoByCode); + + assertEquals(activeInfoByCode.getActiveCodeInfo().getActiveCode(), activeCode); + + + } + + + @Test + public void testGetActiveInfoByUser() throws WxErrorException { + String activeCode = "asfaisfhiuaw"; + String userid = "asfasgasga"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"active_status\": 1,\n" + + "\t\"active_info_list\": \n" + + "\t[\n" + + "\t\t {\n" + + "\t\t\t\"active_code\": \"asfaisfhiuaw\",\n" + + "\t\t\t\"type\": 1,\n" + + "\t\t\t\"userid\": \"asfasgasga\",\n" + + "\t\t\t\"active_time\": 1640966400,\n" + + "\t\t\t\"expire_time\":1640966400\n" + + " \t \t },\n" + + " {\n" + + "\t\t\t\"active_code\": \"gasdawsd\",\n" + + "\t\t\t\"type\": 2,\n" + + "\t\t\t\"userid\": \"asdfasfasf\",\n" + + "\t\t\t\"active_time\":1640966400,\n" + + "\t\t\t\"expire_time\":1640966400\n" + + "\t\t }\n" + + " ]\n" + + "}"; + + String url = configStorage.getApiUrl(GET_ACTIVE_INFO_BY_USER) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseActiveInfoByUserResp activeInfoByUser = wxCpTpLicenseService.getActiveInfoByUser("123456", userid); + assertNotNull(activeInfoByUser); + + assertEquals(activeInfoByUser.getActiveStatus().intValue(), 1); + + assertEquals(activeInfoByUser.getActiveInfoList().get(0).getActiveCode(), activeCode); + } + + @Test + public void testBatchGetActiveInfoByUser() throws WxErrorException { + String activeCode = "asgasgasgas"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"active_info_list\": [\n" + + "\t\t{\n" + + "\t\t\t\"active_code\": \"asgasgasgas\",\n" + + "\t\t\t\"type\": 1,\n" + + "\t\t\t\"status\": 1,\n" + + "\t\t\t\"userid\": \"gadfFDF\",\n" + + "\t\t\t\"create_time\":1640966400,\n" + + "\t\t\t\"active_time\": 1640966400,\n" + + "\t\t\t\"expire_time\":1640966400\n" + + "\t\t},\n" + + "\t\t{\n" + + "\t\t\t\"active_code\": \"awsgdgasdasd\",\n" + + "\t\t\t\"type\": 2,\n" + + "\t\t\t\"status\": 1,\n" + + "\t\t\t\"userid\": \"SGASRDASGAQ\",\n" + + "\t\t\t\"create_time\":1640966400,\n" + + "\t\t\t\"active_time\": 1640966400,\n" + + "\t\t\t\"expire_time\":1640966400\n" + + "\t\t}\n" + + "\t],\n" + + "\t\"invalid_active_code_list\":[\"fasgasga\"]\n" + + "}"; + + + String url = configStorage.getApiUrl(BATCH_GET_ACTIVE_INFO_BY_CODE) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + Set codes = new HashSet<>(); + codes.add("asgasgasgas"); + codes.add("awsgdgasdasd"); + codes.add("fasgasga"); + WxCpTpLicenseBatchCodeInfoResp codeInfoResp = wxCpTpLicenseService.batchGetActiveInfoByCode(codes, "asfasfas"); + assertNotNull(codeInfoResp); + + assertEquals(codeInfoResp.getActiveCodeInfoList().size() , codes.size() - 1); + + assertNotNull(codeInfoResp.getInvalidActiveCodeList()); + + + } + + + @Test + public void testGetCorpAccountList() throws WxErrorException { + String nextCursor = "asfasdfas"; + String userid = "asdasdasd"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"next_cursor\":\"asfasdfas\",\n" + + "\t\"has_more\":1,\n" + + "\t\"account_list\":[\n" + + "\t\t{\n" + + "\t\t\t\"userid\": \"asdasdasd\",\n" + + "\t\t\t\"type\": 1,\n" + + "\t\t\t\"expire_time\":1500000000,\n" + + "\t\t\t\"active_time\":1500000000\n" + + "\t\t},\n" + + "\t\t{\n" + + "\t\t\t\"userid\": \"asgasgasdasd\",\n" + + "\t\t\t\"type\": 1,\n" + + "\t\t\t\"expire_time\":1500000000,\n" + + "\t\t\t\"active_time\":1500000000\n" + + "\t\t}\n" + + "\t]\n" + + "}"; + + String url = configStorage.getApiUrl(LIST_ACTIVED_ACCOUNT) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + WxCpTpLicenseCorpAccountListResp accountList = wxCpTpLicenseService.getCorpAccountList("123456", 10, null); + assertNotNull(accountList); + + assertNotNull(accountList.getOrderList()); + + assertEquals(accountList.getNextCursor(), nextCursor); + + assertEquals(accountList.getOrderList().get(0).getUserid(), userid); + } + + + @Test + public void testBatchTransferLicense() throws WxErrorException { + String handoverUserid = "dazdasfasf"; + String takeoverUserid = "asfasfasf"; + String result = "{\n" + + "\t\"errcode\": 0,\n" + + "\t\"errmsg\": \"ok\",\n" + + "\t\"transfer_result\":[\n" + + "\t{\n" + + "\t\t\"handover_userid\":\"dazdasfasf\",\n" + + "\t\t\"takeover_userid\":\"asfasfasf\",\n" + + "\t\t\"errcode\":0\n" + + "\t}]\n" + + "}"; + + String url = configStorage.getApiUrl(BATCH_TRANSFER_LICENSE) + "?provider_access_token=" + wxCpTpService.getWxCpProviderToken(); + when(wxCpTpService.post(eq(url), any(String.class))).thenReturn(result); + List transferList = new ArrayList<>(); + transferList.add(WxCpTpLicenseTransfer.builder().handoverUserId(handoverUserid).takeoverUserId(takeoverUserid).build()); + WxCpTpLicenseBatchTransferResp licenseBatchTransferResp = wxCpTpLicenseService.batchTransferLicense("123456", transferList); + assertNotNull(licenseBatchTransferResp); + + assertNotNull(licenseBatchTransferResp.getTransferResult()); + + assertEquals(licenseBatchTransferResp.getTransferResult().size(), transferList.size()); + + } + + + + +}