🎨 #3426【视频号】更新视频号小店/微信小店类目、订单、商品、主页管理等相关接口

This commit is contained in:
Zeyes Lee
2024-11-30 00:40:57 +08:00
committed by Binary Wang
parent 524ff80522
commit f72f748cda
124 changed files with 3966 additions and 234 deletions

View File

@@ -20,6 +20,8 @@ import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.channel.util.JsonUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -29,9 +31,19 @@ import org.testng.annotations.Test;
@Guice(modules = ApiTestModule.class)
public class WxChannelBasicServiceImplTest {
private static final Logger log = LoggerFactory.getLogger(WxChannelBasicServiceImplTest.class);
@Inject
private WxChannelService channelService;
@Test
public void testGetAccessToken() throws WxErrorException {
String accessToken = channelService.getAccessToken();
assertNotNull(accessToken);
log.info("accessToken: \n{}\n\n", accessToken);
System.out.println(accessToken);
}
@Test
public void testGetShopInfo() throws WxErrorException {
WxChannelBasicService basicService = channelService.getBasicService();

View File

@@ -4,18 +4,24 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.api.WxChannelCategoryService;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.bean.audit.AuditApplyResponse;
import me.chanjar.weixin.channel.bean.audit.AuditResponse;
import me.chanjar.weixin.channel.bean.audit.CategoryAuditInfo;
import me.chanjar.weixin.channel.bean.audit.CategoryAuditRequest;
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
import me.chanjar.weixin.channel.bean.category.CategoryAndQualificationList;
import me.chanjar.weixin.channel.bean.category.CategoryDetailResult;
import me.chanjar.weixin.channel.bean.category.CategoryQualification;
import me.chanjar.weixin.channel.bean.category.CategoryQualificationResponse;
import me.chanjar.weixin.channel.bean.category.PassCategoryResponse;
import me.chanjar.weixin.channel.bean.category.ShopCategory;
import me.chanjar.weixin.channel.bean.category.ShopCategoryResponse;
import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.channel.util.JsonUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -24,6 +30,7 @@ import org.testng.collections.CollectionUtils;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Slf4j
@Guice(modules = ApiTestModule.class)
public class WxChannelCategoryServiceImplTest {
@@ -36,21 +43,40 @@ public class WxChannelCategoryServiceImplTest {
CategoryQualificationResponse response = categoryService.listAllCategory();
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(response);
//System.out.println(response);
// 测试分类7231 瑜伽服上衣
for (CategoryAndQualificationList cat : response.getCatsV2()) {
if (cat.getList() == null) {
continue;
}
for (CategoryQualification qua : cat.getList()) {
if (qua.getCategory() == null) {
log.error("category is null");
}
if ("7231".equals(qua.getCategory().getId())) {
log.info("qua: {}", JsonUtils.encode(qua));
}
}
}
}
@Test
public void testListAvailableCategory() throws WxErrorException {
public void testListAvailableCategories() throws WxErrorException {
WxChannelCategoryService categoryService = channelService.getCategoryService();
List<ShopCategory> shopCategories = categoryService.listAvailableCategory("0");
assertTrue(CollectionUtils.hasElements(shopCategories));
shopCategories.forEach(System.out::println);
ShopCategoryResponse response = categoryService.listAvailableCategories("0");
assertNotNull(response);
assertTrue(response.isSuccess());
List<ShopCategory> v1 = response.getCategories();
List<ShopCategory> v2 = response.getCatListV2();
assertTrue(CollectionUtils.hasElements(v1) || CollectionUtils.hasElements(v2));
v1.forEach(System.out::println);
v2.forEach(System.out::println);
}
@Test
public void testGetCategoryDetail() throws WxErrorException {
WxChannelCategoryService categoryService = channelService.getCategoryService();
CategoryDetailResult categoryDetail = categoryService.getCategoryDetail("1602");
CategoryDetailResult categoryDetail = categoryService.getCategoryDetail("7231");
assertNotNull(categoryDetail);
assertTrue(categoryDetail.isSuccess());
System.out.println(categoryDetail);
@@ -58,11 +84,47 @@ public class WxChannelCategoryServiceImplTest {
@Test
public void testAddCategory() throws WxErrorException {
// WxChannelCategoryService categoryService = channelService.getCategoryService();
// List<String> certificates = new ArrayList<>();
// certificates.add(
// "hWNith8iZSrxfN7W2tXOoWSXYWi1qADRJxwImvQl2DC6wqqJrl4g8i/UEZfd59yiiEKAnqy0WETFrOcGZFcJDfpH2ccmNZddzesR1/OpAC7bbfmEiDFBK2QL7MBjhR2m");
// AuditApplyResponse response = categoryService.addCategory("1001", "1002", "1005", certificates);
// assertNotNull(response);
// assertTrue(response.isSuccess());
// System.out.println(response);
String json = "{\n"
+ " \"category_info\": {\n"
+ " \"cats_v2\":[\n"
+ " {\n"
+ " \"cat_id\": 6033\n"
+ " },\n"
+ " {\n"
+ " \"cat_id\": 6057\n"
+ " },\n"
+ " {\n"
+ " \"cat_id\": 6091\n"
+ " },\n"
+ " {\n"
+ " \"cat_id\": 6093\n"
+ " }\n"
+ " ],\n"
+ " \"certificate\": [\n"
+ " \"THE_FILE_ID_1\",\n"
+ " \"THE_FILE_ID_2\"\n"
+ " ],\n"
+ " \"brand_list\" : [\n"
+ " { \"brand_id\": 1001 },\n"
+ " { \"brand_id\": 1002 }\n"
+ " ]\n"
+ " }\n"
+ "}";
CategoryAuditRequest param = JsonUtils.decode(json, CategoryAuditRequest.class);
CategoryAuditInfo info = null;
if (info != null) {
info = param.getCategoryInfo();
}
WxChannelCategoryService categoryService = channelService.getCategoryService();
List<String> certificates = new ArrayList<>();
certificates.add(
"hWNith8iZSrxfN7W2tXOoWSXYWi1qADRJxwImvQl2DC6wqqJrl4g8i/UEZfd59yiiEKAnqy0WETFrOcGZFcJDfpH2ccmNZddzesR1/OpAC7bbfmEiDFBK2QL7MBjhR2m");
AuditApplyResponse response = categoryService.addCategory("1001", "1002", "1005", certificates);
AuditApplyResponse response = categoryService.addCategory(info);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(response);

View File

@@ -12,13 +12,16 @@ import me.chanjar.weixin.channel.bean.base.AddressInfo;
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
import me.chanjar.weixin.channel.bean.delivery.DeliveryCompanyResponse;
import me.chanjar.weixin.channel.bean.delivery.DeliveryInfo;
import me.chanjar.weixin.channel.bean.delivery.PackageAuditInfo;
import me.chanjar.weixin.channel.bean.order.ChangeOrderInfo;
import me.chanjar.weixin.channel.bean.order.DecodeSensitiveInfoResponse;
import me.chanjar.weixin.channel.bean.order.DeliveryUpdateParam;
import me.chanjar.weixin.channel.bean.order.OrderAddressInfo;
import me.chanjar.weixin.channel.bean.order.OrderInfoResponse;
import me.chanjar.weixin.channel.bean.order.OrderListParam;
import me.chanjar.weixin.channel.bean.order.OrderListResponse;
import me.chanjar.weixin.channel.bean.order.OrderSearchParam;
import me.chanjar.weixin.channel.bean.order.VirtualTelNumberResponse;
import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
@@ -148,4 +151,36 @@ public class WxChannelOrderServiceImplTest {
assertNotNull(response);
assertTrue(response.isSuccess());
}
@Test
public void testUploadFreshInspect() throws WxErrorException {
WxChannelOrderService orderService = channelService.getOrderService();
String orderId = "123";
List<PackageAuditInfo> items = new ArrayList<>();
items.add(new PackageAuditInfo("product_express_pic_url", "https://store.mp.video.tencent-cloud.com/x"));
items.add(new PackageAuditInfo("product_packaging_box_panoramic_video_url", "https://store.mp.video.tencent-cloud.com/y"));
items.add(new PackageAuditInfo("product_unboxing_panoramic_video_url", "https://store.mp.video.tencent-cloud.com/z"));
items.add(new PackageAuditInfo("single_product_detail_panoramic_video_url", "https://store.mp.video.tencent-cloud.com/a"));
WxChannelBaseResponse response = orderService.uploadFreshInspect(orderId, items);
assertNotNull(response);
assertTrue(response.isSuccess());
}
@Test
public void testGetVirtualTelNumber() throws WxErrorException {
WxChannelOrderService orderService = channelService.getOrderService();
String orderId = "123";
VirtualTelNumberResponse response = orderService.getVirtualTelNumber(orderId);
assertNotNull(response);
assertTrue(response.isSuccess());
}
@Test
public void testDecodeSensitiveInfo() throws WxErrorException {
WxChannelOrderService orderService = channelService.getOrderService();
String orderId = "123";
DecodeSensitiveInfoResponse response = orderService.decodeSensitiveInfo(orderId);
assertNotNull(response);
assertTrue(response.isSuccess());
}
}

View File

@@ -4,17 +4,23 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import me.chanjar.weixin.channel.api.WxChannelProductService;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
import me.chanjar.weixin.channel.bean.limit.LimitTaskAddResponse;
import me.chanjar.weixin.channel.bean.limit.LimitTaskListResponse;
import me.chanjar.weixin.channel.bean.limit.LimitTaskParam;
import me.chanjar.weixin.channel.bean.product.SkuStockBatchResponse;
import me.chanjar.weixin.channel.bean.product.SkuStockResponse;
import me.chanjar.weixin.channel.bean.product.SpuGetResponse;
import me.chanjar.weixin.channel.bean.product.SpuInfo;
import me.chanjar.weixin.channel.bean.product.SpuListResponse;
import me.chanjar.weixin.channel.bean.product.SpuUpdateInfo;
import me.chanjar.weixin.channel.bean.product.SpuUpdateResponse;
import me.chanjar.weixin.channel.bean.product.link.ProductH5UrlResponse;
import me.chanjar.weixin.channel.bean.product.link.ProductQrCodeResponse;
import me.chanjar.weixin.channel.bean.product.link.ProductTagLinkResponse;
import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
@@ -32,7 +38,7 @@ public class WxChannelProductServiceImplTest {
@Test
public void testAddProduct() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
SpuInfo spuInfo = new SpuInfo();
SpuUpdateInfo spuInfo = new SpuUpdateInfo();
// ...
SpuUpdateResponse response = productService.addProduct(spuInfo);
assertNotNull(response);
@@ -42,7 +48,7 @@ public class WxChannelProductServiceImplTest {
@Test
public void testUpdateProduct() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
SpuInfo spuInfo = new SpuInfo();
SpuUpdateInfo spuInfo = new SpuUpdateInfo();
// ...
SpuUpdateResponse response = productService.updateProduct(spuInfo);
assertNotNull(response);
@@ -121,13 +127,53 @@ public class WxChannelProductServiceImplTest {
@Test
public void testGetSkuStock() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
String productId = "";
String skuId = "";
String productId = "10000076089602";
String skuId = "1918289111";
SkuStockResponse response = productService.getSkuStock(productId, skuId);
assertNotNull(response);
assertTrue(response.isSuccess());
}
@Test
public void testGetSkuStockBatch() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
List<String> productIds = new ArrayList<>();
productIds.add("123");
SkuStockBatchResponse response = productService.getSkuStockBatch(productIds);
assertNotNull(response);
assertTrue(response.isSuccess());
}
@Test
public void testGetProductH5Url() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
String productId = "";
ProductH5UrlResponse response = productService.getProductH5Url(productId);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(response.getProductH5url());
}
@Test
public void testGetProductQrCode() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
String productId = "";
ProductQrCodeResponse response = productService.getProductQrCode(productId);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(response.getProductQrcode());
}
@Test
public void testGetProductTagLink() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();
String productId = "";
ProductTagLinkResponse response = productService.getProductTagLink(productId);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(response.getProductTaglink());
}
@Test
public void testAddLimitTask() throws WxErrorException {
WxChannelProductService productService = channelService.getProductService();

View File

@@ -0,0 +1,32 @@
package me.chanjar.weixin.channel.api.impl;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import com.google.inject.Inject;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.bean.vip.VipInfoResponse;
import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.channel.util.JsonUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Guice(modules = ApiTestModule.class)
public class WxChannelVipServiceImplTest {
@Inject
private WxChannelService channelService;
@Test
public void getVipInfo() throws WxErrorException {
String openId = "";
Boolean needPhoneNumber = false;
VipInfoResponse response = channelService.getVipService().getVipInfo(openId, needPhoneNumber);
System.out.println(JsonUtils.encode(response));
assertNotNull(response);
assertTrue(response.isSuccess());
}
}

View File

@@ -0,0 +1,339 @@
package me.chanjar.weixin.channel.api.impl;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import com.google.inject.Inject;
import me.chanjar.weixin.channel.api.WxStoreHomePageService;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.bean.base.WxChannelBaseResponse;
import me.chanjar.weixin.channel.bean.home.background.BackgroundApplyResponse;
import me.chanjar.weixin.channel.bean.home.background.BackgroundGetResponse;
import me.chanjar.weixin.channel.bean.home.banner.BannerApplyParam;
import me.chanjar.weixin.channel.bean.home.banner.BannerApplyResponse;
import me.chanjar.weixin.channel.bean.home.banner.BannerGetResponse;
import me.chanjar.weixin.channel.bean.home.banner.BannerInfo;
import me.chanjar.weixin.channel.bean.home.tree.TreeProductEditInfo;
import me.chanjar.weixin.channel.bean.home.tree.TreeProductEditParam;
import me.chanjar.weixin.channel.bean.home.tree.TreeProductListInfo;
import me.chanjar.weixin.channel.bean.home.tree.TreeProductListResponse;
import me.chanjar.weixin.channel.bean.home.tree.TreeShowGetResponse;
import me.chanjar.weixin.channel.bean.home.tree.TreeShowInfo;
import me.chanjar.weixin.channel.bean.home.tree.TreeShowParam;
import me.chanjar.weixin.channel.bean.home.tree.TreeShowSetResponse;
import me.chanjar.weixin.channel.bean.home.window.WindowProductSettingResponse;
import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.channel.util.JsonUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* @author <a href="https://github.com/lixize">Zeyes</a>
*/
@Guice(modules = ApiTestModule.class)
public class WxStoreHomePageServiceImplTest {
@Inject
private WxChannelService channelService;
@Test
public void testAddTreeProduct() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
// https://developers.weixin.qq.com/doc/store/API/homepage/classification/addclassificationproduct.html
String json = "{\n"
+ " \"req\": {\n"
+ " \"level_1_id\": 10000046,\n"
+ " \"level_2_id\": 10000048,\n"
+ " \"product_ids\": [\n"
+ " 10000076089602\n"
+ " ]\n"
+ " }\n"
+ "}";
TreeProductEditParam param = JsonUtils.decode(json, TreeProductEditParam.class);
TreeProductEditInfo info = null;
if (param != null) {
info = param.getReq();
}
WxChannelBaseResponse response = service.addTreeProduct(info);
assertNotNull(response);
assertTrue(response.isSuccess());
assertNotNull(info);
System.out.println(JsonUtils.encode(response));
}
@Test
public void testDelTreeProduct() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
String json = "{\n"
+ " \"req\": {\n"
+ " \"level_1_id\": 1,\n"
+ " \"level_2_id\": 0,\n"
+ " \"product_ids\": [\n"
+ " 123\n"
+ " ]\n"
+ " }\n"
+ "}";
TreeProductEditParam param = JsonUtils.decode(json, TreeProductEditParam.class);
TreeProductEditInfo info = null;
if (param != null) {
info = param.getReq();
}
WxChannelBaseResponse response = service.delTreeProduct(info);
assertNotNull(response);
assertTrue(response.isSuccess());
assertNotNull(info);
System.out.println(JsonUtils.encode(response));
}
@Test
public void testGetTreeProductList() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
String pageContext = "";
TreeProductListInfo info = new TreeProductListInfo();
info.setLevel1Id(1);
info.setLevel2Id(2);
info.setPageSize(10);
info.setPageContext(pageContext);
TreeProductListResponse response = service.getTreeProductList(info);
assertNotNull(response);
assertTrue(response.isSuccess());
assertNotNull(info);
System.out.println(JsonUtils.encode(response));
}
@Test
public void testSetShowTree() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
// https://developers.weixin.qq.com/doc/store/API/homepage/classification/setclassificationtree.html
String json = "{\n"
+ " \"req\": {\n"
+ " \"version\": 121,\n"
+ " \"classification_id_deleted\": [\n"
+ " \"1.2\"\n"
+ " ],\n"
+ " \"tree\": {\n"
+ " \"level_1\": [\n"
+ " {\n"
+ " \"id\": 4,\n"
+ " \"name\": \"测试7\",\n"
+ " \"level_2\": [\n"
+ " {\n"
+ " \"id\": 5,\n"
+ " \"name\": \"1\",\n"
+ " \"is_displayed\": 1\n"
+ " }\n"
+ " ],\n"
+ " \"is_displayed\": 1\n"
+ " },\n"
+ " {\n"
+ " \"id\": 6,\n"
+ " \"name\": \"测试8\",\n"
+ " \"level_2\": [\n"
+ " {\n"
+ " \"id\": 7,\n"
+ " \"name\": \"1\",\n"
+ " \"is_displayed\": 1\n"
+ " },\n"
+ " {\n"
+ " \"id\": 8,\n"
+ " \"name\": \"2\",\n"
+ " \"is_displayed\": 1\n"
+ " }\n"
+ " ],\n"
+ " \"is_displayed\": 1\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}";
TreeShowParam param = JsonUtils.decode(json, TreeShowParam.class);
TreeShowInfo info = null;
if (param != null) {
info = param.getReq();
}
TreeShowSetResponse response = service.setShowTree(info);
assertNotNull(response);
assertTrue(response.isSuccess());
assertNotNull(info);
System.out.println(JsonUtils.encode(response));
}
@Test
public void testGetShowTree() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
TreeShowGetResponse response = service.getShowTree();
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testListWindowProduct() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
Integer pageSize = 1;
String nextKey = "";
WindowProductSettingResponse response = service.listWindowProduct(pageSize, nextKey);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testReorderWindowProduct() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
String productId = "";
Integer indexNum = 100;
WxChannelBaseResponse response = service.reorderWindowProduct(productId, indexNum);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testHideWindowProduct() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
String productId = "";
// 0:显示 1:隐藏
Integer setHide = 0;
WxChannelBaseResponse response = service.hideWindowProduct(productId, setHide);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testTopWindowProduct() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
String productId = "";
// 0:取消置顶 1:置顶
Integer setTop = 0;
WxChannelBaseResponse response = service.topWindowProduct(productId, setTop);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testApplyBackground() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
String imgUrl = "https://github.githubassets.com/images/icons/emoji/octocat.png";
BackgroundApplyResponse response = service.applyBackground(imgUrl);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testGetBackground() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
BackgroundGetResponse response = service.getBackground();
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testCancelBackground() throws WxErrorException {
Integer applyId = 1;
WxStoreHomePageService service = channelService.getHomePageService();
WxChannelBaseResponse response = service.cancelBackground(applyId);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testRemoveBackground() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
WxChannelBaseResponse response = service.removeBackground();
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testApplyBanner() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
// https://developers.weixin.qq.com/doc/store/API/homepage/banner/submit_banner_apply.html
String json = "{\n"
+ " \"banner\": {\n"
+ " \"scale\": 2,\n"
+ " \"banner\": [\n"
+ " {\n"
+ " \"type\": 1,\n"
+ " \"product\": {\n"
+ " \"product_id\": 123\n"
+ " },\n"
+ " \"banner\": {\n"
+ " \"description\": \"测试商品精品展示位描述\",\n"
+ " \"img_url\": \"https://store.mp.video.tencent-cloud.com/abc\",\n"
+ " \"title\": \"测试商品精品展示位标题\"\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"type\": 3,\n"
+ " \"finder\": {\n"
+ " \"feed_id\": \"export/abc\",\n"
+ " \"finder_user_name\": \"sphabc\"\n"
+ " },\n"
+ " \"banner\": {\n"
+ " \"description\": \"测试视频号视频精品展示位描述\",\n"
+ " \"img_url\": \"https://store.mp.video.tencent-cloud.com/abc\",\n"
+ " \"title\": \"测试视频号视频精品展示位标题\"\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"type\": 4,\n"
+ " \"official_account\": {\n"
+ " \"url\": \"https://mp.weixin.qq.com/abc\"\n"
+ " },\n"
+ " \"banner\": {\n"
+ " \"description\": \"测试公众号文章精品展示位描述\",\n"
+ " \"img_url\": \"https://store.mp.video.tencent-cloud.com/abc\",\n"
+ " \"title\": \"测试公众号文章精品展示位标题\"\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
BannerApplyParam param = JsonUtils.decode(json, BannerApplyParam.class);
BannerInfo info = null;
if (param != null) {
info = param.getBanner();
}
BannerApplyResponse response = service.applyBanner(info);
assertNotNull(response);
assertTrue(response.isSuccess());
assertNotNull(info);
System.out.println(JsonUtils.encode(response));
}
@Test
public void testGetBanner() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
BannerGetResponse response = service.getBanner();
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testCancelBanner() throws WxErrorException {
Integer applyId = 1;
WxStoreHomePageService service = channelService.getHomePageService();
WxChannelBaseResponse response = service.cancelBanner(applyId);
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
@Test
public void testRemoveBanner() throws WxErrorException {
WxStoreHomePageService service = channelService.getHomePageService();
WxChannelBaseResponse response = service.removeBanner();
assertNotNull(response);
assertTrue(response.isSuccess());
System.out.println(JsonUtils.encode(response));
}
}

View File

@@ -1,7 +1,9 @@
package me.chanjar.weixin.channel.message;
import static me.chanjar.weixin.channel.constant.MessageEventConstants.BRAND;
import static me.chanjar.weixin.channel.constant.MessageEventConstants.CLOSE_STORE;
import static me.chanjar.weixin.channel.constant.MessageEventConstants.PRODUCT_SPU_AUDIT;
import static me.chanjar.weixin.channel.constant.MessageEventConstants.SET_SHOP_NICKNAME;
import static org.testng.Assert.*;
import com.google.inject.Inject;
@@ -10,6 +12,8 @@ import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.channel.api.WxChannelService;
import me.chanjar.weixin.channel.bean.message.product.BrandMessage;
import me.chanjar.weixin.channel.bean.message.product.SpuAuditMessage;
import me.chanjar.weixin.channel.bean.message.store.CloseStoreMessage;
import me.chanjar.weixin.channel.bean.message.store.NicknameUpdateMessage;
import me.chanjar.weixin.channel.message.rule.HandlerConsumer;
import me.chanjar.weixin.channel.test.ApiTestModule;
import me.chanjar.weixin.channel.util.JsonUtils;
@@ -56,6 +60,48 @@ public class WxChannelMessageRouterTest {
}
}
@Test
public void closeStore() {
WxChannelMessageRouter router = new WxChannelMessageRouter();
/* 小店注销 */
this.addRule(router, CloseStoreMessage.class, CLOSE_STORE, this::closeStore);
/* 小店修改名称 */
this.addRule(router, NicknameUpdateMessage.class, SET_SHOP_NICKNAME, this::updateNickname);
String closeStoreJson = "{\n"
+ " \"ToUserName\": \"gh_*\",\n"
+ " \"FromUserName\": \"OPENID\",\n"
+ " \"CreateTime\": 1662480000,\n"
+ " \"MsgType\": \"event\",\n"
+ " \"Event\": \"channels_ec_close_store\",\n"
+ " \"appid\": \"APPID\",\n"
+ " \"close_timestamp\": \"1662480000\"\n"
+ "}";
String updateNicknameJson = "{\n"
+ " \"ToUserName\": \"gh_*\", \n"
+ " \"FromUserName\": \"OPENID\", \n"
+ " \"CreateTime\": 1662480000, \n"
+ " \"MsgType\": \"event\", \n"
+ " \"Event\": \"set_shop_nickname\", \n"
+ " \"appid\": \"APPID\",\n"
+ " \"old_nickname\": \"旧昵称\",\n"
+ " \"new_nickname\": \"新昵称\"\n"
+ "}";
WxChannelMessage message1 = JsonUtils.decode(closeStoreJson, WxChannelMessage.class);
WxChannelMessage message2 = JsonUtils.decode(updateNicknameJson, WxChannelMessage.class);
Object result1 = router.route(message1, closeStoreJson, "123456", channelService);
if (result1 != null) {
log.info("result1:{}", result1);
} else {
log.info("result1 return null");
}
Object result2 = router.route(message2, updateNicknameJson, "123456", channelService);
if (result2 != null) {
log.info("result2:{}", result2);
} else {
log.info("result2 return null");
}
}
public void brandUpdate(BrandMessage message, String content, String appId,
Map<String, Object> context, WxSessionManager sessionManager) {
log.info("品牌更新:{}", JsonUtils.encode(message));
@@ -67,6 +113,16 @@ public class WxChannelMessageRouterTest {
log.info("商品审核:{}", JsonUtils.encode(message));
}
public void closeStore(CloseStoreMessage message, String content, String appId,
Map<String, Object> context, WxSessionManager sessionManager) {
log.info("小店注销:{}", JsonUtils.encode(message));
}
public void updateNickname(NicknameUpdateMessage message, String content, String appId,
Map<String, Object> context, WxSessionManager sessionManager) {
log.info("昵称更新:{}", JsonUtils.encode(message));
}
/**
* 添加一条规则进入路由器
*

View File

@@ -29,6 +29,7 @@ public class ApiTestModule implements Module {
"测试配置文件【" + TEST_CONFIG_XML + "】未找到请参照test-config-sample.xml文件生成");
}
// 提示xml相关依赖不存在时引入一下就好
TestConfig config = this.fromXml(TestConfig.class, inputStream);
WxChannelService service = new WxChannelServiceImpl();

View File

@@ -4,6 +4,7 @@
<secret>secret</secret>
<token>Token</token>
<aesKey>EncodingAESKey</aesKey>
<stableAccessToken>false</stableAccessToken>
<accessToken>可以不填写</accessToken>
<expiresTime>可以不填写</expiresTime>
</xml>