mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-29 09:38:19 +08:00
🎨 #1753 小程序直播部分接口代码优化重构,对照官方文档补充新增参数
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.util.List;
|
||||
@ -37,7 +37,7 @@ public interface WxMaLiveGoodsService {
|
||||
* @return 返回auditId、goodsId
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
|
||||
WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 撤回审核
|
||||
@ -91,7 +91,7 @@ public interface WxMaLiveGoodsService {
|
||||
* @return 更新商品是否成功
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
|
||||
boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取商品状态
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.util.List;
|
||||
@ -31,7 +31,7 @@ public interface WxMaLiveService {
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException;
|
||||
Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取直播房间列表.(分页)
|
||||
|
||||
@ -2,16 +2,14 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaLiveGoodsService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import me.chanjar.weixin.common.enums.WxType;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
|
||||
@ -32,15 +30,9 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
private final WxMaService wxMaService;
|
||||
|
||||
@Override
|
||||
public WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("goodsInfo", goods);
|
||||
String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
public WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
|
||||
return WxMaLiveResult.fromJson(this.wxMaService.post(ADD_GOODS,
|
||||
WxMaGsonBuilder.create().toJson(ImmutableMap.of("goodsInfo", goods))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,11 +40,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
Map<String, Integer> map = new HashMap<>(4);
|
||||
map.put("auditId", auditId);
|
||||
map.put("goodsId", goodsId);
|
||||
String responseContent = this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -62,9 +50,6 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
map.put("goodsId", goodsId);
|
||||
String responseContent = this.wxMaService.post(AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return jsonObject.get("auditId").getAsString();
|
||||
}
|
||||
|
||||
@ -72,23 +57,15 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
public boolean deleteGoods(Integer goodsId) throws WxErrorException {
|
||||
Map<String, Integer> map = new HashMap<>(2);
|
||||
map.put("goodsId", goodsId);
|
||||
String responseContent = this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
|
||||
public boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("goodsInfo", goods);
|
||||
String responseContent = this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -97,11 +74,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("goods_ids", goodsIds);
|
||||
String responseContent = this.wxMaService.post(GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
return WxMaLiveResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,9 +82,6 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("status", status, "offset", offset, "limit", limit);
|
||||
String responseContent = wxMaService.get(GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
JsonArray goodsArr = jsonObject.getAsJsonArray("goods");
|
||||
if (goodsArr.size() > 0) {
|
||||
for (int i = 0; i < goodsArr.size(); i++) {
|
||||
|
||||
@ -2,8 +2,8 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaLiveService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -31,7 +31,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
|
||||
private final WxMaService wxMaService;
|
||||
|
||||
@Override
|
||||
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
|
||||
public Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
|
||||
String responseContent = this.wxMaService.post(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
package cn.binarywang.wx.miniapp.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 直播接口入参
|
||||
*
|
||||
* @author yjwang
|
||||
* @date 2020/4/5
|
||||
*/
|
||||
@Data
|
||||
public class WxMaLiveInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7285263767524755887L;
|
||||
|
||||
/**
|
||||
* 直播列表
|
||||
*/
|
||||
@Data
|
||||
public static class RoomInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7745775280267417154L;
|
||||
private String name;
|
||||
private Integer roomid;
|
||||
private String coverImg;
|
||||
private String shareImg;
|
||||
private Integer liveStatus;
|
||||
private Long startTime;
|
||||
private Long endTime;
|
||||
private String anchorName;
|
||||
private String anchorWechat;
|
||||
private String anchorImg;
|
||||
private Integer type;
|
||||
private Integer screenType;
|
||||
private Integer closeLike;
|
||||
private Integer closeGoods;
|
||||
private Integer closeComment;
|
||||
private List<Goods> goods;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
*/
|
||||
@Data
|
||||
public static class Goods implements Serializable {
|
||||
private static final long serialVersionUID = 5769245932149287574L;
|
||||
private Integer goodsId;
|
||||
private String coverImgUrl;
|
||||
private String url;
|
||||
private Integer priceType;
|
||||
private String price;
|
||||
private String price2;
|
||||
private String name;
|
||||
/**
|
||||
* 1, 2:表示是为api添加商品,否则是在MP添加商品
|
||||
*/
|
||||
private String thirdPartyTag;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.binarywang.wx.miniapp.bean.live;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 直播商品信息
|
||||
*/
|
||||
@Data
|
||||
public class WxMaLiveGoodInfo implements Serializable {
|
||||
private static final long serialVersionUID = 5769245932149287574L;
|
||||
private Integer goodsId;
|
||||
private String coverImgUrl;
|
||||
private String url;
|
||||
private Integer priceType;
|
||||
private String price;
|
||||
private String price2;
|
||||
private String name;
|
||||
/**
|
||||
* 1, 2:表示是为api添加商品,否则是在MP添加商品
|
||||
*/
|
||||
private String thirdPartyTag;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.binarywang.wx.miniapp.bean;
|
||||
package cn.binarywang.wx.miniapp.bean.live;
|
||||
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@ -18,8 +18,6 @@ import java.util.List;
|
||||
@Data
|
||||
public class WxMaLiveResult implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Integer errcode;
|
||||
private String errmsg;
|
||||
private Integer total;
|
||||
private Integer auditId;
|
||||
private Integer goodsId;
|
||||
@ -0,0 +1,86 @@
|
||||
package cn.binarywang.wx.miniapp.bean.live;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 直播间信息
|
||||
*/
|
||||
@Data
|
||||
public class WxMaLiveRoomInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7745775280267417154L;
|
||||
|
||||
/**
|
||||
* 直播间名字,最短3个汉字,最长17个汉字,1个汉字相当于2个字符
|
||||
**/
|
||||
private String name;
|
||||
/**
|
||||
* 背景图,填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;直播间背景图,图片规则:建议像素1080*1920,大小不超过2M
|
||||
**/
|
||||
private String coverImg;
|
||||
/**
|
||||
* 直播计划开始时间(开播时间需要在当前时间的10分钟后 并且 开始时间不能在 6 个月后)
|
||||
**/
|
||||
private Long startTime;
|
||||
/**
|
||||
* 直播计划结束时间(开播时间和结束时间间隔不得短于30分钟,不得超过24小时)
|
||||
**/
|
||||
private Long endTime;
|
||||
/**
|
||||
* 主播昵称,最短2个汉字,最长15个汉字,1个汉字相当于2个字符
|
||||
**/
|
||||
private String anchorName;
|
||||
/**
|
||||
* 主播微信号,如果未实名认证,需要先前往“小程序直播”小程序进行实名验证, 小程序二维码链接:https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
|
||||
**/
|
||||
private String anchorWechat;
|
||||
/**
|
||||
* 主播副号微信号,如果未实名认证,需要先前往“小程序直播”小程序进行实名验证, 小程序二维码链接:https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
|
||||
**/
|
||||
private String subAnchorWechat;
|
||||
/**
|
||||
* 分享图,填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;直播间分享图,图片规则:建议像素800*640,大小不超过1M;
|
||||
**/
|
||||
private String shareImg;
|
||||
/**
|
||||
* 购物直播频道封面图,填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html; 购物直播频道封面图,图片规则:建议像素800*800,大小不超过100KB;
|
||||
**/
|
||||
private String feedsImg;
|
||||
/**
|
||||
* 是否开启官方收录 【1: 开启,0:关闭】,默认开启收录
|
||||
**/
|
||||
private Integer isFeedsPublic;
|
||||
/**
|
||||
* 直播间类型 【1: 推流,0:手机直播】
|
||||
**/
|
||||
private Integer type;
|
||||
/**
|
||||
* 横屏、竖屏 【1:横屏,0:竖屏】(横屏:视频宽高比为16:9、4:3、1.85:1 ;竖屏:视频宽高比为9:16、2:3)
|
||||
**/
|
||||
private Integer screenType;
|
||||
/**
|
||||
* 是否关闭点赞 【0:开启,1:关闭】(若关闭,直播开始后不允许开启)
|
||||
**/
|
||||
private Integer closeLike;
|
||||
/**
|
||||
* 是否关闭货架 【0:开启,1:关闭】(若关闭,直播开始后不允许开启)
|
||||
**/
|
||||
private Integer closeGoods;
|
||||
/**
|
||||
* 是否关闭评论 【0:开启,1:关闭】(若关闭,直播开始后不允许开启)
|
||||
**/
|
||||
private Integer closeComment;
|
||||
/**
|
||||
* 是否关闭回放 【0:开启,1:关闭】默认关闭回放
|
||||
**/
|
||||
private Integer closeReplay;
|
||||
/**
|
||||
* 是否关闭分享 【0:开启,1:关闭】默认开启分享(直播开始后不允许修改)
|
||||
**/
|
||||
private Integer loseShare;
|
||||
/**
|
||||
* closeKf Number 否 是否关闭客服 【0:开启,1:关闭】 默认关闭客服
|
||||
**/
|
||||
private Integer closeKf;
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
@ -31,7 +31,7 @@ public class WxMaLiveGoodsServiceImplTest {
|
||||
//上传临时素材
|
||||
WxMediaUploadResult mediaUpload = this.wxService.getMediaService().uploadMedia("image", new File("E:\\1.png"));
|
||||
|
||||
WxMaLiveInfo.Goods goods = new WxMaLiveInfo.Goods();
|
||||
WxMaLiveGoodInfo goods = new WxMaLiveGoodInfo();
|
||||
goods.setCoverImgUrl(mediaUpload.getMediaId());
|
||||
goods.setName("宫廷奢华真丝四件套");
|
||||
goods.setPrice("1599");
|
||||
@ -64,7 +64,7 @@ public class WxMaLiveGoodsServiceImplTest {
|
||||
@Test
|
||||
public void updateGoods() throws Exception {
|
||||
|
||||
WxMaLiveInfo.Goods goods = new WxMaLiveInfo.Goods();
|
||||
WxMaLiveGoodInfo goods = new WxMaLiveGoodInfo();
|
||||
goods.setGoodsId(8);
|
||||
goods.setName("宫廷奢华真丝四件套");
|
||||
goods.setCoverImgUrl("http://mmbiz.qpic.cn/mmbiz_png/omYktZNGamuUQE0WPVfqdnLV61JDhluXOac7PiaoZeticFpcR7wvicC0aXUC2VXkl7r1gN0QSKosv2satn6oCFeiaQ/0");
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
|
||||
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
|
||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
@ -33,7 +33,7 @@ public class WxMaLiveServiceImplTest {
|
||||
//上传临时素材
|
||||
WxMediaUploadResult mediaUpload = this.wxService.getMediaService().uploadMedia("image", new File("E:\\1.png"));
|
||||
|
||||
WxMaLiveInfo.RoomInfo roomInfo = new WxMaLiveInfo.RoomInfo();
|
||||
WxMaLiveRoomInfo roomInfo = new WxMaLiveRoomInfo();
|
||||
roomInfo.setName("订阅通知直播间");
|
||||
roomInfo.setCoverImg(mediaUpload.getMediaId());
|
||||
Calendar c = Calendar.getInstance();
|
||||
|
||||
Reference in New Issue
Block a user