1
0
mirror of synced 2025-12-13 02:10:59 +08:00

🆕 #2578【小程序】小程序直播增加挂件组件全局key相关接口

This commit is contained in:
linlinjava
2022-04-05 23:09:59 +08:00
committed by GitHub
parent 100fd1f856
commit 2f2d51b53d
5 changed files with 63 additions and 3 deletions

View File

@@ -114,4 +114,32 @@ public interface WxMaLiveGoodsService {
* @throws WxErrorException .
*/
WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException;
/**
* 直播挂件设置全局key
* <pre>
* 若已设置此全局key且添加商品时未指定goodsKey字段则我们会使用此全局key作为该商品的goodsKey。 须注意的是若全局key已设定并添加了未指定goodsKey字段的商品之后再重新设定不一样的全局key则会导致先前的映射失效。 为了避免映射失效建议全局key只设定一次。
* 注意key必须为字符串数组
* 调用额度500次/一天
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/goods/setkey?access_token=
* </pre>
*
* @param goodsKey 全局key
* @return 设置是否成功
* @throws WxErrorException .
*/
boolean setKey(List<String> goodsKey) throws WxErrorException;
/**
* 查看当前设定的全局key
* <pre>
* 查看当前设定的全局key。
* 调用额度500次/一天
* http请求方式GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getkey?access_token=
* </pre>
*
* @return 全局key
* @throws WxErrorException .
*/
List<String> getKey() throws WxErrorException;
}

View File

@@ -386,7 +386,7 @@ public interface WxMaLiveService {
* <p>
* 调用额度10000次/一天
* <p>
* http请求方式GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN
* http请求方式POST https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN
* </pre>
* @param roomId 直播间id
* @param goodsId 商品ID

View File

@@ -9,6 +9,7 @@ import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonHelper;
@@ -20,6 +21,7 @@ import java.util.List;
import java.util.Map;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Goods.*;
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Code.GET_PAGE_URL;
/**
* <pre>
@@ -94,4 +96,26 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
return WxMaLiveResult.fromJson(jsonObject.toString());
}
@Override
public boolean setKey(List<String> goodsKey) throws WxErrorException {
Map<String, Object> map = new HashMap<>(1);
map.put("goodsKey", goodsKey);
this.wxMaService.post(SET_KEY, WxMaGsonBuilder.create().toJson(map));
return true;
}
@Override
public List<String> getKey() throws WxErrorException {
String responseContent = this.wxMaService.get(GET_KEY, null);
JsonObject jsonObject = GsonParser.parse(responseContent);
boolean vendorGoodsKey = jsonObject.has("vendorGoodsKey");
if (vendorGoodsKey) {
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("vendorGoodsKey"),
new TypeToken<List<String>>() {
}.getType());
} else {
return null;
}
}
}

View File

@@ -272,7 +272,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
public String getSubanchor(Integer roomId) throws WxErrorException {
Map<String, Object> map = new HashMap<>(1);
map.put(ROOM_ID, roomId);
String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, Joiner.on("&").withKeyValueSeparator("=").join(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -390,7 +390,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
Map<String, Object> map = new HashMap<>(2);
map.put(ROOM_ID, roomId);
map.put("goodsId", goodsId);
String responseContent = this.wxMaService.get(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map));
String responseContent = this.wxMaService.post(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map));
JsonObject jsonObject = GsonParser.parse(responseContent);
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));

View File

@@ -272,6 +272,14 @@ public class WxMaApiUrlConstants {
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";
/**
* 直播挂件设置全局 Key
*/
String SET_KEY = "https://api.weixin.qq.com/wxaapi/broadcast/goods/setkey";
/**
* 直播挂件获取全局 Key
*/
String GET_KEY = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getkey";
}
/**