22
33import cn .binarywang .wx .miniapp .api .WxMaLiveService ;
44import cn .binarywang .wx .miniapp .api .WxMaService ;
5+ import cn .binarywang .wx .miniapp .bean .live .WxMaAssistantResult ;
6+ import cn .binarywang .wx .miniapp .bean .live .WxMaLiveAssistantInfo ;
57import cn .binarywang .wx .miniapp .bean .live .WxMaLiveResult ;
68import cn .binarywang .wx .miniapp .bean .live .WxMaLiveRoomInfo ;
79import cn .binarywang .wx .miniapp .util .json .WxMaGsonBuilder ;
@@ -90,12 +92,6 @@ public String getSharedCode(Integer roomId, String params) throws WxErrorExcepti
9092 return jsonObject .get ("cdnUrl" ).getAsString ();
9193 }
9294
93- @ Override
94- public WxMaLiveResult getLiveInfo (Integer start , Integer limit ) throws WxErrorException {
95- JsonObject jsonObject = getLiveInfo (start , limit , null );
96- return WxMaLiveResult .fromJson (jsonObject .toString ());
97- }
98-
9995 @ Override
10096 public List <WxMaLiveResult .RoomInfo > getLiveInfos () throws WxErrorException {
10197 List <WxMaLiveResult .RoomInfo > results = new ArrayList <>();
@@ -124,6 +120,13 @@ public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
124120 return results ;
125121 }
126122
123+ @ Override
124+ public WxMaLiveResult getLiveInfo (Integer start , Integer limit ) throws WxErrorException {
125+ JsonObject jsonObject = getLiveInfo (start , limit , null );
126+ return WxMaLiveResult .fromJson (jsonObject .toString ());
127+ }
128+
129+
127130 @ Override
128131 public WxMaLiveResult getLiveReplay (String action , Integer roomId , Integer start , Integer limit ) throws WxErrorException {
129132 Map <String , Object > map = new HashMap <>(4 );
@@ -132,7 +135,19 @@ public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start
132135 JsonObject jsonObject = getLiveInfo (start , limit , map );
133136 return WxMaLiveResult .fromJson (jsonObject .toString ());
134137 }
135-
138+ private JsonObject getLiveInfo (Integer start , Integer limit , Map <String , Object > map ) throws WxErrorException {
139+ if (map == null ) {
140+ map = new HashMap (2 );
141+ }
142+ map .put ("start" , start );
143+ map .put ("limit" , limit );
144+ String responseContent = wxMaService .post (GET_LIVE_INFO , WxMaGsonBuilder .create ().toJson (map ));
145+ JsonObject jsonObject = GsonParser .parse (responseContent );
146+ if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
147+ throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
148+ }
149+ return jsonObject ;
150+ }
136151 @ Override
137152 public WxMaLiveResult getLiveReplay (Integer roomId , Integer start , Integer limit ) throws WxErrorException {
138153 return getLiveReplay ("get_replay" , roomId , start , limit );
@@ -151,17 +166,57 @@ public boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxE
151166 return true ;
152167 }
153168
154- private JsonObject getLiveInfo (Integer start , Integer limit , Map <String , Object > map ) throws WxErrorException {
155- if (map == null ) {
156- map = new HashMap (2 );
169+ @ Override
170+ public boolean addAssistant (Integer roomId , List <WxMaLiveAssistantInfo > users ) throws WxErrorException {
171+ Map <String , Object > map = new HashMap <>(2 );
172+ map .put ("roomId" , roomId );
173+ map .put ("users" , users );
174+ String responseContent = this .wxMaService .post (ADD_ASSISTANT , WxMaGsonBuilder .create ().toJson (map ));
175+ JsonObject jsonObject = GsonParser .parse (responseContent );
176+ if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
177+ throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
157178 }
158- map .put ("start" , start );
159- map .put ("limit" , limit );
160- String responseContent = wxMaService .post (GET_LIVE_INFO , WxMaGsonBuilder .create ().toJson (map ));
179+ return true ;
180+ }
181+
182+ @ Override
183+ public boolean modifyAssistant (Integer roomId , String username ,String nickname ) throws WxErrorException {
184+ Map <String , Object > map = new HashMap <>(2 );
185+ map .put ("roomId" , roomId );
186+ map .put ("username" ,username );
187+ map .put ("nickname" , nickname );
188+ String responseContent = this .wxMaService .post (MODIFY_ASSISTANT , WxMaGsonBuilder .create ().toJson (map ));
161189 JsonObject jsonObject = GsonParser .parse (responseContent );
162190 if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
163191 throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
164192 }
165- return jsonObject ;
193+ return true ;
194+ }
195+
196+ @ Override
197+ public boolean removeAssistant (Integer roomId ,String username ) throws WxErrorException {
198+ Map <String , Object > map = new HashMap <>(2 );
199+ map .put ("roomId" , roomId );
200+ map .put ("username" ,username );
201+ String responseContent = this .wxMaService .post (REMOVE_ASSISTANT , WxMaGsonBuilder .create ().toJson (map ));
202+ JsonObject jsonObject = GsonParser .parse (responseContent );
203+ if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
204+ throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
205+ }
206+ return true ;
166207 }
208+
209+ @ Override
210+ public List <WxMaAssistantResult .Assistant > getAssistantList (Integer roomId ) throws WxErrorException {
211+ Map <String , Object > map = new HashMap <>(2 );
212+ map .put ("roomId" , roomId );
213+ String responseContent = this .wxMaService .post (GET_ASSISTANT_LIST , WxMaGsonBuilder .create ().toJson (map ));
214+ JsonObject jsonObject = GsonParser .parse (responseContent );
215+ if (jsonObject .get ("errcode" ).getAsInt () != 0 ) {
216+ throw new WxErrorException (WxError .fromJson (responseContent , WxType .MiniApp ));
217+ }
218+ return WxMaAssistantResult .fromJson (responseContent ).getList ();
219+ }
220+
221+
167222}
0 commit comments