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

【微信小程序】小程序直播修复接口实现问题,增加挂件组件全局key接口 #2578

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -20,6 +21,7 @@
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>
Expand Down Expand Up @@ -94,4 +96,26 @@ public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer st
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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public boolean deleteSubanchor(Integer roomId) throws WxErrorException {
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));
Expand Down Expand Up @@ -390,7 +390,7 @@ public String getVideo(Integer roomId, Integer goodsId) throws WxErrorException
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ interface Goods {
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";
}

/**
Expand Down