Skip to content

Commit ef0b34b

Browse files
committed
🎨 #1753 小程序直播部分接口代码优化重构,对照官方文档补充新增参数
1 parent 19b033c commit ef0b34b

File tree

12 files changed

+163
-120
lines changed

12 files changed

+163
-120
lines changed

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.chanjar.weixin.cp.constant;
22

33

4+
import lombok.experimental.UtilityClass;
5+
46
/**
57
* <pre>
68
* 企业微信api地址常量类
@@ -9,6 +11,7 @@
911
*
1012
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1113
*/
14+
@UtilityClass
1215
public final class WxCpApiPathConsts {
1316
public static final String DEFAULT_CP_BASE_URL = "https://qyapi.weixin.qq.com";
1417

@@ -26,6 +29,7 @@ public final class WxCpApiPathConsts {
2629
* 消息推送相关接口
2730
* https://work.weixin.qq.com/api/doc/90000/90135/90235
2831
*/
32+
@UtilityClass
2933
public static class Message {
3034
/**
3135
* 发送应用消息
@@ -38,45 +42,52 @@ public static class Message {
3842
public static final String LINKEDCORP_MESSAGE_SEND = "/cgi-bin/linkedcorp/message/send";
3943
}
4044

45+
@UtilityClass
4146
public static class Agent {
4247
public static final String AGENT_GET = "/cgi-bin/agent/get?agentid=%d";
4348
public static final String AGENT_SET = "/cgi-bin/agent/set";
4449
public static final String AGENT_LIST = "/cgi-bin/agent/list";
4550
}
4651

52+
@UtilityClass
4753
public static class OAuth2 {
4854
public static final String GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
4955
public static final String GET_USER_DETAIL = "/cgi-bin/user/getuserdetail";
5056
public static final String URL_OAUTH2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
5157
}
5258

59+
@UtilityClass
5360
public static class Chat {
5461
public static final String APPCHAT_CREATE = "/cgi-bin/appchat/create";
5562
public static final String APPCHAT_UPDATE = "/cgi-bin/appchat/update";
5663
public static final String APPCHAT_GET_CHATID = "/cgi-bin/appchat/get?chatid=";
5764
public static final String APPCHAT_SEND = "/cgi-bin/appchat/send";
5865
}
5966

67+
@UtilityClass
6068
public static class Department {
6169
public static final String DEPARTMENT_CREATE = "/cgi-bin/department/create";
6270
public static final String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
6371
public static final String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
6472
public static final String DEPARTMENT_LIST = "/cgi-bin/department/list";
6573
}
6674

75+
@UtilityClass
6776
public static class Media {
6877
public static final String MEDIA_GET = "/cgi-bin/media/get";
6978
public static final String MEDIA_UPLOAD = "/cgi-bin/media/upload?type=";
7079
public static final String IMG_UPLOAD = "/cgi-bin/media/uploadimg";
7180
public static final String JSSDK_MEDIA_GET = "/cgi-bin/media/get/jssdk";
7281
}
7382

83+
@UtilityClass
7484
public static class Menu {
7585
public static final String MENU_CREATE = "/cgi-bin/menu/create?agentid=%d";
7686
public static final String MENU_DELETE = "/cgi-bin/menu/delete?agentid=%d";
7787
public static final String MENU_GET = "/cgi-bin/menu/get?agentid=%d";
7888
}
7989

90+
@UtilityClass
8091
public static class Oa {
8192
public static final String GET_CHECKIN_DATA = "/cgi-bin/checkin/getcheckindata";
8293
public static final String GET_CHECKIN_OPTION = "/cgi-bin/checkin/getcheckinoption";
@@ -87,6 +98,7 @@ public static class Oa {
8798
public static final String APPLY_EVENT = "/cgi-bin/oa/applyevent";
8899
}
89100

101+
@UtilityClass
90102
public static class Tag {
91103
public static final String TAG_CREATE = "/cgi-bin/tag/create";
92104
public static final String TAG_UPDATE = "/cgi-bin/tag/update";
@@ -97,10 +109,12 @@ public static class Tag {
97109
public static final String TAG_DEL_TAG_USERS = "/cgi-bin/tag/deltagusers";
98110
}
99111

112+
@UtilityClass
100113
public static class TaskCard {
101114
public static final String UPDATE_TASK_CARD = "/cgi-bin/message/update_taskcard";
102115
}
103116

117+
@UtilityClass
104118
public static class Tp {
105119
public static final String JSCODE_TO_SESSION = "/cgi-bin/service/miniprogram/jscode2session";
106120
public static final String GET_CORP_TOKEN = "/cgi-bin/service/get_corp_token";
@@ -111,6 +125,7 @@ public static class Tp {
111125
public static final String GET_AUTH_INFO = "/cgi-bin/service/get_auth_info";
112126
}
113127

128+
@UtilityClass
114129
public static class User {
115130
public static final String USER_AUTHENTICATE = "/cgi-bin/user/authsucc?userid=";
116131
public static final String USER_CREATE = "/cgi-bin/user/create";
@@ -127,6 +142,7 @@ public static class User {
127142
public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
128143
}
129144

145+
@UtilityClass
130146
public static class ExternalContact {
131147
@Deprecated
132148
public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";

Diff for: weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpConsts.java

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.chanjar.weixin.cp.constant;
22

3+
import lombok.experimental.UtilityClass;
4+
35
/**
46
* <pre>
57
* 企业微信常量
@@ -8,11 +10,13 @@
810
*
911
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1012
*/
13+
@UtilityClass
1114
public class WxCpConsts {
1215
/**
1316
* 企业微信端推送过来的事件类型.
1417
* 参考文档:https://work.weixin.qq.com/api/doc#12974
1518
*/
19+
@UtilityClass
1620
public static class EventType {
1721
/**
1822
* 成员关注事件.
@@ -105,6 +109,7 @@ public static class EventType {
105109
/**
106110
* 企业外部联系人变更事件的CHANGE_TYPE
107111
*/
112+
@UtilityClass
108113
public static class ExternalContactChangeType {
109114
/**
110115
* 新增外部联系人
@@ -128,6 +133,7 @@ public static class ExternalContactChangeType {
128133
/**
129134
* 企业微信通讯录变更事件.
130135
*/
136+
@UtilityClass
131137
public static class ContactChangeType {
132138
/**
133139
* 新增成员事件.
@@ -169,6 +175,7 @@ public static class ContactChangeType {
169175
/**
170176
* 互联企业发送应用消息的消息类型.
171177
*/
178+
@UtilityClass
172179
public static class LinkedCorpMsgType {
173180
/**
174181
* 文本消息.
@@ -213,6 +220,7 @@ public static class LinkedCorpMsgType {
213220
/**
214221
* 群机器人的消息类型.
215222
*/
223+
@UtilityClass
216224
public static class GroupRobotMsgType {
217225
/**
218226
* 文本消息.
@@ -238,6 +246,7 @@ public static class GroupRobotMsgType {
238246
/**
239247
* 应用推送消息的消息类型.
240248
*/
249+
@UtilityClass
241250
public static class AppChatMsgType {
242251
/**
243252
* 文本消息.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cn.binarywang.wx.miniapp.api;
22

3-
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
4-
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
3+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
4+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
55
import me.chanjar.weixin.common.error.WxErrorException;
66

77
import java.util.List;
@@ -37,7 +37,7 @@ public interface WxMaLiveGoodsService {
3737
* @return 返回auditId、goodsId
3838
* @throws WxErrorException .
3939
*/
40-
WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
40+
WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException;
4141

4242
/**
4343
* 撤回审核
@@ -91,7 +91,7 @@ public interface WxMaLiveGoodsService {
9191
* @return 更新商品是否成功
9292
* @throws WxErrorException .
9393
*/
94-
boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
94+
boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException;
9595

9696
/**
9797
* 获取商品状态

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cn.binarywang.wx.miniapp.api;
22

3-
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
4-
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
3+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
4+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
55
import me.chanjar.weixin.common.error.WxErrorException;
66

77
import java.util.List;
@@ -31,7 +31,7 @@ public interface WxMaLiveService {
3131
* @return .
3232
* @throws WxErrorException .
3333
*/
34-
Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException;
34+
Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException;
3535

3636
/**
3737
* 获取直播房间列表.(分页)

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

+10-40
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import cn.binarywang.wx.miniapp.api.WxMaLiveGoodsService;
44
import cn.binarywang.wx.miniapp.api.WxMaService;
5-
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
6-
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
5+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
6+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
77
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
88
import com.google.common.base.Joiner;
99
import com.google.common.collect.ImmutableMap;
1010
import com.google.gson.JsonArray;
1111
import com.google.gson.JsonObject;
1212
import lombok.AllArgsConstructor;
13-
import me.chanjar.weixin.common.enums.WxType;
14-
import me.chanjar.weixin.common.error.WxError;
1513
import me.chanjar.weixin.common.error.WxErrorException;
1614
import me.chanjar.weixin.common.util.json.GsonParser;
1715

@@ -32,27 +30,17 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
3230
private final WxMaService wxMaService;
3331

3432
@Override
35-
public WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
36-
Map<String, Object> map = new HashMap<>(2);
37-
map.put("goodsInfo", goods);
38-
String responseContent = this.wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
39-
JsonObject jsonObject = GsonParser.parse(responseContent);
40-
if (jsonObject.get("errcode").getAsInt() != 0) {
41-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
42-
}
43-
return WxMaLiveResult.fromJson(jsonObject.toString());
33+
public WxMaLiveResult addGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
34+
return WxMaLiveResult.fromJson(this.wxMaService.post(ADD_GOODS,
35+
WxMaGsonBuilder.create().toJson(ImmutableMap.of("goodsInfo", goods))));
4436
}
4537

4638
@Override
4739
public boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException {
4840
Map<String, Integer> map = new HashMap<>(4);
4941
map.put("auditId", auditId);
5042
map.put("goodsId", goodsId);
51-
String responseContent = this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
52-
JsonObject jsonObject = GsonParser.parse(responseContent);
53-
if (jsonObject.get("errcode").getAsInt() != 0) {
54-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
55-
}
43+
this.wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
5644
return true;
5745
}
5846

@@ -62,33 +50,22 @@ public String auditGoods(Integer goodsId) throws WxErrorException {
6250
map.put("goodsId", goodsId);
6351
String responseContent = this.wxMaService.post(AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
6452
JsonObject jsonObject = GsonParser.parse(responseContent);
65-
if (jsonObject.get("errcode").getAsInt() != 0) {
66-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
67-
}
6853
return jsonObject.get("auditId").getAsString();
6954
}
7055

7156
@Override
7257
public boolean deleteGoods(Integer goodsId) throws WxErrorException {
7358
Map<String, Integer> map = new HashMap<>(2);
7459
map.put("goodsId", goodsId);
75-
String responseContent = this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
76-
JsonObject jsonObject = GsonParser.parse(responseContent);
77-
if (jsonObject.get("errcode").getAsInt() != 0) {
78-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
79-
}
60+
this.wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
8061
return true;
8162
}
8263

8364
@Override
84-
public boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
65+
public boolean updateGoods(WxMaLiveGoodInfo goods) throws WxErrorException {
8566
Map<String, Object> map = new HashMap<>(2);
8667
map.put("goodsInfo", goods);
87-
String responseContent = this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
88-
JsonObject jsonObject = GsonParser.parse(responseContent);
89-
if (jsonObject.get("errcode").getAsInt() != 0) {
90-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
91-
}
68+
this.wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
9269
return true;
9370
}
9471

@@ -97,21 +74,14 @@ public WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorEx
9774
Map<String, Object> map = new HashMap<>(2);
9875
map.put("goods_ids", goodsIds);
9976
String responseContent = this.wxMaService.post(GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map));
100-
JsonObject jsonObject = GsonParser.parse(responseContent);
101-
if (jsonObject.get("errcode").getAsInt() != 0) {
102-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
103-
}
104-
return WxMaLiveResult.fromJson(jsonObject.toString());
77+
return WxMaLiveResult.fromJson(responseContent);
10578
}
10679

10780
@Override
10881
public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException {
10982
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("status", status, "offset", offset, "limit", limit);
11083
String responseContent = wxMaService.get(GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params));
11184
JsonObject jsonObject = GsonParser.parse(responseContent);
112-
if (jsonObject.get("errcode").getAsInt() != 0) {
113-
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
114-
}
11585
JsonArray goodsArr = jsonObject.getAsJsonArray("goods");
11686
if (goodsArr.size() > 0) {
11787
for (int i = 0; i < goodsArr.size(); i++) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import cn.binarywang.wx.miniapp.api.WxMaLiveService;
44
import cn.binarywang.wx.miniapp.api.WxMaService;
5-
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
6-
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
5+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
6+
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveRoomInfo;
77
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
88
import com.google.gson.JsonObject;
99
import lombok.AllArgsConstructor;
@@ -31,7 +31,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService {
3131
private final WxMaService wxMaService;
3232

3333
@Override
34-
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
34+
public Integer createRoom(WxMaLiveRoomInfo roomInfo) throws WxErrorException {
3535
String responseContent = this.wxMaService.post(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
3636
JsonObject jsonObject = GsonParser.parse(responseContent);
3737
if (jsonObject.get("errcode").getAsInt() != 0) {

0 commit comments

Comments
 (0)