🆕 #2578【小程序】小程序直播增加挂件组件全局key相关接口
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user