🆕 #2048 【开放平台】实现小商店的部分接口

This commit is contained in:
kelvenlaw
2021-07-03 21:06:02 +08:00
committed by GitHub
parent fb0460e1a1
commit eaa517359a
65 changed files with 3538 additions and 3 deletions

View File

@@ -1,6 +1,9 @@
package me.chanjar.weixin.open.api;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
@@ -8,8 +11,14 @@ import me.chanjar.weixin.open.bean.WxOpenCreateResult;
import me.chanjar.weixin.open.bean.WxOpenGetResult;
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
import me.chanjar.weixin.open.bean.minishop.*;
import me.chanjar.weixin.open.bean.minishop.coupon.WxMinishopCoupon;
import me.chanjar.weixin.open.bean.minishop.coupon.WxMinishopCouponStock;
import me.chanjar.weixin.open.bean.minishop.goods.*;
import me.chanjar.weixin.open.bean.minishop.limitdiscount.LimitDiscountGoods;
import me.chanjar.weixin.open.bean.result.*;
import java.io.File;
import java.util.List;
/**
@@ -127,6 +136,38 @@ public interface WxOpenComponentService {
*/
String DELETE_TEMPLATE_URL = "https://api.weixin.qq.com/wxa/deletetemplate";
String REGISTER_SHOP_URL = "https://api.weixin.qq.com/product/register/register_shop";
String CHECK_SHOP_AUDITSTATUS_URL = "https://api.weixin.qq.com/product/register/check_audit_status";
String SUBMIT_MERCHANTINFO_URL = "https://api.weixin.qq.com/product/register/submit_merchantinfo";
String SUBMIT_BASICINFO_URL = "https://api.weixin.qq.com/product/register/submit_basicinfo";
String UPLOAD_IMAGE_URL = "https://api.weixin.qq.com/product/img/upload";
String MINISHOP_CATEGORY_GET_URL = "https://api.weixin.qq.com/product/category/get";
String MINISHOP_BRAND_GET_URL = "https://api.weixin.qq.com/product/brand/get";
String MINISHOP_DELIVERY_TEMPLATE_GET_URL = "https://api.weixin.qq.com/product/delivery/get_freight_template";
String MINISHOP_SHOPCATEGORY_GET_URL = "https://api.weixin.qq.com/product/store/get_shopcat";
String MINISHOP_CREATE_COUPON_URL = "https://api.weixin.qq.com/product/coupon/create";
String MINISHOP_GET_COUPON_LIST = "https://api.weixin.qq.com/product/coupon/get_list";
String MINISHOP_PUSH_COUPON = "https://api.weixin.qq.com/product/coupon/push";
String MINISHOP_UPDATE_COUPON_URL = "https://api.weixin.qq.com/product/coupon/update";
String MINISHOP_UPDATE_COUPON_STATUS_URL = "https://api.weixin.qq.com/product/coupon/update_status";
String MINISHOP_GET_DELIVERY_COMPANY_URL = "https://api.weixin.qq.com/product/delivery/get_company_list";
/**
* Gets wx mp service by appid.
*
@@ -153,6 +194,15 @@ public interface WxOpenComponentService {
@Deprecated
WxOpenFastMaService getWxFastMaServiceByAppid(String appid);
/**
* 获取指定appid的小商店服务
*
* @param appid
* @return
*/
WxOpenMinishopService getWxMinishopServiceByAppid(String appid);
/**
* Gets wx open config storage.
*
@@ -508,4 +558,372 @@ public interface WxOpenComponentService {
* @throws WxErrorException .
*/
WxOpenResult fastRegisterWeappSearch(String name, String legalPersonaWechat, String legalPersonaName) throws WxErrorException;
/**
* https://api.weixin.qq.com/product/register/register_shop?component_access_token=xxxxxxxxx
* 注册小商店账号
*
* @param wxName 微信号(必填)
* @param idCardName 身份证姓名(必填)
* @param idCardNumber 身份证号(必填)
* @param channelId 渠道号,服务商后台生成渠道信息。(选填)
* @param apiOpenstoreType 1-整店打包开通小商店2-组件开放(开通小程序,并且已经完整的嵌入电商功能)(必填)
* @param authPageUrl 授权url选填
* @return the wx open result
* @throws WxErrorException
*/
WxOpenResult registerShop(String wxName, String idCardName, String idCardNumber, String channelId, Integer apiOpenstoreType, String authPageUrl) throws WxErrorException;
/**
* https://api.weixin.qq.com/product/register/check_audit_status
* 异步状态查询
* @param wxName 微信号
* @return
*/
String checkAuditStatus(String wxName) throws WxErrorException;
/**
* 已经获取到小商店的appId那么需要通过accesstoken来获取该小商店的状态
* @param appId
* @param wxName
* @return
* @throws WxErrorException
*/
String checkAuditStatus(String appId, String wxName) throws WxErrorException;
/**
*
* @param appId
* @param subjectType
* @param busiLicense
* @param organizationCodeInfo
* @param idcardInfo
* @param superAdministratorInfo
* @param merchantShoprtName
* @return
*/
WxOpenResult submitMerchantInfo(String appId, String subjectType, MinishopBusiLicense busiLicense, MinishopOrganizationCodeInfo organizationCodeInfo, MinishopIdcardInfo idcardInfo, MinishopSuperAdministratorInfo superAdministratorInfo, String merchantShoprtName) throws WxErrorException;
/**
*
* @param appId
* @param nameInfo
* @param returnInfo
* @return
* @throws WxErrorException
*/
WxOpenResult submitBasicInfo(String appId, MinishopNameInfo nameInfo, MinishopReturnInfo returnInfo) throws WxErrorException;
/**
*
* @param height
* @param width
* @param file
* @return
* @throws WxErrorException
*/
WxMinishopImageUploadResult uploadMinishopImagePicFile(String appId, Integer height, Integer width, File file) throws WxErrorException;
/**
* 获取小商店的类目详情
* @param appId小商店APPID
* @param fCatId父类目ID可先填0获取根部类目
* @return 小商店类目信息列表
*/
MinishopCategories getMinishopCategories(String appId, Integer fCatId) throws WxErrorException;
/**
* 获取小商店品牌信息
* @param appId小商店appID
* @return
*/
MinishopBrandList getMinishopBrands(String appId) throws WxErrorException;
/**
* 获取小商店运费模版信息
* @param appId小商店appID
* @return
*/
MinishopDeliveryTemplateResult getMinishopDeliveryTemplate(String appId) throws WxErrorException;
/**
* 获取小商店商品分类信息
* @param appId
* @return
*/
MinishopShopCatList getMinishopCatList(String appId) throws WxErrorException;
/**
* 获取小商店的快递公司列表
* @param appId
* @return
* @throws WxErrorException
*/
WxMinishopAddGoodsSpuResult<List<WxMinishopDeliveryCompany>> getMinishopDeliveryCompany(String appId) throws WxErrorException;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//小商店优惠券接口
/**
* 创建小商店优惠券
* @param appId小商店的appId
* @param couponInfo 优惠券信息
* @return couponId: 优惠券ID
* @throws WxErrorException
*/
Integer minishopCreateCoupon(String appId, WxMinishopCoupon couponInfo) throws WxErrorException;
/**
* 与小商店对接,获取小商店的优惠券信息
* @param appId小商店的appId
* @param startCreateTime优惠券创建时间的搜索开始时间
* @param endCreateTime优惠券创建时间的搜索结束时间
* @param status优惠券状态
* @param page第几页最小填1
* @param pageSize每页数量(不超过10,000)
* @return
* @throws WxErrorException
*/
WxMinishopCouponStock minishopGetCouponList(String appId, String startCreateTime, String endCreateTime, Integer status, Integer page, Integer pageSize) throws WxErrorException;
/**
* 与小商店对接,将优惠券发送给某人
* @param appid小商店appId
* @param openId优惠券接收人的openId
* @param couponId: 优惠券ID
* @return
*/
WxOpenResult minishopPushCouponToUser(String appid, String openId, Integer couponId) throws WxErrorException;
/**
* 与小商店对接,更新商城优惠券
* @param appId
* @param couponInfo
* @return
* @throws WxErrorException
*/
Integer minishopUpdateCoupon(String appId, WxMinishopCoupon couponInfo) throws WxErrorException;
/**
* 从优惠券创建后status=1可流转到2,4,5, COUPON_STATUS_VALID = 2 ;//生效 COUPON_STATUS_INVALID = 4 ;//已作废 COUPON_STATUS_DEL = 5;//删除
* @param appId
* @param couponId
* @param status
* @return
* @throws WxErrorException
*/
WxOpenResult minishopUpdateCouponStatus(String appId, Integer couponId, Integer status) throws WxErrorException;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//小商店spu接口
String MINISHOP_ADD_SPU_URL = "https://api.weixin.qq.com/product/spu/add";
String MINISHOP_DEL_SPU_URL = "https://api.weixin.qq.com/product/spu/del";
String MINISHOP_UPDATE_SPU_URL = "https://api.weixin.qq.com/product/spu/update";
String MINISHOP_LISTING_SPU_URL = "https://api.weixin.qq.com/product/spu/listing";
String MINISHOP_DELISTING_SPU_URL = "https://api.weixin.qq.com/product/spu/delisting";
/**
* 小商店添加商品接口,添加商品后只是添加到草稿箱,需要通过调用上架商品,并通过审核才能在商城中显示。
* @param appId
* @param spu
* @return
* @throws WxErrorException
*/
WxMinishopAddGoodsSpuResult<WxMinishopAddGoodsSpuData> minishopGoodsAddSpu(String appId, WxMinishopSpu spu) throws WxErrorException;
/**
* 小商店删除商品接口,直接删除,不会存在小商店回收站里面。
* @param appId
* @param productId
* @param outProductId
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsDelSpu(String appId, Long productId, Long outProductId) throws WxErrorException;
/**
* 小商店更新商品接口,不会直接影响上架商品的信息,而是存在草稿箱,需要调用上架商品接口,并通过审核才能在商城中显示。
* @param appId
* @param spu
* @return
* @throws WxErrorException
*/
WxMinishopAddGoodsSpuResult<WxMinishopAddGoodsSpuData> minishopGoodsUpdateSpu(String appId, WxMinishopSpu spu) throws WxErrorException;
/**
* 上架商品。
* @param appId
* @param productId
* @param outProductId
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsListingSpu(String appId, Long productId, Long outProductId) throws WxErrorException;
/**
* 下架商品
* @param appId
* @param productId
* @param outProductId
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsDelistingSpu(String appId, Long productId, Long outProductId) throws WxErrorException;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//小商店sku接口
String MINISHOP_ADD_SKU_URL = "https://api.weixin.qq.com/product/sku/add";
String MINISHOP_BATCH_ADD_SKU_URL = "https://api.weixin.qq.com/product/sku/batch_add";
String MINISHOP_DEL_SKU_URL = "https://api.weixin.qq.com/product/sku/del";
String MINISHOP_UPDATE_SKU_URL = "https://api.weixin.qq.com/product/sku/update";
String MINISHOP_UPDATE_SKU_PRICE_URL = "https://api.weixin.qq.com/product/sku/update_price";
String MINISHOP_UPDATE_SKU_STOCK_URL = "https://api.weixin.qq.com/product/stock/update";
/**
* 小商店新增sku信息
* @param appId
* @param sku
* @return
* @throws WxErrorException
*/
WxMinishopAddGoodsSpuResult<WxMinishopAddGoodsSkuData> minishiopGoodsAddSku(String appId, WxMinishopSku sku) throws WxErrorException;
/**
* 小商店批量新增sku信息
* @param appId
* @param skuList
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsBatchAddSku(String appId, List<WxMinishopSku> skuList) throws WxErrorException;
/**
* 小商店删除sku消息
* @param appId
* @param productId
* @param outProductId
* @param outSkuId
* @param skuId
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsDelSku(String appId, Long productId, Long outProductId, String outSkuId, Long skuId) throws WxErrorException;
/**
* 小商店更新sku
* @param appId
* @param sku
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsUpdateSku(String appId, WxMinishopSku sku) throws WxErrorException;
/**
* 小商店更新sku价格
* @param appId
* @param productId
* @param outProductId
* @param outSkuId
* @param skuId
* @param salePrice
* @param marketPrice
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsUpdateSkuPrice(String appId, Long productId, Long outProductId, String outSkuId, Long skuId, Long salePrice, Long marketPrice) throws WxErrorException;
/**
* 小商店更新sku库存
* @param appId
* @param productId
* @param outProductId
* @param outSkuId
* @param skuId
* @param type
* @param stockNum
* @return
* @throws WxErrorException
*/
WxOpenResult minishopGoodsUpdateSkuStock(String appId, Long productId, Long outProductId, String outSkuId, Long skuId, Integer type, Integer stockNum) throws WxErrorException;
/**
* 小商店通用Post接口
* @param appId
* @param url
* @param requestParam
* @return
* @throws WxErrorException
*/
String minishopCommonPost(String appId, String url, String requestParam) throws WxErrorException;
//////////////////////////////////////////////////////////////
//商品抢购任务-秒杀活动
String API_MINISHOP_ADD_LIMIT_DISCOUNT_URL = "https://api.weixin.qq.com/product/limiteddiscount/add/";
String API_MINISHOP_GET_LIMIT_DISCOUNT_URL = "https://api.weixin.qq.com/product/limiteddiscount/get_list/";
String API_MINISHOP_UPDATE_LIMIT_DICOUNT_STATUS_URL = "https://api.weixin.qq.com/product/limiteddiscount/update_status/";
/**
* 添加抢购任务
* 每个商品(SPU)同一时间只能有一个抢购任务。 如果当前有抢购任务没有结束,无论是否开始,都不允许创建第二个抢购任务 可以提前修改抢购任务状态为结束后,再创建新的任务。 每次创建抢购任务时必须填充该SPU下 所有SKU的抢购信息
* @param appId
* @param limitDiscountGoods
* @return
* @throws WxErrorException
*/
Integer addLimitDiscountGoods(String appId, LimitDiscountGoods limitDiscountGoods) throws WxErrorException;
/**
* status为0代表 还未结束的抢购任务,无论是否开始 status为1代表已经结束的 抢购任务 如果不填status则两种都拉取
* @param appId
* @param status
* @return
*/
List<LimitDiscountGoods> getLimitDiscountList(String appId, Integer status) throws WxErrorException;
/**
* 修改抢购任务状态
* 用于提前结束抢购任务,无论抢购任务是否在执行中,都可以关闭。 也可以直接删除抢购任务 注意:结束后不允许再开启,状态不可逆
* @param appId
* @param taskId
* @param status
* @return
*/
WxOpenResult updateLimitDiscountStatus(String appId, Long taskId, Integer status) throws WxErrorException;
}

View File

@@ -3,6 +3,7 @@ package me.chanjar.weixin.open.api;
import cn.binarywang.wx.miniapp.api.WxMaService;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo;
import me.chanjar.weixin.open.bean.ma.WxMaScheme;
import me.chanjar.weixin.open.bean.message.WxOpenMaSubmitAuditMessage;
import me.chanjar.weixin.open.bean.result.*;
@@ -220,6 +221,17 @@ public interface WxOpenMaService extends WxMaService {
*/
String API_SPEED_AUDIT = "https://api.weixin.qq.com/wxa/speedupaudit";
/**
* 获取小程序scheme码
*/
String API_GENERATE_SCHEME = "https://api.weixin.qq.com/wxa/generatescheme";
/**
* 通过此接口开通自定义版交易组件,将同步返回接入结果,不再有异步事件回调。
*/
String API_REGISTER_SHOP_COMPONENT = "https://api.weixin.qq.com/shop/register/apply";
/**
* 获得小程序的域名配置信息
*
@@ -594,6 +606,14 @@ public interface WxOpenMaService extends WxMaService {
*/
WxOpenResult publishQrcodeJump(String prefix) throws WxErrorException;
WxMaScheme generateMaScheme(String jumpWxaPath, String jumpWxaQuery, Boolean isExpire, Long expireTime) throws WxErrorException;
/**
* 为小程序开通小商店组件
* @return
*/
WxOpenResult registerShopComponent() throws WxErrorException;
/**
* 小程序基础信息服务 (小程序名称、头像、描述、类目等信息设置)
*

View File

@@ -0,0 +1,120 @@
package me.chanjar.weixin.open.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.bean.minishopGoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopGoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopGoods.ParentCatId;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
/**
* 微信小商城 商品
* @author xiaojintao
*/
public interface WxOpenMinishopGoodsService {
/**
* 获取类目详情 接入商品前必须接口
*/
String getMinishopGoodsCatUrl = "https://api.weixin.qq.com/product/category/get";
/**
* SPU接口(修改需要重新上架商品) 添加商品 POST
*/
String addMinishopGoodsSPUUrl = "https://api.weixin.qq.com/product/spu/add";
/**
* SPU接口(修改需要重新上架商品) 删除商品 POST
*/
String delMinishopGoodsSPUUrl = "https://api.weixin.qq.com/product/spu/del";
/**
* SPU接口(修改需要重新上架商品) 获取商品 POST
*/
String getMinishopGoodsSPUUrl = "https://api.weixin.qq.com/product/spu/get";
/**
* SPU接口(修改需要重新上架商品) 获取商品列表 POST
*/
String getListMinishopGoodsSPUURL = "https://api.weixin.qq.com/product/spu/get_list";
/**
* SPU接口(修改需要重新上架商品) 搜索商品 POST
*/
String searchMinishopGoodsSPUURL = "https://api.weixin.qq.com/product/spu/search";
/**
* SPU接口(修改需要重新上架商品) 更新商品 POST
*/
String updateMinishopGoodsSPUUrl = "https://api.weixin.qq.com/product/spu/update";
/**
* SPU接口(修改需要重新上架商品) 上架商品 POST
*/
String listingMinishopGoodsSPUUrl = "https://api.weixin.qq.com/product/spu/listing";
/**
* SPU接口(修改需要重新上架商品) 下架商品 POST
*/
String delistingMinishopGoodsSPUUrl = "https://api.weixin.qq.com/product/spu/delisting";
/**
* SKU接口(修改后需重新上架商品) 添加SKU POST
*/
String addMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/add";
/**
* SKU接口(修改后需重新上架商品) 批量添加SKU POST
*/
String batchAddMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/batch_add";
/**
* SKU接口(修改后需重新上架商品) 批量添加SKU POST
*/
String delMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/del";
/**
* SKU接口(修改后需重新上架商品) 获取SKU信息 POST
*/
String getMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/get";
/**
* SKU接口(修改后需重新上架商品) 批量获取SKU信息 POST
*/
String getListMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/get_list";
/**
* SKU接口(修改后需重新上架商品) 批量获取SKU信息 POST
*/
String updateMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/update";
/**
* SKU接口(修改后需重新上架商品) 更新SKU价格 POST
*/
String updatePriceMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/sku/update_price";
/**
* SKU接口(修改后需重新上架商品) 更新库存 POST
*/
String updateStockMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/stock/update";
/**
* SKU接口(修改后需重新上架商品) 获取库存 POST
*/
String getStockMinishopGoodsSKUUrl = "https://api.weixin.qq.com/product/stock/get";
/**
* 获取 商品类目
*/
GoodsCatList getMinishopGoodsCat(ParentCatId fCatId) throws WxErrorException;
/**
* 新增商品SPU
* @param dto
* @return
*/
WxOpenResult addMinishopGoodsSPU(AddMinishopGoodsSPU dto) throws WxErrorException;
}

View File

@@ -0,0 +1,57 @@
package me.chanjar.weixin.open.api;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.bean.minishop.*;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
import java.io.File;
/**
* 微信小商店开店接口
* add by kelven 2021-01-29
*/
public interface WxOpenMinishopService {
String submitMerchantInfoUrl = "https://api.weixin.qq.com/product/register/submit_merchantinfo";
String submitBasicInfoUrl = "https://api.weixin.qq.com/product/register/submit_basicinfo";
public final static String UPLOAD_IMG_MINISHOP_FILE_URL = "https://api.weixin.qq.com/product/img/upload";
String getCategoryUrl = "https://api.weixin.qq.com/product/category/get";
String getBrandsUrl = "https://api.weixin.qq.com/product/brand/get";
String getDeliveryUrl = "https://api.weixin.qq.com/product/delivery/get_freight_template";
/**获取店铺的商品分类*/
String getShopCatUrl = "https://api.weixin.qq.com/product/store/get_shopcat";
/**
*
* @param appId
* @param subjectType
* @param busiLicense
* @param organizationCodeInfo
* @param idcardInfo
* @param superAdministratorInfo
* @param merchantShoprtName
* @return
*/
WxOpenResult submitMerchantInfo(String appId, String subjectType, MinishopBusiLicense busiLicense, MinishopOrganizationCodeInfo organizationCodeInfo, MinishopIdcardInfo idcardInfo, MinishopSuperAdministratorInfo superAdministratorInfo, String merchantShoprtName) throws WxErrorException;
WxOpenResult submitBasicInfo(String appId, MinishopNameInfo nameInfo, MinishopReturnInfo returnInfo);
MinishopAuditStatus checkAuditStatus(String wxName) throws WxErrorException;
String uploadImagePicFile(Integer height, Integer width, File file) throws WxErrorException;
MinishopCategories getCategory(Integer fCatId);
MinishopBrandList getBrands();
MinishopShopCatList getShopCat();
}

View File

@@ -1,7 +1,11 @@
package me.chanjar.weixin.open.api;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import java.io.File;
/**
* The interface Wx open service.
*
@@ -49,4 +53,7 @@ public interface WxOpenService {
*/
String post(String url, String postData) throws WxErrorException;
WxMinishopImageUploadResult uploadMinishopMediaFile(String url, File file) throws WxErrorException;
}

View File

@@ -1,11 +1,16 @@
package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
@@ -28,6 +33,13 @@ import me.chanjar.weixin.open.bean.WxOpenGetResult;
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
import me.chanjar.weixin.open.bean.minishop.*;
import me.chanjar.weixin.open.bean.minishop.coupon.WxMinishopCoupon;
import me.chanjar.weixin.open.bean.minishop.coupon.WxMinishopCouponStock;
import me.chanjar.weixin.open.bean.minishop.goods.*;
import me.chanjar.weixin.open.bean.minishop.limitdiscount.LimitDiscountGoods;
import me.chanjar.weixin.open.bean.minishop.limitdiscount.LimitDiscountSku;
import me.chanjar.weixin.open.bean.result.*;
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult;
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerListResult;
import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerOptionResult;
@@ -36,6 +48,10 @@ import me.chanjar.weixin.open.bean.result.WxOpenResult;
import me.chanjar.weixin.open.util.json.WxOpenGsonBuilder;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -53,6 +69,8 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
private static final Map<String, WxOpenMpService> WX_OPEN_MP_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxOpenFastMaService> WX_OPEN_FAST_MA_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxOpenMinishopService> WX_OPEN_MINISHOP_SERVICE_MAP = new ConcurrentHashMap<>();
private final WxOpenService wxOpenService;
@Override
@@ -112,6 +130,22 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return fastMaService;
}
@Override
public WxOpenMinishopService getWxMinishopServiceByAppid(String appId) {
WxOpenMinishopService minishopService = WX_OPEN_MINISHOP_SERVICE_MAP.get(appId);
if (minishopService == null) {
synchronized (WX_OPEN_MINISHOP_SERVICE_MAP) {
minishopService = WX_OPEN_MINISHOP_SERVICE_MAP.get(appId);
if (minishopService == null) {
minishopService = new WxOpenMinishopServiceImpl(this, appId, getWxOpenConfigStorage().getWxMaConfig(appId));
WX_OPEN_MINISHOP_SERVICE_MAP.put(appId, minishopService);
}
}
}
return minishopService;
}
public WxOpenService getWxOpenService() {
return wxOpenService;
}
@@ -590,4 +624,575 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
String response = post(FAST_REGISTER_WEAPP_SEARCH_URL, jsonObject.toString(), "component_access_token");
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult registerShop(String wxName, String idCardName, String idCardNumber, String channelId, Integer apiOpenstoreType, String authPageUrl) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("wx_name", wxName);
jsonObject.addProperty("id_card_name", idCardName);
jsonObject.addProperty("id_card_number", idCardNumber);
if (channelId != null && !channelId.isEmpty()) {
jsonObject.addProperty("channel_id", channelId);
}
jsonObject.addProperty("api_openstore_type", apiOpenstoreType);
if (authPageUrl != null && !authPageUrl.isEmpty()) {
jsonObject.addProperty("auth_page_url", authPageUrl);
}
String response = post(REGISTER_SHOP_URL, jsonObject.toString(), "component_access_token");
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public String checkAuditStatus(String wxName) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("wx_name", wxName);
String url = CHECK_SHOP_AUDITSTATUS_URL + "?access_token=" + getComponentAccessToken(false);
String response = post(url, jsonObject.toString());
log.info("CHECK_SHOP_AUDITSTATUS_URL: " + response);
return response;
}
@Override
public String checkAuditStatus(String appId, String wxName) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("wx_name", wxName);
String url = CHECK_SHOP_AUDITSTATUS_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
String response = post(url, jsonObject.toString());
log.info("CHECK_SHOP_AUDITSTATUS_URL: " + response);
return response;
}
@Override
public WxOpenResult submitMerchantInfo(String appId, String subjectType, MinishopBusiLicense busiLicense, MinishopOrganizationCodeInfo organizationCodeInfo, MinishopIdcardInfo idcardInfo, MinishopSuperAdministratorInfo superAdministratorInfo, String merchantShoprtName) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("app_id", appId);
jsonObject.addProperty("subject_type", subjectType);
jsonObject.add("busi_license", busiLicense.toJsonObject());
if (organizationCodeInfo != null) {
jsonObject.add("organization_code_info", organizationCodeInfo.toJsonObject());
}
if (idcardInfo != null) {
jsonObject.add("id_card_info", idcardInfo.toJsonObject());
}
if (superAdministratorInfo != null) {
jsonObject.add("super_administrator_info", superAdministratorInfo.toJsonObject());
}
if (merchantShoprtName != null) {
jsonObject.addProperty("merchant_shortname", merchantShoprtName);
}
String url = SUBMIT_MERCHANTINFO_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult submitBasicInfo(String appId, MinishopNameInfo nameInfo, MinishopReturnInfo returnInfo) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("appid", appId);
jsonObject.add("name_info", nameInfo.toJsonObject());
jsonObject.add("return_info", returnInfo.toJsonObject());
String url = SUBMIT_BASICINFO_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxMinishopImageUploadResult uploadMinishopImagePicFile(String appId, Integer height, Integer width, File file) throws WxErrorException {
String url = WxOpenMinishopService.UPLOAD_IMG_MINISHOP_FILE_URL + "?access_token="+getAuthorizerAccessToken(appId, false)+"&height="+height+"&width="+width;
log.info("upload url: " + url);
// String response = (url, file);
WxMinishopImageUploadResult result = getWxOpenService().uploadMinishopMediaFile(url, file);
return result;
}
@Override
public MinishopCategories getMinishopCategories(String appId, Integer fCatId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("f_cat_id", fCatId);
String url = MINISHOP_CATEGORY_GET_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
String response = getWxOpenService().post(url, jsonObject.toString());
log.info("response: " + response);
JsonObject respJson = GsonParser.parse(response);
MinishopCategories categories = new MinishopCategories();
categories.setErrcode(respJson.get("errcode").getAsInt());
if (categories.getErrcode() == 0) {
JsonArray catListJson = respJson.getAsJsonArray("cat_list");
if (catListJson != null || catListJson.size() > 0) {
List<MinishopCategory> categoryList = new ArrayList<>();
for (int i = 0; i < catListJson.size(); i++) {
JsonObject catJson = catListJson.get(i).getAsJsonObject();
MinishopCategory cate = new MinishopCategory();
cate.setCatId(catJson.get("cat_id").getAsInt());
cate.setFCatId(catJson.get("f_cat_id").getAsInt());
cate.setName(catJson.get("name").getAsString());
categoryList.add(cate);
}
categories.setCatList(categoryList);
}
} else {
categories.setErrmsg(respJson.get("errmsg").getAsString());
}
return categories;
}
@Override
public MinishopBrandList getMinishopBrands(String appId) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
String url = MINISHOP_BRAND_GET_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
MinishopBrandList brandList = new MinishopBrandList();
brandList.setErrcode(respJson.get("errcode").getAsInt());
if (brandList.getErrcode() == 0) {
JsonArray brandArrayJson = respJson.get("brands").getAsJsonArray();
if (brandArrayJson.size() > 0) {
List<MinishopBrand> brands = new ArrayList<>();
for (int i = 0; i < brandArrayJson.size(); i++) {
JsonObject brandJson = brandArrayJson.get(i).getAsJsonObject();
MinishopBrand brand = new MinishopBrand();
brand.setFirstCatId(brandJson.get("first_cat_id").getAsInt());
brand.setSecondCatId(brandJson.get("second_cat_id").getAsInt());
brand.setThirdCatId(brandJson.get("third_cat_id").getAsInt());
MinishopBrand.MinishopBrandInfo brandInfo = new MinishopBrand.MinishopBrandInfo();
JsonObject brandInfoJson = brandJson.get("brand_info").getAsJsonObject();
brandInfo.setBrandId(brandInfoJson.get("brand_id").getAsInt());
brandInfo.setBrandName(brandInfoJson.get("brand_name").getAsString());
brand.setBrandInfo(brandInfo);
brands.add(brand);
}
brandList.setBrands(brands);
}
} else {
brandList.setErrmsg(respJson.get("errmsg").getAsString());
}
return brandList;
}
@Override
public MinishopDeliveryTemplateResult getMinishopDeliveryTemplate(String appId) throws WxErrorException {
String url = MINISHOP_DELIVERY_TEMPLATE_GET_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
JsonObject jsonObject = new JsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
MinishopDeliveryTemplateResult templateResult = new MinishopDeliveryTemplateResult();
templateResult.setErrCode(respJson.get("errcode").getAsInt());
if (templateResult.getErrCode() == 0) {
JsonArray templateArrayJson = respJson.get("template_list").getAsJsonArray();
if (templateArrayJson.size() > 0) {
List<MinishopDeliveryTemplate> templateList = new ArrayList<>();
for (int i = 0; i < templateArrayJson.size(); i++) {
JsonObject templateJson = templateArrayJson.get(i).getAsJsonObject();
MinishopDeliveryTemplate template = new MinishopDeliveryTemplate();
template.setTemplateId(templateJson.get("template_id").getAsInt());
template.setName(templateJson.get("name").getAsString());
template.setValuationType(templateJson.get("valuation_type").getAsInt() == 1 ? MinishopDeliveryTemplate.ValuationType.WEIGHT : MinishopDeliveryTemplate.ValuationType.PACKAGE);
templateList.add(template);
}
templateResult.setTemplateList(templateList);
}
} else {
templateResult.setErrMsg(respJson.get("errmsg").getAsString());
}
return templateResult;
}
@Override
public MinishopShopCatList getMinishopCatList(String appId) throws WxErrorException {
String url = MINISHOP_SHOPCATEGORY_GET_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
JsonObject jsonObject = new JsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
MinishopShopCatList shopCatList = new MinishopShopCatList();
shopCatList.setErrcode(respJson.get("errcode").getAsInt());
if (shopCatList.getErrcode() == 0) {
JsonArray shopcatArrayJson = respJson.get("shopcat_list").getAsJsonArray();
if (shopcatArrayJson.size() > 0) {
List<MinishopShopCat> shopCats = new ArrayList<>();
for (int i = 0; i < shopcatArrayJson.size(); i++) {
JsonObject shopCatJson = shopcatArrayJson.get(i).getAsJsonObject();
MinishopShopCat shopCat = new MinishopShopCat();
shopCat.setShopCatId(shopCatJson.get("shopcat_id").getAsInt());
shopCat.setShopCatName(shopCatJson.get("shopcat_name").getAsString());
shopCat.setFShopCatId(shopCatJson.get("f_shopcat_id").getAsInt());
shopCat.setCatLevel(shopCatJson.get("cat_level").getAsInt());
shopCats.add(shopCat);
}
shopCatList.setShopCatList(shopCats);
}
} else {
shopCatList.setErrmsg(respJson.get("errmsg").getAsString());
}
return shopCatList;
}
@Override
public WxMinishopAddGoodsSpuResult<List<WxMinishopDeliveryCompany>> getMinishopDeliveryCompany(String appId) throws WxErrorException {
String url = MINISHOP_GET_DELIVERY_COMPANY_URL + "?access_token=" + getAuthorizerAccessToken(appId, false);
JsonObject jsonObject = new JsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
if (result.getErrcode() == 0) {
JsonArray companyArray = respObj.get("company_list").getAsJsonArray();
List<WxMinishopDeliveryCompany> companies = new ArrayList<>();
for (int i = 0; i < companyArray.size(); i++) {
JsonObject company = companyArray.get(i).getAsJsonObject();
WxMinishopDeliveryCompany resultData = new WxMinishopDeliveryCompany();
resultData.setDeliveryId(company.get("delivery_id").getAsString());
resultData.setDeliveryName(company.get("delivery_name").getAsString());
companies.add(resultData);
}
result.setData(companies);
} else {
result.setErrmsg(respObj.get("errmsg").getAsString());
}
return result;
}
@Override
public Integer minishopCreateCoupon(String appId, WxMinishopCoupon couponInfo) throws WxErrorException {
String url = MINISHOP_CREATE_COUPON_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = couponInfo.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
Integer couponId = -1;
if (respJson.get("errcode").getAsInt() == 0) {
JsonObject dataJson = respJson.get("data").getAsJsonObject();
couponId = dataJson.get("coupon_id").getAsInt();
}
return couponId;
}
@Override
public WxMinishopCouponStock minishopGetCouponList(String appId, String startCreateTime, String endCreateTime, Integer status, Integer page, Integer pageSize) throws WxErrorException {
String url = MINISHOP_GET_COUPON_LIST + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
return null;
}
@Override
public WxOpenResult minishopPushCouponToUser(String appId, String openId, Integer couponId) throws WxErrorException {
String url = MINISHOP_PUSH_COUPON + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("openid", openId);
jsonObject.addProperty("coupon_id", couponId);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public Integer minishopUpdateCoupon(String appId, WxMinishopCoupon couponInfo) throws WxErrorException {
String url = MINISHOP_UPDATE_COUPON_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = couponInfo.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respJson = GsonParser.parse(response);
Integer couponId = -1;
if (respJson.get("errcode").getAsInt() == 0) {
JsonObject dataJson = respJson.get("data").getAsJsonObject();
couponId = dataJson.get("coupon_id").getAsInt();
}
return couponId;
}
@Override
public WxOpenResult minishopUpdateCouponStatus(String appId, Integer couponId, Integer status) throws WxErrorException {
String url = MINISHOP_UPDATE_COUPON_STATUS_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("coupon_id", couponId);
jsonObject.addProperty("status", status);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxMinishopAddGoodsSpuResult<WxMinishopAddGoodsSpuData> minishopGoodsAddSpu(String appId, WxMinishopSpu spu) throws WxErrorException {
String url = MINISHOP_ADD_SPU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = spu.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
if (result.getErrcode() == 0) {
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
resultData.setProductId(dataObj.get("product_id").getAsLong());
resultData.setOutProductId(dataObj.get("out_product_id").getAsString());
resultData.setCreateTime(dataObj.get("create_time").getAsString());
result.setData(resultData);
} else {
result.setErrmsg(respObj.get("errmsg").getAsString());
}
return result;
}
@Override
public WxOpenResult minishopGoodsDelSpu(String appId, Long productId, Long outProductId) throws WxErrorException {
String url = MINISHOP_DEL_SPU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("product_id", productId);
jsonObject.addProperty("out_product_id", outProductId.toString());
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxMinishopAddGoodsSpuResult<WxMinishopAddGoodsSpuData> minishopGoodsUpdateSpu(String appId, WxMinishopSpu spu) throws WxErrorException {
String url = MINISHOP_UPDATE_SPU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = spu.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
if (result.getErrcode() == 0) {
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSpuData resultData = new WxMinishopAddGoodsSpuData();
resultData.setProductId(dataObj.get("product_id").getAsLong());
resultData.setOutProductId(dataObj.get("out_product_id").getAsString());
resultData.setCreateTime(dataObj.get("update_time").getAsString());
result.setData(resultData);
} else {
result.setErrmsg(respObj.get("errmsg").getAsString());
}
return result;
}
@Override
public WxOpenResult minishopGoodsListingSpu(String appId, Long productId, Long outProductId) throws WxErrorException {
String url = MINISHOP_LISTING_SPU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("product_id", productId);
jsonObject.addProperty("out_product_id", outProductId.toString());
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult minishopGoodsDelistingSpu(String appId, Long productId, Long outProductId) throws WxErrorException {
String url = MINISHOP_DELISTING_SPU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("product_id", productId);
jsonObject.addProperty("out_product_id", outProductId.toString());
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxMinishopAddGoodsSpuResult<WxMinishopAddGoodsSkuData> minishiopGoodsAddSku(String appId, WxMinishopSku sku) throws WxErrorException {
String url = MINISHOP_ADD_SKU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = sku.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
WxMinishopAddGoodsSpuResult result = new WxMinishopAddGoodsSpuResult();
result.setErrcode(respObj.get("errcode").getAsInt());
if (result.getErrcode() == 0) {
JsonObject dataObj = respObj.get("data").getAsJsonObject();
WxMinishopAddGoodsSkuData resultData = new WxMinishopAddGoodsSkuData();
resultData.setSkuId(dataObj.get("sku_id").getAsLong());
resultData.setCreateTime(dataObj.get("create_time").getAsString());
result.setData(resultData);
} else {
result.setErrmsg(respObj.get("errmsg").getAsString());
}
return result;
}
@Override
public WxOpenResult minishopGoodsBatchAddSku(String appId, List<WxMinishopSku> skuList) throws WxErrorException {
String url = MINISHOP_BATCH_ADD_SKU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
for (WxMinishopSku sku : skuList) {
jsonArray.add(sku.toJsonObject());
}
jsonObject.add("skus", jsonArray);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult minishopGoodsDelSku(String appId, Long productId, Long outProductId, String outSkuId, Long skuId) throws WxErrorException {
String url = MINISHOP_DEL_SKU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("product_id", productId);
jsonObject.addProperty("out_product_id", outProductId);
jsonObject.addProperty("sku_id", skuId);
jsonObject.addProperty("out_sku_id", outSkuId);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult minishopGoodsUpdateSku(String appId, WxMinishopSku sku) throws WxErrorException {
String url = MINISHOP_UPDATE_SKU_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = sku.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult minishopGoodsUpdateSkuPrice(String appId, Long productId, Long outProductId, String outSkuId, Long skuId, Long salePrice, Long marketPrice) throws WxErrorException {
String url = MINISHOP_UPDATE_SKU_PRICE_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("product_id", productId);
jsonObject.addProperty("out_product_id", outProductId);
jsonObject.addProperty("sku_id", skuId);
jsonObject.addProperty("out_sku_id", outSkuId);
jsonObject.addProperty("sale_price", outSkuId);
jsonObject.addProperty("market_price", outSkuId);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxOpenResult minishopGoodsUpdateSkuStock(String appId, Long productId, Long outProductId, String outSkuId, Long skuId, Integer type, Integer stockNum) throws WxErrorException {
String url = MINISHOP_UPDATE_SKU_STOCK_URL + "?access_token=" + getAuthorizerAccessToken(appId, true);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("product_id", productId);
jsonObject.addProperty("out_product_id", outProductId);
jsonObject.addProperty("sku_id", skuId);
jsonObject.addProperty("out_sku_id", outSkuId);
jsonObject.addProperty("type", type);
jsonObject.addProperty("stock_num", stockNum);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public String minishopCommonPost(String appId, String url, String requestParam) throws WxErrorException {
return null;
}
@Override
public Integer addLimitDiscountGoods(String appId, LimitDiscountGoods limitDiscountGoods) throws WxErrorException {
String url = API_MINISHOP_ADD_LIMIT_DISCOUNT_URL + "access_token=" + getAuthorizerAccessToken(appId, false);
JsonObject jsonObject = limitDiscountGoods.toJsonObject();
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
Integer taskId = 0;
if (respObj.get("errcode").getAsInt() == 0) {
taskId = respObj.get("task_id").getAsInt();
}
return taskId;
}
@Override
public List<LimitDiscountGoods> getLimitDiscountList(String appId, Integer status) throws WxErrorException {
String url = API_MINISHOP_GET_LIMIT_DISCOUNT_URL + "access_token=" + getAuthorizerAccessToken(appId, false);
JsonObject jsonObject = new JsonObject();
if (status != null) {
jsonObject.addProperty("status", status);
}
String response = getWxOpenService().post(url, jsonObject.toString());
JsonObject respObj = GsonParser.parse(response);
List<LimitDiscountGoods> limitDiscountGoodsList = new ArrayList<>();
if (respObj.get("errcode").getAsInt() == 0) {
//成功获取到秒杀活动列表
JsonArray jsonArray = respObj.get("limited_discount_list").getAsJsonArray();
if (jsonArray != null && jsonArray.size() > 0) {
for (int i = 0; i < jsonArray.size(); i ++) {
JsonObject goodsObj = jsonArray.get(i).getAsJsonObject();
LimitDiscountGoods discountGoods = new LimitDiscountGoods();
discountGoods.setTaskId(goodsObj.get("task_id").getAsLong());
discountGoods.setStatus(goodsObj.get("status").getAsInt());
discountGoods.setStartTime(new Date(goodsObj.get("start_time").getAsLong()*1000));
discountGoods.setEndTime(new Date(goodsObj.get("end_time").getAsLong()*1000));
List<LimitDiscountSku> skuList = new ArrayList<>();
JsonArray skuArray = goodsObj.get("limited_discount_sku_list").getAsJsonArray();
if (skuArray != null && skuArray.size() > 0) {
for (int j = 0; j < skuArray.size(); j ++) {
JsonObject skuObj = skuArray.get(i).getAsJsonObject();
LimitDiscountSku sku = new LimitDiscountSku();
sku.setSkuId(skuObj.get("sku_id").getAsLong());
sku.setSalePrice(new BigDecimal(skuObj.get("sale_price").getAsDouble() / 100));
sku.setSaleStock(skuObj.get("sale_stock").getAsInt());
skuList.add(sku);
}
discountGoods.setLimitDiscountSkuList(skuList);
}
limitDiscountGoodsList.add(discountGoods);
}
}
}
return limitDiscountGoodsList;
}
@Override
public WxOpenResult updateLimitDiscountStatus(String appId, Long taskId, Integer status) throws WxErrorException {
String url = API_MINISHOP_UPDATE_LIMIT_DICOUNT_STATUS_URL + "access_token=" + getAuthorizerAccessToken(appId, false);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("task_id", taskId);
jsonObject.addProperty("status", status);
String response = getWxOpenService().post(url, jsonObject.toString());
return WxOpenGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
}

View File

@@ -5,6 +5,8 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -14,6 +16,7 @@ import me.chanjar.weixin.open.api.WxOpenMaBasicService;
import me.chanjar.weixin.open.api.WxOpenMaService;
import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo;
import me.chanjar.weixin.open.bean.ma.WxMaQrcodeParam;
import me.chanjar.weixin.open.bean.ma.WxMaScheme;
import me.chanjar.weixin.open.bean.message.WxOpenMaSubmitAuditMessage;
import me.chanjar.weixin.open.bean.result.*;
import me.chanjar.weixin.open.executor.MaQrCodeRequestExecutor;
@@ -359,6 +362,40 @@ public class WxOpenMaServiceImpl extends WxMaServiceImpl implements WxOpenMaServ
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
@Override
public WxMaScheme generateMaScheme(String jumpWxaPath, String jumpWxaQuery, Boolean isExpire, Long expireTime) throws WxErrorException {
JsonObject jumpWxa = null;
if (jumpWxaPath != null && jumpWxaQuery != null) {
jumpWxa = new JsonObject();
jumpWxa.addProperty("path", jumpWxaPath);
jumpWxa.addProperty("query", jumpWxaQuery);
}
JsonObject params = new JsonObject();
if (jumpWxa != null) {
params.add("jump_wxa", jumpWxa);
}
if (isExpire != null) {
params.addProperty("is_expire", isExpire);
}
if (expireTime != null) {
params.addProperty("expire_time", expireTime);
}
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
String response = post(API_GENERATE_SCHEME, gson.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxMaScheme.class);
}
@Override
public WxOpenResult registerShopComponent() throws WxErrorException {
JsonObject params = new JsonObject();
String response = post(API_REGISTER_SHOP_COMPONENT, GSON.toJson(params));
return WxMaGsonBuilder.create().fromJson(response, WxOpenResult.class);
}
private JsonArray toJsonArray(List<String> strList) {
JsonArray jsonArray = new JsonArray();
if (strList != null && !strList.isEmpty()) {

View File

@@ -0,0 +1,37 @@
package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenMinishopGoodsService;
import me.chanjar.weixin.open.bean.minishopGoods.AddMinishopGoodsSPU;
import me.chanjar.weixin.open.bean.minishopGoods.GoodsCatList;
import me.chanjar.weixin.open.bean.minishopGoods.ParentCatId;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
@Slf4j
public class WxOpenMinishopGoodsServiceImpl extends WxMaServiceImpl implements WxOpenMinishopGoodsService {
@Override
public GoodsCatList getMinishopGoodsCat(ParentCatId dto) throws WxErrorException {
String response = post(getMinishopGoodsCatUrl, dto.toJsonObject().toString());
log.info(response);
return null;
}
@Override
public WxOpenResult addMinishopGoodsSPU(AddMinishopGoodsSPU dto) throws WxErrorException {
String response = post(addMinishopGoodsSPUUrl, dto.toJsonObject().toString());
return null;
}
}

View File

@@ -0,0 +1,80 @@
package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenComponentService;
import me.chanjar.weixin.open.api.WxOpenMinishopService;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.bean.minishop.*;
import me.chanjar.weixin.open.bean.result.WxOpenResult;
import java.io.File;
@Slf4j
public class WxOpenMinishopServiceImpl extends WxMaServiceImpl implements WxOpenMinishopService {
private final WxOpenComponentService wxOpenComponentService;
private final WxMaConfig wxMaConfig;
private final String appId;
public WxOpenMinishopServiceImpl(WxOpenComponentService wxOpenComponentService, String appId, WxMaConfig wxMaConfig) {
this.wxOpenComponentService = wxOpenComponentService;
this.appId = appId;
this.wxMaConfig = wxMaConfig;
log.info("appId: " + appId);
if (wxMaConfig == null) {
log.error("WxMaConfig is null");
}
this.addConfig(appId, wxMaConfig);
initHttp();
}
@Override
public WxOpenResult submitMerchantInfo(String appId, String subjectType, MinishopBusiLicense busiLicense, MinishopOrganizationCodeInfo organizationCodeInfo, MinishopIdcardInfo idcardInfo, MinishopSuperAdministratorInfo superAdministratorInfo, String merchantShoprtName) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("app_id", appId);
jsonObject.addProperty("subject_type", subjectType);
jsonObject.add("busi_license", busiLicense.toJsonObject());
jsonObject.add("organization_code_info", organizationCodeInfo.toJsonObject());
jsonObject.add("id_card_info", idcardInfo.toJsonObject());
jsonObject.add("super_administrator_info", superAdministratorInfo.toJsonObject());
String response = post(submitMerchantInfoUrl, jsonObject.toString());
return null;
}
@Override
public WxOpenResult submitBasicInfo(String appId, MinishopNameInfo nameInfo, MinishopReturnInfo returnInfo) {
return null;
}
@Override
public MinishopAuditStatus checkAuditStatus(String wxName) throws WxErrorException {
return null;
}
@Override
public String uploadImagePicFile(Integer height, Integer width, File file) throws WxErrorException {
String url = UPLOAD_IMG_MINISHOP_FILE_URL + "?access_token="+getAccessToken(true)+"&height="+height+"&width="+width;
log.info("upload url: " + url);
String response = post(url, file);
return response;
}
@Override
public MinishopCategories getCategory(Integer fCatId) {
return null;
}
@Override
public MinishopBrandList getBrands() {
return null;
}
@Override
public MinishopShopCatList getShopCat() {
return null;
}
}

View File

@@ -1,15 +1,17 @@
package me.chanjar.weixin.open.api.impl;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.bean.result.WxMinishopImageUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import org.apache.http.HttpHost;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.File;
/**
* apache-http方式实现
*
@@ -64,4 +66,9 @@ public class WxOpenServiceApacheHttpClientImpl extends WxOpenServiceAbstractImpl
public String post(String url, String postData) throws WxErrorException {
return execute(SimplePostRequestExecutor.create(this), url, postData);
}
@Override
public WxMinishopImageUploadResult uploadMinishopMediaFile(String url, File file) throws WxErrorException {
return execute(MinishopUploadRequestExecutor.create(this), url, file);
}
}