1
0
mirror of synced 2025-12-15 03:35:04 +08:00

:new :#2382 【企业微信】增加获取商品图册的接口

This commit is contained in:
Lo_ading
2021-11-14 21:31:29 +08:00
committed by GitHub
parent ef99e3d24f
commit 93779d227a
11 changed files with 298 additions and 6 deletions

View File

@@ -109,7 +109,7 @@ public interface WxCpExternalContactService {
* @param userId 外部联系人的userid
* @return . external contact
* @throws WxErrorException the wx error exception
* @deprecated 建议使用 {@link #getContactDetail(String)}
* @deprecated 建议使用 {@link #getContactDetail(String, String)}
*/
@Deprecated
WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorException;
@@ -130,10 +130,11 @@ public interface WxCpExternalContactService {
* </pre>
*
* @param userId 外部联系人的userid注意不是企业成员的帐号
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @return . contact detail
* @throws WxErrorException .
*/
WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException;
WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException;
/**
* 企业和服务商可通过此接口将微信外部联系人的userid转为微信openid用于调用支付相关接口。暂不支持企业微信外部联系人ExternalUserid为wo开头的userid转openid。
@@ -190,7 +191,7 @@ public interface WxCpExternalContactService {
* @throws WxErrorException .
*/
String opengidToChatid(@NotNull String opengid) throws WxErrorException;
/**
* 批量获取客户详情.
* <pre>
@@ -789,4 +790,31 @@ public interface WxCpExternalContactService {
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException;
/**
* <pre>
* 获取商品图册
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
* </pre>
*
* @param limit 返回的最大记录数整型最大值100默认值50超过最大值时取默认值
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpProductAlbumListResult getProductAlbumList(Integer limit, String cursor) throws WxErrorException;
/**
* <pre>
* 获取商品图册
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
* </pre>
*
* @param productId 商品id
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpProductAlbumResult getProductAlbum(String productId) throws WxErrorException;
}

View File

@@ -102,8 +102,12 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
}
@Override
public WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_DETAIL + userId);
public WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException {
String params = userId;
if(StringUtils.isNotEmpty(cursor)){
params = params + "&cursor=" + cursor;
}
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_DETAIL + params);
String responseContent = this.mainService.get(url, null);
return WxCpExternalContactInfo.fromJson(responseContent);
}
@@ -702,4 +706,45 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
final String result = this.mainService.post(url, json.toString());
return WxCpBaseResp.fromJson(result);
}
/**
* <pre>
* 获取商品图册
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
* </pre>
*
* @param limit 返回的最大记录数整型最大值100默认值50超过最大值时取默认值
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
@Override
public WxCpProductAlbumListResult getProductAlbumList(Integer limit, String cursor) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("limit", limit);
json.addProperty("cursor", cursor);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_PRODUCT_ALBUM_LIST);
final String result = this.mainService.post(url, json.toString());
return WxCpProductAlbumListResult.fromJson(result);
}
/**
* <pre>
* 获取商品图册
* https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
* </pre>
*
* @param productId 商品id
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
@Override
public WxCpProductAlbumResult getProductAlbum(String productId) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("product_id", productId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_PRODUCT_ALBUM);
final String result = this.mainService.post(url, json.toString());
return WxCpProductAlbumResult.fromJson(result);
}
}

View File

@@ -0,0 +1,53 @@
package me.chanjar.weixin.cp.bean.external;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.external.product.Attachment;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* <pre>
* 获取商品图册
* 参考文档https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
* </pre>
*
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
*/
@Getter
@Setter
public class WxCpProductAlbumInfo implements Serializable {
private static final long serialVersionUID = -8338202601802366899L;
@SerializedName("product_id")
private String productId;
@SerializedName("product_sn")
private String productSn;
@SerializedName("description")
private String description;
/**
* NOTE: 20211110 价钱返回全部为0
*/
@SerializedName("price")
private Integer price;
/**
* NOTE: 20211110 商品列表接口不返回此字段, 商品详情接口返回
*/
@SerializedName("create_time")
private Long createTime;
@SerializedName("attachments")
private List<Attachment> attachments;
public static WxCpProductAlbumInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumInfo.class);
}
}

View File

@@ -0,0 +1,35 @@
package me.chanjar.weixin.cp.bean.external;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* <pre>
* 获取商品图册列表执行结果
* 参考文档https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册列表
* </pre>
*
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
*/
@Getter
@Setter
public class WxCpProductAlbumListResult extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = 121265727802015428L;
@SerializedName("product_list")
private List<WxCpProductAlbumInfo> productList;
@SerializedName("next_cursor")
private String nextCursor;
public static WxCpProductAlbumListResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumListResult.class);
}
}

View File

@@ -0,0 +1,31 @@
package me.chanjar.weixin.cp.bean.external;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* <pre>
* 获取商品图册执行结果
* 参考文档https://work.weixin.qq.com/api/doc/90000/90135/95096#获取商品图册
* </pre>
*
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
*/
@Getter
@Setter
public class WxCpProductAlbumResult extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = 4076734101839851497L;
@SerializedName("product")
private WxCpProductAlbumInfo product;
public static WxCpProductAlbumResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumResult.class);
}
}

View File

@@ -51,10 +51,30 @@ public class ExternalContact implements Serializable {
public static class ExternalProfile implements Serializable {
private static final long serialVersionUID = -2899906589789022765L;
@SerializedName("external_corp_name")
private String externalCorpName;
@SerializedName("wechat_channels")
private WechatChannel wechatChannels;
@SerializedName("external_attr")
private List<ExternalAttribute> externalAttrs;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class WechatChannel implements Serializable {
@SerializedName("nickname")
private String nickname;
@SerializedName("status")
private Integer status;
}
@Data
@Builder
@NoArgsConstructor

View File

@@ -0,0 +1,31 @@
package me.chanjar.weixin.cp.bean.external.product;
import java.io.Serializable;
import lombok.Data;
import me.chanjar.weixin.cp.constant.WxCpConsts;
/**
* 商品画册附件
*
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
*/
@Data
public class Attachment implements Serializable {
private static final long serialVersionUID = -4545283630169056262L;
/**
* NOTE: 20211110 字段接口未返回
*/
private String type;
/**
* 附件类型目前仅支持image
*/
private Image image;
public void setImage(Image image) {
this.image = image;
this.type = WxCpConsts.ProductAttachmentType.IMAGE;
}
}

View File

@@ -0,0 +1,20 @@
package me.chanjar.weixin.cp.bean.external.product;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Data;
/**
* 商品画册图片
*
* @author <a href="https://github.com/Loading-Life">Lo_ading</a>
*/
@Data
public class Image implements Serializable {
private static final long serialVersionUID = -2737415903252627814L;
@SerializedName("media_id")
private String mediaId;
}

View File

@@ -219,6 +219,9 @@ public interface WxCpApiPathConsts {
String GET_GROUP_MSG_TASK = "/cgi-bin/externalcontact/get_groupmsg_task";
String GET_GROUP_MSG_LIST_V2 = "/cgi-bin/externalcontact/get_groupmsg_list_v2";
String GET_PRODUCT_ALBUM = "/cgi-bin/externalcontact/get_product_album";
String GET_PRODUCT_ALBUM_LIST = "/cgi-bin/externalcontact/get_product_album_list";
String GROUP_WELCOME_TEMPLATE_ADD = "/cgi-bin/externalcontact/group_welcome_template/add";
String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit";
String GROUP_WELCOME_TEMPLATE_GET = "/cgi-bin/externalcontact/group_welcome_template/get";

View File

@@ -359,4 +359,15 @@ public class WxCpConsts {
*/
public static final String FILE = "file";
}
@UtilityClass
public static class ProductAttachmentType {
/**
* 图片消息.
*/
public static final String IMAGE = "image";
}
}

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.testng.collections.CollectionUtils;
import static org.testng.Assert.assertNotNull;
@@ -111,7 +112,7 @@ public class WxCpExternalContactServiceImplTest {
@Test
public void testGetContactDetail() throws WxErrorException {
String externalUserId = this.configStorage.getExternalUserId();
WxCpExternalContactInfo result = this.wxCpService.getExternalContactService().getContactDetail(externalUserId);
WxCpExternalContactInfo result = this.wxCpService.getExternalContactService().getContactDetail(externalUserId, null);
System.out.println(result);
assertNotNull(result);
}
@@ -314,4 +315,18 @@ public class WxCpExternalContactServiceImplTest {
.remarkPicMediaId("aaa")
.build());
}
@Test
public void testGetProductListAlbum() throws WxErrorException {
WxCpProductAlbumListResult result = this.wxCpService.getExternalContactService()
.getProductAlbumList(100, null);
System.out.println(result);
assertNotNull(result);
if(CollectionUtils.hasElements(result.getProductList())){
WxCpProductAlbumResult result1 = this.wxCpService.getExternalContactService().getProductAlbum(result.getProductList().get(0).getProductId());
System.out.println(result1);
assertNotNull(result1);
}
}
}