🎨 #1753 小程序直播部分接口代码优化重构,对照官方文档补充新增参数

This commit is contained in:
Binary Wang
2020-09-12 09:58:06 +08:00
parent 19b033c41f
commit ef0b34bb92
12 changed files with 163 additions and 120 deletions

View File

@@ -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;
/**
* 获取商品状态

View File

@@ -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;
/**
* 获取直播房间列表.(分页)

View File

@@ -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++) {

View File

@@ -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) {