Skip to content

Commit 2f2d51b

Browse files
authored
🆕 #2578【小程序】小程序直播增加挂件组件全局key相关接口
1 parent 100fd1f commit 2f2d51b

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveGoodsService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,32 @@ public interface WxMaLiveGoodsService {
114114
* @throws WxErrorException .
115115
*/
116116
WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException;
117+
118+
/**
119+
* 直播挂件设置全局key
120+
* <pre>
121+
* 若已设置此全局key,且添加商品时未指定goodsKey字段,则我们会使用此全局key作为该商品的goodsKey。 须注意的是,若全局key已设定,并添加了未指定goodsKey字段的商品之后,再重新设定不一样的全局key则会导致先前的映射失效。 为了避免映射失效,建议全局key只设定一次。
122+
* 注意:key必须为字符串数组
123+
* 调用额度:500次/一天
124+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/setkey?access_token=
125+
* </pre>
126+
*
127+
* @param goodsKey 全局key
128+
* @return 设置是否成功
129+
* @throws WxErrorException .
130+
*/
131+
boolean setKey(List<String> goodsKey) throws WxErrorException;
132+
133+
/**
134+
* 查看当前设定的全局key
135+
* <pre>
136+
* 查看当前设定的全局key。
137+
* 调用额度:500次/一天
138+
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getkey?access_token=
139+
* </pre>
140+
*
141+
* @return 全局key
142+
* @throws WxErrorException .
143+
*/
144+
List<String> getKey() throws WxErrorException;
117145
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public interface WxMaLiveService {
386386
* <p>
387387
* 调用额度:10000次/一天
388388
* <p>
389-
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN
389+
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/getVideo?access_token=ACCESS_TOKEN
390390
* </pre>
391391
* @param roomId 直播间id
392392
* @param goodsId 商品ID

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.common.collect.ImmutableMap;
1010
import com.google.gson.JsonArray;
1111
import com.google.gson.JsonObject;
12+
import com.google.gson.reflect.TypeToken;
1213
import lombok.RequiredArgsConstructor;
1314
import me.chanjar.weixin.common.error.WxErrorException;
1415
import me.chanjar.weixin.common.util.json.GsonHelper;
@@ -20,6 +21,7 @@
2021
import java.util.Map;
2122

2223
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Broadcast.Goods.*;
24+
import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Code.GET_PAGE_URL;
2325

2426
/**
2527
* <pre>
@@ -94,4 +96,26 @@ public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer st
9496
return WxMaLiveResult.fromJson(jsonObject.toString());
9597
}
9698

99+
@Override
100+
public boolean setKey(List<String> goodsKey) throws WxErrorException {
101+
Map<String, Object> map = new HashMap<>(1);
102+
map.put("goodsKey", goodsKey);
103+
this.wxMaService.post(SET_KEY, WxMaGsonBuilder.create().toJson(map));
104+
return true;
105+
}
106+
107+
@Override
108+
public List<String> getKey() throws WxErrorException {
109+
String responseContent = this.wxMaService.get(GET_KEY, null);
110+
JsonObject jsonObject = GsonParser.parse(responseContent);
111+
boolean vendorGoodsKey = jsonObject.has("vendorGoodsKey");
112+
if (vendorGoodsKey) {
113+
return WxMaGsonBuilder.create().fromJson(jsonObject.getAsJsonArray("vendorGoodsKey"),
114+
new TypeToken<List<String>>() {
115+
}.getType());
116+
} else {
117+
return null;
118+
}
119+
}
120+
97121
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public boolean deleteSubanchor(Integer roomId) throws WxErrorException {
272272
public String getSubanchor(Integer roomId) throws WxErrorException {
273273
Map<String, Object> map = new HashMap<>(1);
274274
map.put(ROOM_ID, roomId);
275-
String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, WxMaGsonBuilder.create().toJson(map));
275+
String responseContent = this.wxMaService.get(Room.GET_SUBANCHOR, Joiner.on("&").withKeyValueSeparator("=").join(map));
276276
JsonObject jsonObject = GsonParser.parse(responseContent);
277277
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
278278
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
@@ -390,7 +390,7 @@ public String getVideo(Integer roomId, Integer goodsId) throws WxErrorException
390390
Map<String, Object> map = new HashMap<>(2);
391391
map.put(ROOM_ID, roomId);
392392
map.put("goodsId", goodsId);
393-
String responseContent = this.wxMaService.get(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map));
393+
String responseContent = this.wxMaService.post(Room.GET_VIDEO, WxMaGsonBuilder.create().toJson(map));
394394
JsonObject jsonObject = GsonParser.parse(responseContent);
395395
if (jsonObject.get(ERR_CODE).getAsInt() != 0) {
396396
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ interface Goods {
272272
String UPDATE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update";
273273
String GET_GOODS_WARE_HOUSE = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse";
274274
String GET_APPROVED_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved";
275+
/**
276+
* 直播挂件设置全局 Key
277+
*/
278+
String SET_KEY = "https://api.weixin.qq.com/wxaapi/broadcast/goods/setkey";
279+
/**
280+
* 直播挂件获取全局 Key
281+
*/
282+
String GET_KEY = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getkey";
275283
}
276284

277285
/**

0 commit comments

Comments
 (0)