Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加直播间商品相关操作接口 #1651

Merged
merged 4 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import me.chanjar.weixin.common.error.WxErrorException;

import java.util.List;

/**
* <pre>
* 直播间商品相关操作接口
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html
* Created by lipengjun on 2020/6/29.
* </pre>
*
* @author <a href="https://github.com/lipengjun92">lipengjun ([email protected])</a>
*/
public interface WxMaLiveGoodsService {
String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add";
String RESET_AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit";
String AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit";
String DELETE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete";
String UPDATE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update";
String GET_GOODS_WARE_HOUSE = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse";
String GET_APPROVED_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved";

/**
* 商品添加并提审
* <pre>
* 调用此接口上传并提审需要直播的商品信息,审核通过后商品录入【小程序直播】商品库
* 注意:开发者必须保存【商品ID】与【审核单ID】,如果丢失,则无法调用其他相关接口
* 调用额度:500次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=ACCESS_TOKEN
* </pre>
*
* @param goods 商品
* @return 返回auditId、goodsId
* @throws WxErrorException .
*/
WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;

/**
* 撤回审核
* <pre>
* 调用此接口,可撤回直播商品的提审申请,消耗的提审次数不返还
* 调用额度:500次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit?access_token=ACCESS_TOKEN
* <pre>
* @param auditId 审核单ID
* @param goodsId 商品ID
* @return 撤回审核是否成功
* @throws WxErrorException .
*/
boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException;

/**
* 重新提交审核
* <pre>
* 调用此接口,可撤回直播商品的提审申请,消耗的提审次数不返还
* 调用额度:500次/一天(与接口'商品添加并提审'共用500次限制)
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/audit?access_token=ACCESS_TOKEN
* <pre>
* @param goodsId 商品ID
* @return 审核单ID
* @throws WxErrorException .
*/
String auditGoods(Integer goodsId) throws WxErrorException;

/**
* 删除商品
* <pre>
* 调用此接口,可删除【小程序直播】商品库中的商品,删除后直播间上架的该商品也将被同步删除,不可恢复;
* 调用额度:1000次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=ACCESS_TOKEN
* <pre>
* @param goodsId 商品ID
* @return 删除商品是否成功
* @throws WxErrorException .
*/
boolean deleteGoods(Integer goodsId) throws WxErrorException;

/**
* 更新商品
* <pre>
* 调用此接口可以更新商品信息,审核通过的商品仅允许更新价格类型与价格,审核中的商品不允许更新,未审核的商品允许更新所有字段, 只传入需要更新的字段。
* 调用额度:1000次/一天
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/update?access_token=ACCESS_TOKEN
* </pre>
*
* @param goods 商品
* @return 更新商品是否成功
* @throws WxErrorException .
*/
boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;

/**
* 获取商品状态
* <pre>
* 调用此接口可获取商品的信息与审核状态
* 调用额度:1000次/一天
* http请求方式:POST https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=ACCESS_TOKEN
* <pre>
* @param goodsIds 商品ID集
* @return 商品状态信息
* @throws WxErrorException .
*/
WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorException;

/**
* 获取商品列表
* <pre>
* 调用此接口可获取商品列表
* 调用额度:10000次/一天
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token=ACCESS_TOKEN
* <pre>
* @param offset 分页条数起点
* @param limit 分页大小,默认30,不超过100
* @param status 商品状态,0:未审核。1:审核中,2:审核通过,3:审核驳回
* @return 商品列表
* @throws WxErrorException .
*/
WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.WxMaGetLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import me.chanjar.weixin.common.error.WxErrorException;

import java.util.List;
Expand All @@ -15,6 +15,22 @@
*/
public interface WxMaLiveService {
String GET_LIVE_INFO = "http://api.weixin.qq.com/wxa/business/getliveinfo";
String CREATE_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=%s";
String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods";

/**
* 创建直播间
* <pre>
* 调用此接口创建直播间,创建成功后将在直播间列表展示,调用额度:10000次/一天
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#1
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=ACCESS_TOKEN
* </pre>
*
* @param roomInfo 直播间信息
* @return .
* @throws WxErrorException .
*/
Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException;

/**
* 获取直播房间列表.(分页)
Expand All @@ -24,39 +40,54 @@ public interface WxMaLiveService {
* @return .
* @throws WxErrorException .
*/
WxMaGetLiveInfo getLiveInfo(Integer start, Integer limit) throws WxErrorException;
WxMaLiveInfo getLiveInfo(Integer start, Integer limit) throws WxErrorException;

/**
* 获取所有直播间信息(没有分页直接获取全部)
*
* @return
* @throws WxErrorException
*/
List<WxMaGetLiveInfo.RoomInfo> getLiveinfos() throws WxErrorException;
List<WxMaLiveInfo.RoomInfo> getLiveinfos() throws WxErrorException;

/**
*
* 获取直播房间回放数据信息.
*
* @param action 获取回放
* @param action 获取回放
* @param room_id 直播间 id
* @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
* @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
* @return
* @throws WxErrorException
*/
WxMaGetLiveInfo getLiveReplay(String action, Integer room_id, Integer start, Integer limit) throws WxErrorException;
WxMaLiveInfo getLiveReplay(String action, Integer room_id, Integer start, Integer limit) throws WxErrorException;

/**
*
* 获取直播房间回放数据信息.
* <p>
* 获取回放 (默认:get_replay)
*
* 获取回放 (默认:get_replay)
* @param room_id 直播间 id
* @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
* @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
* @return
* @throws WxErrorException
*/
WxMaGetLiveInfo getLiveReplay(Integer room_id, Integer start, Integer limit) throws WxErrorException;
WxMaLiveInfo getLiveReplay(Integer room_id, Integer start, Integer limit) throws WxErrorException;

/**
* 直播间导入商品
* <p>
* 调用接口往指定直播间导入已入库的商品
* 调用频率
* 调用额度:10000次/一天
* <p>
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods?access_token=ACCESS_TOKEN
* <pre>
* @param roomId 房间ID
* @param goodsIds 数组列表,可传入多个,里面填写 商品 ID
* @return 导入商品是否成功
* @throws WxErrorException .
*/
boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cn.binarywang.wx.miniapp.api;

import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;

import java.io.File;

/**
* <pre>
* 素材管理的相关接口
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html
* Created by lipengjun on 2020/6/29.
* </pre>
*
* @author <a href="https://github.com/lipengjun92">lipengjun ([email protected])</a>
*/
public interface WxMaMaterialService {
String MEDIA_UPLOAD_URL = "https://api.weixin.qq.com/cgi-bin/media/upload?type=%s";
/**
* <pre>
* 新增临时素材
* 小程序获取临时素材,用于直播间商品
* 素材管理接口对所有认证的订阅号和服务号开放。通过本接口,小程序可以新增临时素材(即上传临时多媒体文件),返回的mediaId用于直播间商品使用。
* 请注意:
* 1、对于临时素材,每个素材(media_id)会在开发者上传或粉丝发送到微信服务器3天后自动删除(所以用户发送给开发者的素材,若开发者需要,应尽快下载到本地),以节省服务器资源。
* 2、media_id是可复用的。
* 3、素材的格式大小等要求与公众平台官网一致。具体是,图片大小不超过2M,支持png/jpeg/jpg/gif格式,语音大小不超过5M,长度不超过60秒,支持mp3/amr格式
* 4、需使用https调用本接口。
* 本接口即为原“上传多媒体文件”接口。
* 注意事项:
* 上传的临时多媒体文件有格式和大小限制,如下:
* 图片(image): 2M,支持PNG\JPEG\JPG\GIF格式
* 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
* 视频(video):10MB,支持MP4格式
* 缩略图(thumb):64KB,支持JPG格式
* 媒体文件在后台保存时间为3天,即3天后media_id失效。
* 详情请见: <a href="http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738726&token=&lang=zh_CN">新增临时素材</a>
* 接口url格式:https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE
* </pre>
*
* @param mediaType 媒体类型, 请看{@link me.chanjar.weixin.common.api.WxConsts}
* @param file 文件对象
* @throws WxErrorException
*/
WxMediaUploadResult mediaUpload(String mediaType, File file) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,18 @@ public interface WxMaService extends WxService {
* @return .
*/
WxMaLiveService getLiveService();

/**
* 获取直播间商品服务对象
*
* @return .
*/
WxMaLiveGoodsService getLiveGoodsService();

/**
* 获取小程序素材管理服务对象
*
* @return .
*/
WxMaMaterialService getMaterialService();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaSubscribeService subscribeService = new WxMaSubscribeServiceImpl(this);
private final WxMaCloudService cloudService = new WxMaCloudServiceImpl(this);
private final WxMaLiveService liveService = new WxMaLiveServiceImpl(this);
private final WxMaLiveGoodsService liveGoodsService = new WxMaLiveGoodsServiceImpl(this);
private final WxMaMaterialService maMaterialService = new WxMaMaterialServiceImpl(this);

private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
Expand Down Expand Up @@ -394,4 +396,14 @@ public WxMaCloudService getCloudService() {
public WxMaLiveService getLiveService() {
return this.liveService;
}

@Override
public WxMaLiveGoodsService getLiveGoodsService() {
return this.liveGoodsService;
}

@Override
public WxMaMaterialService getMaterialService() {
return this.maMaterialService;
}
}
Loading