Skip to content

Commit 93779d2

Browse files
authored
:new :#2382 【企业微信】增加获取商品图册的接口
1 parent ef99e3d commit 93779d2

File tree

11 files changed

+298
-6
lines changed

11 files changed

+298
-6
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

+31-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public interface WxCpExternalContactService {
109109
* @param userId 外部联系人的userid
110110
* @return . external contact
111111
* @throws WxErrorException the wx error exception
112-
* @deprecated 建议使用 {@link #getContactDetail(String)}
112+
* @deprecated 建议使用 {@link #getContactDetail(String, String)}
113113
*/
114114
@Deprecated
115115
WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorException;
@@ -130,10 +130,11 @@ public interface WxCpExternalContactService {
130130
* </pre>
131131
*
132132
* @param userId 外部联系人的userid,注意不是企业成员的帐号
133+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
133134
* @return . contact detail
134135
* @throws WxErrorException .
135136
*/
136-
WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException;
137+
WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException;
137138

138139
/**
139140
* 企业和服务商可通过此接口,将微信外部联系人的userid转为微信openid,用于调用支付相关接口。暂不支持企业微信外部联系人(ExternalUserid为wo开头)的userid转openid。
@@ -190,7 +191,7 @@ public interface WxCpExternalContactService {
190191
* @throws WxErrorException .
191192
*/
192193
String opengidToChatid(@NotNull String opengid) throws WxErrorException;
193-
194+
194195
/**
195196
* 批量获取客户详情.
196197
* <pre>
@@ -789,4 +790,31 @@ WxCpGetMomentComments getMomentComments(String momentId, String userId)
789790
* @throws WxErrorException the wx error exception
790791
*/
791792
WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException;
793+
794+
/**
795+
* <pre>
796+
* 获取商品图册
797+
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
798+
* </pre>
799+
*
800+
* @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
801+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
802+
* @return wx cp base resp
803+
* @throws WxErrorException the wx error exception
804+
*/
805+
WxCpProductAlbumListResult getProductAlbumList(Integer limit, String cursor) throws WxErrorException;
806+
807+
/**
808+
* <pre>
809+
* 获取商品图册
810+
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
811+
* </pre>
812+
*
813+
* @param productId 商品id
814+
* @return wx cp base resp
815+
* @throws WxErrorException the wx error exception
816+
*/
817+
WxCpProductAlbumResult getProductAlbum(String productId) throws WxErrorException;
818+
819+
792820
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

+47-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ public WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorE
102102
}
103103

104104
@Override
105-
public WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException {
106-
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_DETAIL + userId);
105+
public WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException {
106+
String params = userId;
107+
if(StringUtils.isNotEmpty(cursor)){
108+
params = params + "&cursor=" + cursor;
109+
}
110+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_DETAIL + params);
107111
String responseContent = this.mainService.get(url, null);
108112
return WxCpExternalContactInfo.fromJson(responseContent);
109113
}
@@ -702,4 +706,45 @@ public WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String a
702706
final String result = this.mainService.post(url, json.toString());
703707
return WxCpBaseResp.fromJson(result);
704708
}
709+
710+
/**
711+
* <pre>
712+
* 获取商品图册
713+
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
714+
* </pre>
715+
*
716+
* @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
717+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
718+
* @return wx cp base resp
719+
* @throws WxErrorException the wx error exception
720+
*/
721+
@Override
722+
public WxCpProductAlbumListResult getProductAlbumList(Integer limit, String cursor) throws WxErrorException {
723+
JsonObject json = new JsonObject();
724+
json.addProperty("limit", limit);
725+
json.addProperty("cursor", cursor);
726+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_PRODUCT_ALBUM_LIST);
727+
final String result = this.mainService.post(url, json.toString());
728+
return WxCpProductAlbumListResult.fromJson(result);
729+
}
730+
731+
/**
732+
* <pre>
733+
* 获取商品图册
734+
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
735+
* </pre>
736+
*
737+
* @param productId 商品id
738+
* @return wx cp base resp
739+
* @throws WxErrorException the wx error exception
740+
*/
741+
@Override
742+
public WxCpProductAlbumResult getProductAlbum(String productId) throws WxErrorException {
743+
JsonObject json = new JsonObject();
744+
json.addProperty("product_id", productId);
745+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_PRODUCT_ALBUM);
746+
final String result = this.mainService.post(url, json.toString());
747+
return WxCpProductAlbumResult.fromJson(result);
748+
}
749+
705750
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.io.Serializable;
5+
import java.util.List;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import me.chanjar.weixin.cp.bean.external.product.Attachment;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
/**
12+
* <pre>
13+
* 获取商品图册
14+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
15+
* </pre>
16+
*
17+
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
18+
*/
19+
@Getter
20+
@Setter
21+
public class WxCpProductAlbumInfo implements Serializable {
22+
23+
private static final long serialVersionUID = -8338202601802366899L;
24+
25+
@SerializedName("product_id")
26+
private String productId;
27+
28+
@SerializedName("product_sn")
29+
private String productSn;
30+
31+
@SerializedName("description")
32+
private String description;
33+
34+
/**
35+
* NOTE: 20211110 价钱返回全部为0
36+
*/
37+
@SerializedName("price")
38+
private Integer price;
39+
40+
/**
41+
* NOTE: 20211110 商品列表接口不返回此字段, 商品详情接口返回
42+
*/
43+
@SerializedName("create_time")
44+
private Long createTime;
45+
46+
@SerializedName("attachments")
47+
private List<Attachment> attachments;
48+
49+
public static WxCpProductAlbumInfo fromJson(String json) {
50+
return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumInfo.class);
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.io.Serializable;
5+
import java.util.List;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
/**
12+
* <pre>
13+
* 获取商品图册列表执行结果
14+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
15+
* </pre>
16+
*
17+
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
18+
*/
19+
@Getter
20+
@Setter
21+
public class WxCpProductAlbumListResult extends WxCpBaseResp implements Serializable {
22+
23+
private static final long serialVersionUID = 121265727802015428L;
24+
25+
@SerializedName("product_list")
26+
private List<WxCpProductAlbumInfo> productList;
27+
28+
@SerializedName("next_cursor")
29+
private String nextCursor;
30+
31+
public static WxCpProductAlbumListResult fromJson(String json) {
32+
return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumListResult.class);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.cp.bean.external;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.io.Serializable;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
/**
11+
* <pre>
12+
* 获取商品图册执行结果
13+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
14+
* </pre>
15+
*
16+
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
17+
*/
18+
@Getter
19+
@Setter
20+
public class WxCpProductAlbumResult extends WxCpBaseResp implements Serializable {
21+
22+
private static final long serialVersionUID = 4076734101839851497L;
23+
24+
@SerializedName("product")
25+
private WxCpProductAlbumInfo product;
26+
27+
public static WxCpProductAlbumResult fromJson(String json) {
28+
return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumResult.class);
29+
}
30+
31+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/contact/ExternalContact.java

+20
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,30 @@ public class ExternalContact implements Serializable {
5151
public static class ExternalProfile implements Serializable {
5252
private static final long serialVersionUID = -2899906589789022765L;
5353

54+
@SerializedName("external_corp_name")
55+
private String externalCorpName;
56+
57+
@SerializedName("wechat_channels")
58+
private WechatChannel wechatChannels;
59+
5460
@SerializedName("external_attr")
5561
private List<ExternalAttribute> externalAttrs;
5662
}
5763

64+
@Data
65+
@Builder
66+
@NoArgsConstructor
67+
@AllArgsConstructor
68+
public static class WechatChannel implements Serializable {
69+
70+
@SerializedName("nickname")
71+
private String nickname;
72+
73+
@SerializedName("status")
74+
private Integer status;
75+
76+
}
77+
5878
@Data
5979
@Builder
6080
@NoArgsConstructor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.cp.bean.external.product;
2+
3+
import java.io.Serializable;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.constant.WxCpConsts;
6+
7+
/**
8+
* 商品画册附件
9+
*
10+
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
11+
*/
12+
@Data
13+
public class Attachment implements Serializable {
14+
15+
private static final long serialVersionUID = -4545283630169056262L;
16+
17+
/**
18+
* NOTE: 20211110 字段接口未返回
19+
*/
20+
private String type;
21+
22+
/**
23+
* 附件类型,目前仅支持image
24+
*/
25+
private Image image;
26+
27+
public void setImage(Image image) {
28+
this.image = image;
29+
this.type = WxCpConsts.ProductAttachmentType.IMAGE;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package me.chanjar.weixin.cp.bean.external.product;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.io.Serializable;
5+
import lombok.Data;
6+
7+
/**
8+
* 商品画册图片
9+
*
10+
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
11+
*/
12+
@Data
13+
public class Image implements Serializable {
14+
15+
private static final long serialVersionUID = -2737415903252627814L;
16+
17+
@SerializedName("media_id")
18+
private String mediaId;
19+
20+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+3
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ interface ExternalContact {
219219
String GET_GROUP_MSG_TASK = "/cgi-bin/externalcontact/get_groupmsg_task";
220220
String GET_GROUP_MSG_LIST_V2 = "/cgi-bin/externalcontact/get_groupmsg_list_v2";
221221

222+
String GET_PRODUCT_ALBUM = "/cgi-bin/externalcontact/get_product_album";
223+
String GET_PRODUCT_ALBUM_LIST = "/cgi-bin/externalcontact/get_product_album_list";
224+
222225
String GROUP_WELCOME_TEMPLATE_ADD = "/cgi-bin/externalcontact/group_welcome_template/add";
223226
String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit";
224227
String GROUP_WELCOME_TEMPLATE_GET = "/cgi-bin/externalcontact/group_welcome_template/get";

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java

+11
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,15 @@ public static class WelcomeMsgType {
359359
*/
360360
public static final String FILE = "file";
361361
}
362+
363+
@UtilityClass
364+
public static class ProductAttachmentType {
365+
366+
/**
367+
* 图片消息.
368+
*/
369+
public static final String IMAGE = "image";
370+
371+
}
372+
362373
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.Date;
2222
import java.util.List;
23+
import org.testng.collections.CollectionUtils;
2324

2425
import static org.testng.Assert.assertNotNull;
2526

@@ -111,7 +112,7 @@ public void testListExternalWithPermission() throws WxErrorException {
111112
@Test
112113
public void testGetContactDetail() throws WxErrorException {
113114
String externalUserId = this.configStorage.getExternalUserId();
114-
WxCpExternalContactInfo result = this.wxCpService.getExternalContactService().getContactDetail(externalUserId);
115+
WxCpExternalContactInfo result = this.wxCpService.getExternalContactService().getContactDetail(externalUserId, null);
115116
System.out.println(result);
116117
assertNotNull(result);
117118
}
@@ -314,4 +315,18 @@ public void testUpdateRemark() throws WxErrorException {
314315
.remarkPicMediaId("aaa")
315316
.build());
316317
}
318+
319+
@Test
320+
public void testGetProductListAlbum() throws WxErrorException {
321+
WxCpProductAlbumListResult result = this.wxCpService.getExternalContactService()
322+
.getProductAlbumList(100, null);
323+
System.out.println(result);
324+
assertNotNull(result);
325+
if(CollectionUtils.hasElements(result.getProductList())){
326+
WxCpProductAlbumResult result1 = this.wxCpService.getExternalContactService().getProductAlbum(result.getProductList().get(0).getProductId());
327+
System.out.println(result1);
328+
assertNotNull(result1);
329+
}
330+
}
331+
317332
}

0 commit comments

Comments
 (0)