:new :#2382 【企业微信】增加获取商品图册的接口
This commit is contained in:
@@ -109,7 +109,7 @@ public interface WxCpExternalContactService {
|
|||||||
* @param userId 外部联系人的userid
|
* @param userId 外部联系人的userid
|
||||||
* @return . external contact
|
* @return . external contact
|
||||||
* @throws WxErrorException the wx error exception
|
* @throws WxErrorException the wx error exception
|
||||||
* @deprecated 建议使用 {@link #getContactDetail(String)}
|
* @deprecated 建议使用 {@link #getContactDetail(String, String)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorException;
|
WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorException;
|
||||||
@@ -130,10 +130,11 @@ public interface WxCpExternalContactService {
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param userId 外部联系人的userid,注意不是企业成员的帐号
|
* @param userId 外部联系人的userid,注意不是企业成员的帐号
|
||||||
|
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
|
||||||
* @return . contact detail
|
* @return . contact detail
|
||||||
* @throws WxErrorException .
|
* @throws WxErrorException .
|
||||||
*/
|
*/
|
||||||
WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException;
|
WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业和服务商可通过此接口,将微信外部联系人的userid转为微信openid,用于调用支付相关接口。暂不支持企业微信外部联系人(ExternalUserid为wo开头)的userid转openid。
|
* 企业和服务商可通过此接口,将微信外部联系人的userid转为微信openid,用于调用支付相关接口。暂不支持企业微信外部联系人(ExternalUserid为wo开头)的userid转openid。
|
||||||
@@ -789,4 +790,31 @@ public interface WxCpExternalContactService {
|
|||||||
* @throws WxErrorException the wx error exception
|
* @throws WxErrorException the wx error exception
|
||||||
*/
|
*/
|
||||||
WxCpBaseResp delGroupWelcomeTemplate(@NotNull String templateId, String agentId) throws WxErrorException;
|
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;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,8 +102,12 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException {
|
public WxCpExternalContactInfo getContactDetail(String userId, String cursor) throws WxErrorException {
|
||||||
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_CONTACT_DETAIL + userId);
|
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);
|
String responseContent = this.mainService.get(url, null);
|
||||||
return WxCpExternalContactInfo.fromJson(responseContent);
|
return WxCpExternalContactInfo.fromJson(responseContent);
|
||||||
}
|
}
|
||||||
@@ -702,4 +706,45 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
|
|||||||
final String result = this.mainService.post(url, json.toString());
|
final String result = this.mainService.post(url, json.toString());
|
||||||
return WxCpBaseResp.fromJson(result);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
53
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumInfo.java
vendored
Normal file
53
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumInfo.java
vendored
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumListResult.java
vendored
Normal file
35
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumListResult.java
vendored
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumResult.java
vendored
Normal file
31
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumResult.java
vendored
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -51,10 +51,30 @@ public class ExternalContact implements Serializable {
|
|||||||
public static class ExternalProfile implements Serializable {
|
public static class ExternalProfile implements Serializable {
|
||||||
private static final long serialVersionUID = -2899906589789022765L;
|
private static final long serialVersionUID = -2899906589789022765L;
|
||||||
|
|
||||||
|
@SerializedName("external_corp_name")
|
||||||
|
private String externalCorpName;
|
||||||
|
|
||||||
|
@SerializedName("wechat_channels")
|
||||||
|
private WechatChannel wechatChannels;
|
||||||
|
|
||||||
@SerializedName("external_attr")
|
@SerializedName("external_attr")
|
||||||
private List<ExternalAttribute> externalAttrs;
|
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
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
31
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/product/Attachment.java
vendored
Normal file
31
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/product/Attachment.java
vendored
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/product/Image.java
vendored
Normal file
20
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/product/Image.java
vendored
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -219,6 +219,9 @@ public interface WxCpApiPathConsts {
|
|||||||
String GET_GROUP_MSG_TASK = "/cgi-bin/externalcontact/get_groupmsg_task";
|
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_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_ADD = "/cgi-bin/externalcontact/group_welcome_template/add";
|
||||||
String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit";
|
String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit";
|
||||||
String GROUP_WELCOME_TEMPLATE_GET = "/cgi-bin/externalcontact/group_welcome_template/get";
|
String GROUP_WELCOME_TEMPLATE_GET = "/cgi-bin/externalcontact/group_welcome_template/get";
|
||||||
|
|||||||
@@ -359,4 +359,15 @@ public class WxCpConsts {
|
|||||||
*/
|
*/
|
||||||
public static final String FILE = "file";
|
public static final String FILE = "file";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public static class ProductAttachmentType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片消息.
|
||||||
|
*/
|
||||||
|
public static final String IMAGE = "image";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.testng.collections.CollectionUtils;
|
||||||
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ public class WxCpExternalContactServiceImplTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetContactDetail() throws WxErrorException {
|
public void testGetContactDetail() throws WxErrorException {
|
||||||
String externalUserId = this.configStorage.getExternalUserId();
|
String externalUserId = this.configStorage.getExternalUserId();
|
||||||
WxCpExternalContactInfo result = this.wxCpService.getExternalContactService().getContactDetail(externalUserId);
|
WxCpExternalContactInfo result = this.wxCpService.getExternalContactService().getContactDetail(externalUserId, null);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
}
|
}
|
||||||
@@ -314,4 +315,18 @@ public class WxCpExternalContactServiceImplTest {
|
|||||||
.remarkPicMediaId("aaa")
|
.remarkPicMediaId("aaa")
|
||||||
.build());
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user