|
|
@@ -3,21 +3,22 @@ package com.slodon.b2b2c.controller.live;
|
|
3
|
3
|
|
|
4
|
4
|
import com.alibaba.fastjson.JSON;
|
|
5
|
5
|
import com.alibaba.fastjson.JSONObject;
|
|
|
6
|
+import com.slodon.b2b2c.controller.common.UploadController;
|
|
|
7
|
+import com.slodon.b2b2c.core.constant.ResponseConst;
|
|
6
|
8
|
import com.slodon.b2b2c.core.controller.BaseController;
|
|
7
|
9
|
import com.slodon.b2b2c.core.response.JsonResult;
|
|
8
|
10
|
import com.slodon.b2b2c.core.response.PageVO;
|
|
9
|
11
|
import com.slodon.b2b2c.core.response.PagerInfo;
|
|
10
|
12
|
import com.slodon.b2b2c.core.response.SldResponse;
|
|
11
|
|
-import com.slodon.b2b2c.core.util.AssertUtil;
|
|
12
|
|
-import com.slodon.b2b2c.core.util.HttpClientUtil;
|
|
13
|
|
-import com.slodon.b2b2c.core.util.WebUtil;
|
|
|
13
|
+import com.slodon.b2b2c.core.util.*;
|
|
14
|
14
|
import com.slodon.b2b2c.enums.WxLiveUrlEnum;
|
|
|
15
|
+import com.slodon.b2b2c.errors.WxCodeError;
|
|
15
|
16
|
import com.slodon.b2b2c.live.dto.LiveBroadcastDto;
|
|
16
|
|
-import com.slodon.b2b2c.live.dto.LiveBroadcastEditDto;
|
|
17
|
17
|
import com.slodon.b2b2c.live.example.LiveBroadcastExample;
|
|
18
|
18
|
import com.slodon.b2b2c.live.pojo.LiveBroadcast;
|
|
19
|
19
|
import com.slodon.b2b2c.live.vo.LivesVO;
|
|
20
|
20
|
import com.slodon.b2b2c.model.live.LiveBroadModel;
|
|
|
21
|
+import com.slodon.b2b2c.seller.pojo.Vendor;
|
|
21
|
22
|
import io.swagger.annotations.Api;
|
|
22
|
23
|
import io.swagger.annotations.ApiImplicitParam;
|
|
23
|
24
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
@@ -26,79 +27,199 @@ import lombok.extern.slf4j.Slf4j;
|
|
26
|
27
|
import org.apache.commons.beanutils.PropertyUtils;
|
|
27
|
28
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
28
|
29
|
import org.springframework.util.CollectionUtils;
|
|
29
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
30
|
+import org.springframework.util.StringUtils;
|
|
|
31
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
32
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
33
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
34
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
35
|
+import org.springframework.web.multipart.MultipartFile;
|
|
30
|
36
|
|
|
31
|
37
|
import javax.annotation.Resource;
|
|
32
|
38
|
import javax.servlet.http.HttpServletRequest;
|
|
33
|
|
-import java.util.ArrayList;
|
|
34
|
|
-import java.util.HashMap;
|
|
35
|
|
-import java.util.List;
|
|
36
|
|
-import java.util.Map;
|
|
|
39
|
+import java.io.File;
|
|
|
40
|
+import java.text.ParseException;
|
|
|
41
|
+import java.text.SimpleDateFormat;
|
|
|
42
|
+import java.util.*;
|
|
37
|
43
|
|
|
38
|
44
|
@Api(tags = "admin-微信直播管理")
|
|
39
|
45
|
@RestController
|
|
40
|
46
|
@Slf4j
|
|
41
|
|
-@RequestMapping("v3/live/broad")
|
|
|
47
|
+@RequestMapping("v3/live/seller/broad")
|
|
42
|
48
|
public class LiveBroadController extends BaseController {
|
|
43
|
|
- private final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=";//获取access_token地址
|
|
|
49
|
+
|
|
|
50
|
+ private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
44
|
51
|
|
|
45
|
52
|
@Resource
|
|
46
|
53
|
private StringRedisTemplate stringRedisTemplate;
|
|
47
|
54
|
@Resource
|
|
48
|
55
|
private LiveBroadModel liveBroadModel;
|
|
|
56
|
+ @Resource
|
|
|
57
|
+ private UploadController uploadController;
|
|
49
|
58
|
|
|
50
|
59
|
private String getToken() throws Exception {
|
|
51
|
60
|
String appId = stringRedisTemplate.opsForValue().get("login_wx_mini_appid");
|
|
52
|
61
|
String secret = stringRedisTemplate.opsForValue().get("login_wx_mini_appsecret");
|
|
53
|
|
- String access_token_resp = HttpClientUtil.httpGet(ACCESS_TOKEN_URL + appId + "&secret=" + secret);
|
|
|
62
|
+ String access_token_resp = HttpClientUtil.httpGet(WxLiveUrlEnum.ACCESS_TOKEN_URL.getUrl() + appId + "&secret=" + secret);
|
|
54
|
63
|
String access_token = JSON.parseObject(access_token_resp).getString("access_token");
|
|
55
|
64
|
AssertUtil.notEmpty(access_token, "微信认证失败");
|
|
56
|
65
|
System.out.println("结果access_token: "+access_token);
|
|
57
|
66
|
return access_token;
|
|
58
|
67
|
}
|
|
|
68
|
+ @ApiOperation("添加临时素材")
|
|
|
69
|
+ @ApiImplicitParams({
|
|
|
70
|
+ @ApiImplicitParam(name = "multipartFile", value = "文件", paramType = "formData", required = true)
|
|
|
71
|
+ })
|
|
|
72
|
+ @PostMapping(value = "upload", consumes = "multipart/*", headers = "content-type=multipart/form-data")
|
|
|
73
|
+ public JsonResult mediaUpload(HttpServletRequest request,MultipartFile multipartFile) {
|
|
|
74
|
+ HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
75
|
+ try {
|
|
|
76
|
+ //先保存到本地
|
|
|
77
|
+ JsonResult uploadImg = uploadController.uploadImg(multipartFile, "tempImg");
|
|
|
78
|
+ resultMap = (HashMap<String, Object>) uploadImg.getData();
|
|
|
79
|
+ String access_token = getToken();
|
|
|
80
|
+ //校验
|
|
|
81
|
+ String url = WxLiveUrlEnum.TEMP_UPLOAD.getUrl();
|
|
|
82
|
+ url = url.replace("ACCESS_TOKEN",access_token).replace("TYPE","image");
|
|
|
83
|
+ File file = MultipartFileToFile(multipartFile);
|
|
|
84
|
+ String result = FileUploadUtil.postUploadSSL(url, file, file.getName());
|
|
|
85
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
86
|
+ resultMap.put("mediaId",jsonObject.getString("media_id"));
|
|
|
87
|
+// resultMap.put("url",jsonObject.getString("media_id"));
|
|
|
88
|
+// resultMap.put("path",jsonObject.getString("media_id"));
|
|
|
89
|
+ } catch (Exception e) {
|
|
|
90
|
+ e.printStackTrace();
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+ return SldResponse.success(resultMap);
|
|
|
94
|
+ }
|
|
|
95
|
+ /**
|
|
|
96
|
+ * 将MultipartFile转换为File
|
|
|
97
|
+ * @param multiFile
|
|
|
98
|
+ * @return
|
|
|
99
|
+ */
|
|
|
100
|
+ public static File MultipartFileToFile(MultipartFile multiFile) {
|
|
|
101
|
+ // 获取文件名
|
|
|
102
|
+ String fileName = multiFile.getOriginalFilename();
|
|
|
103
|
+ // 获取文件后缀
|
|
|
104
|
+ String prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
105
|
+ // 若须要防止生成的临时文件重复,能够在文件名后添加随机码
|
|
|
106
|
+ try {
|
|
|
107
|
+ File file = File.createTempFile(fileName, prefix);
|
|
|
108
|
+ multiFile.transferTo(file);
|
|
|
109
|
+ return file;
|
|
|
110
|
+ } catch (Exception e) {
|
|
|
111
|
+ e.printStackTrace();
|
|
|
112
|
+ }
|
|
|
113
|
+ return null;
|
|
|
114
|
+ }
|
|
59
|
115
|
|
|
60
|
|
-// @ApiOperation("添加临时素材")
|
|
61
|
|
-// @PostMapping("/mediaUpload")
|
|
62
|
|
-// public JsonResult mediaUpload(HttpServletRequest request, @RequestBody LiveBroadcastDto liveBroadcastDto) {
|
|
63
|
|
-// try {
|
|
64
|
|
-// String access_token = getToken();
|
|
65
|
|
-// //校验
|
|
66
|
|
-// String url = "https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token="+access_token;
|
|
67
|
|
-// String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(liveBroadcastDto));
|
|
68
|
|
-// JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
69
|
|
-// String errCode = jsonObject.getString("errcode");
|
|
70
|
|
-// if (!"0".equals(errCode)){
|
|
71
|
|
-// log.warn("直播间添加失败原因:"+reStr);
|
|
72
|
|
-// return SldResponse.success("添加失败");
|
|
73
|
|
-// }
|
|
74
|
|
-// liveBroadcastDto.setRoomId(String.valueOf(jsonObject.get("roomId")));
|
|
75
|
|
-// liveBroadModel.broadcastRoomCreate(liveBroadcastDto);
|
|
76
|
|
-// } catch (Exception e) {
|
|
77
|
|
-// e.printStackTrace();
|
|
78
|
|
-// }
|
|
79
|
|
-// return SldResponse.success("添加成功");
|
|
80
|
|
-// }
|
|
81
|
116
|
|
|
82
|
117
|
@ApiOperation("添加直播间")
|
|
83
|
118
|
@PostMapping("/wxBroadcastRoomCreate")
|
|
84
|
|
- public JsonResult wxBroadcastRoomCreate(HttpServletRequest request, @RequestBody LiveBroadcastDto liveBroadcastDto) {
|
|
|
119
|
+ public JsonResult wxBroadcastRoomCreate(HttpServletRequest request,LiveBroadcastDto liveBroadcastDto) {
|
|
|
120
|
+ HashMap<String, String> resultMap = new HashMap<>();
|
|
85
|
121
|
try {
|
|
86
|
|
- String access_token = getToken();
|
|
|
122
|
+ Vendor vendor = UserUtil.getUser(request, Vendor.class);
|
|
|
123
|
+ if (vendor == null || vendor.getVendorId() == null){
|
|
|
124
|
+ return SldResponse.fail("获取商户id失败");
|
|
|
125
|
+ }
|
|
|
126
|
+ liveBroadcastDto.setVendorId(String.valueOf(vendor.getVendorId()));
|
|
87
|
127
|
//校验
|
|
|
128
|
+ checkParam(liveBroadcastDto,resultMap);
|
|
|
129
|
+ if (String.valueOf(ResponseConst.STATE_FAIL).equals(resultMap.get("state").toString())){
|
|
|
130
|
+ return SldResponse.fail(resultMap.get("msg"));
|
|
|
131
|
+ }
|
|
|
132
|
+ //获取token
|
|
|
133
|
+ String access_token = getToken();
|
|
88
|
134
|
String url = WxLiveUrlEnum.ADD_LIVE.getUrl()+access_token;
|
|
89
|
135
|
String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(liveBroadcastDto));
|
|
90
|
136
|
JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
91
|
137
|
String errCode = jsonObject.getString("errcode");
|
|
92
|
138
|
if (!"0".equals(errCode)){
|
|
93
|
139
|
log.warn("直播间添加失败原因:"+reStr);
|
|
94
|
|
- return SldResponse.success("添加失败");
|
|
|
140
|
+ return jsonObject.getString("qrcode_url") != null
|
|
|
141
|
+ ? SldResponse.fail("qrcode_url")
|
|
|
142
|
+ : SldResponse.fail( WxCodeError.WX_CODE.get(errCode));
|
|
95
|
143
|
}
|
|
96
|
144
|
liveBroadcastDto.setRoomId(String.valueOf(jsonObject.get("roomId")));
|
|
97
|
145
|
liveBroadModel.broadcastRoomCreate(liveBroadcastDto);
|
|
98
|
146
|
} catch (Exception e) {
|
|
99
|
147
|
e.printStackTrace();
|
|
100
|
148
|
}
|
|
101
|
|
- return SldResponse.success("添加成功");
|
|
|
149
|
+ return SldResponse.success(resultMap);
|
|
|
150
|
+ }
|
|
|
151
|
+
|
|
|
152
|
+ private void checkParam(LiveBroadcastDto liveBroadcastDto, HashMap<String, String> resultMap) throws ParseException {
|
|
|
153
|
+ resultMap.put("state","255");
|
|
|
154
|
+ if(liveBroadcastDto==null){
|
|
|
155
|
+ resultMap.put("msg","请填写参数");
|
|
|
156
|
+ return;
|
|
|
157
|
+ }
|
|
|
158
|
+ if(liveBroadcastDto.getName() == null || liveBroadcastDto.getName().length() < 3 || liveBroadcastDto.getName().length() > 17){
|
|
|
159
|
+ resultMap.put("msg","直播间名字,最短3个汉字,最长17个汉字");
|
|
|
160
|
+ return;
|
|
|
161
|
+ }
|
|
|
162
|
+ if(liveBroadcastDto.getCoverImg() == null){
|
|
|
163
|
+ resultMap.put("msg","背景图必填");
|
|
|
164
|
+ return;
|
|
|
165
|
+ }
|
|
|
166
|
+ if(liveBroadcastDto.getStartTimeStr() == null || liveBroadcastDto.getEndTimeStr() == null){
|
|
|
167
|
+ resultMap.put("msg","开始和结束时间必填");
|
|
|
168
|
+ return;
|
|
|
169
|
+ }
|
|
|
170
|
+ if(liveBroadcastDto.getAnchorName() == null || liveBroadcastDto.getAnchorName().length() < 2 || liveBroadcastDto.getAnchorName().length() > 15){
|
|
|
171
|
+ resultMap.put("msg","主播昵称,最短2个汉字,最长15个汉字");
|
|
|
172
|
+ return;
|
|
|
173
|
+ }
|
|
|
174
|
+ if(liveBroadcastDto.getAnchorWechat() == null){
|
|
|
175
|
+ resultMap.put("msg","主播微信号不能为空");
|
|
|
176
|
+ return;
|
|
|
177
|
+ }
|
|
|
178
|
+ if(liveBroadcastDto.getShareImg() == null){
|
|
|
179
|
+ resultMap.put("msg","分享图必填");
|
|
|
180
|
+ return;
|
|
|
181
|
+ }
|
|
|
182
|
+ if(liveBroadcastDto.getFeedsImg() == null){
|
|
|
183
|
+ resultMap.put("msg","购物直播频道封面图必填");
|
|
|
184
|
+ return;
|
|
|
185
|
+ }
|
|
|
186
|
+ if(liveBroadcastDto.getType() == null){
|
|
|
187
|
+ liveBroadcastDto.setType(0);
|
|
|
188
|
+ }
|
|
|
189
|
+ if(liveBroadcastDto.getCloseLike() == null){
|
|
|
190
|
+ resultMap.put("msg","是否关闭点赞必填");
|
|
|
191
|
+ return;
|
|
|
192
|
+ }
|
|
|
193
|
+ if(liveBroadcastDto.getCloseGoods() == null){
|
|
|
194
|
+ resultMap.put("msg","是否关闭货架必填");
|
|
|
195
|
+ return;
|
|
|
196
|
+ }
|
|
|
197
|
+ if(liveBroadcastDto.getCloseComment() == null){
|
|
|
198
|
+ resultMap.put("msg","是否关闭评论必填");
|
|
|
199
|
+ return;
|
|
|
200
|
+ }
|
|
|
201
|
+ if(liveBroadcastDto.getCloseKf() == null){
|
|
|
202
|
+ resultMap.put("msg","是否关闭客服必填");
|
|
|
203
|
+ return;
|
|
|
204
|
+ }
|
|
|
205
|
+ Date startTimeDate = sdf.parse(liveBroadcastDto.getStartTimeStr());
|
|
|
206
|
+ Date endTimeDate = sdf.parse(liveBroadcastDto.getEndTimeStr());
|
|
|
207
|
+ Long startTime = startTimeDate.getTime() / 1000;
|
|
|
208
|
+ Long endTime = endTimeDate.getTime() / 1000;
|
|
|
209
|
+
|
|
|
210
|
+ if (startTime-System.currentTimeMillis()/1000<600){
|
|
|
211
|
+ resultMap.put("msg","开始时间需要在当前时间的10分钟后 并且 开始时间不能在 6 个月后");
|
|
|
212
|
+ return;
|
|
|
213
|
+ }
|
|
|
214
|
+ if (endTime-startTime<1800 || endTime-startTime>86400 ){
|
|
|
215
|
+ resultMap.put("msg","开播时间和结束时间间隔不得短于30分钟,不得超过24小时");
|
|
|
216
|
+ return;
|
|
|
217
|
+ }
|
|
|
218
|
+ liveBroadcastDto.setStartTime(startTimeDate.getTime() / 1000);
|
|
|
219
|
+ liveBroadcastDto.setEndTime(endTimeDate.getTime() / 1000);
|
|
|
220
|
+
|
|
|
221
|
+
|
|
|
222
|
+ resultMap.put("state","200");
|
|
102
|
223
|
}
|
|
103
|
224
|
|
|
104
|
225
|
@ApiOperation("获取直播列表")
|
|
|
@@ -109,17 +230,28 @@ public class LiveBroadController extends BaseController {
|
|
109
|
230
|
})
|
|
110
|
231
|
@GetMapping("/list")
|
|
111
|
232
|
public JsonResult<PageVO<LivesVO>> getList(HttpServletRequest request, String name) {
|
|
|
233
|
+ Vendor vendor = UserUtil.getUser(request, Vendor.class);
|
|
112
|
234
|
PagerInfo pager = WebUtil.handlerPagerInfo(request);
|
|
113
|
235
|
LiveBroadcastExample example = new LiveBroadcastExample();
|
|
114
|
236
|
example.setName(name);
|
|
|
237
|
+ if (vendor != null && vendor.getVendorId() != null){
|
|
|
238
|
+ example.setVendorId(String.valueOf(vendor.getVendorId()));
|
|
|
239
|
+ }
|
|
115
|
240
|
List<LiveBroadcast> livesList = liveBroadModel.getLivesList(example, pager);
|
|
116
|
241
|
List<LivesVO> livesVOS = new ArrayList<>();
|
|
117
|
242
|
if (!CollectionUtils.isEmpty(livesList)) {
|
|
118
|
243
|
livesList.forEach(node->{
|
|
119
|
244
|
LivesVO vo = new LivesVO();
|
|
120
|
|
- vo.setName(node.getName());
|
|
121
|
|
- vo.setAnchorName(node.getAnchorName());
|
|
122
|
|
- vo.setRoomId(node.getRoomId());
|
|
|
245
|
+ try {
|
|
|
246
|
+ PropertyUtils.copyProperties(vo,node);
|
|
|
247
|
+ vo.setStartTimeStr(sdf.format(node.getStartTime()*1000));
|
|
|
248
|
+ vo.setEndTimeStr(sdf.format(node.getEndTime()*1000));
|
|
|
249
|
+ vo.setCoverImgUrl(FileUrlUtil.getFileUrl(vo.getCoverImgPath(), null));
|
|
|
250
|
+ vo.setFeedsImgUrl(FileUrlUtil.getFileUrl(vo.getFeedsImgPath(), null));
|
|
|
251
|
+ vo.setShareImgUrl(FileUrlUtil.getFileUrl(vo.getShareImgPath(), null));
|
|
|
252
|
+ } catch (Exception e) {
|
|
|
253
|
+ e.printStackTrace();
|
|
|
254
|
+ }
|
|
123
|
255
|
livesVOS.add(vo);
|
|
124
|
256
|
});
|
|
125
|
257
|
}
|
|
|
@@ -141,6 +273,12 @@ public class LiveBroadController extends BaseController {
|
|
141
|
273
|
map.put("start",start);
|
|
142
|
274
|
map.put("limit",limit);
|
|
143
|
275
|
String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(map));
|
|
|
276
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
277
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
278
|
+ if (!"0".equals(errCode)){
|
|
|
279
|
+ log.warn("获取直播间列表及直播间信息:"+reStr);
|
|
|
280
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
281
|
+ }
|
|
144
|
282
|
return SldResponse.success(reStr);
|
|
145
|
283
|
} catch (Exception e) {
|
|
146
|
284
|
e.printStackTrace();
|
|
|
@@ -188,7 +326,11 @@ public class LiveBroadController extends BaseController {
|
|
188
|
326
|
map.put("ids",ids);
|
|
189
|
327
|
map.put("roomId",roomId);
|
|
190
|
328
|
String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(map));
|
|
191
|
|
- return SldResponse.success(reStr);
|
|
|
329
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
330
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
331
|
+ if (!"0".equals(errCode)){
|
|
|
332
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
333
|
+ }
|
|
192
|
334
|
} catch (Exception e) {
|
|
193
|
335
|
e.printStackTrace();
|
|
194
|
336
|
}
|
|
|
@@ -206,30 +348,48 @@ public class LiveBroadController extends BaseController {
|
|
206
|
348
|
//校验
|
|
207
|
349
|
String url = WxLiveUrlEnum.DEL_LIVE.getUrl()+access_token;
|
|
208
|
350
|
String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(new HashMap<>().put("id",roomId)));
|
|
209
|
|
- return SldResponse.success(reStr);
|
|
|
351
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
352
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
353
|
+ if (!"0".equals(errCode)){
|
|
|
354
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
355
|
+ }
|
|
|
356
|
+ liveBroadModel.wxDelLive(roomId);
|
|
|
357
|
+ return SldResponse.success("删除成功");
|
|
210
|
358
|
} catch (Exception e) {
|
|
211
|
359
|
e.printStackTrace();
|
|
212
|
360
|
}
|
|
213
|
|
- return SldResponse.success("查询失败");
|
|
|
361
|
+ return SldResponse.success("删除失败");
|
|
214
|
362
|
}
|
|
215
|
363
|
|
|
216
|
364
|
@ApiOperation("编辑直播间")
|
|
217
|
365
|
@PostMapping("/wxBroadcastRoomEdit")
|
|
218
|
|
- public JsonResult wxBroadcastRoomEdit(HttpServletRequest request, @RequestBody LiveBroadcastEditDto liveBroadcastEditDto) {
|
|
|
366
|
+ public JsonResult wxBroadcastRoomEdit(HttpServletRequest request, LiveBroadcastDto liveBroadcastDto) {
|
|
219
|
367
|
try {
|
|
220
|
|
- String access_token = getToken();
|
|
221
|
368
|
//校验
|
|
|
369
|
+ HashMap<String, String> resultMap = new HashMap<>();
|
|
|
370
|
+ checkParam(liveBroadcastDto,resultMap);
|
|
|
371
|
+ if ("255".equals(resultMap.get("state"))){
|
|
|
372
|
+ return SldResponse.fail(resultMap.get("msg"));
|
|
|
373
|
+ }
|
|
|
374
|
+ if (StringUtils.isEmpty(liveBroadcastDto.getRoomId())){
|
|
|
375
|
+ return SldResponse.fail("直播间id不能为空");
|
|
|
376
|
+ }
|
|
|
377
|
+ String access_token = getToken();
|
|
222
|
378
|
String url = WxLiveUrlEnum.EDIT_LIVE.getUrl()+access_token;
|
|
223
|
|
- String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(liveBroadcastEditDto));
|
|
|
379
|
+ liveBroadcastDto.setId(Integer.valueOf(liveBroadcastDto.getRoomId()));
|
|
|
380
|
+ String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(liveBroadcastDto));
|
|
224
|
381
|
JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
225
|
382
|
String errCode = jsonObject.getString("errcode");
|
|
|
383
|
+
|
|
226
|
384
|
if (!"0".equals(errCode)){
|
|
227
|
385
|
log.warn("直播间编辑失败原因:"+reStr);
|
|
228
|
|
- return SldResponse.success("编辑失败");
|
|
|
386
|
+ return jsonObject.getString("qrcode_url") != null
|
|
|
387
|
+ ? SldResponse.fail("qrcode_url")
|
|
|
388
|
+ : SldResponse.fail( WxCodeError.WX_CODE.get(errCode));
|
|
229
|
389
|
}
|
|
|
390
|
+
|
|
230
|
391
|
LiveBroadcast live_broadcast = new LiveBroadcast();
|
|
231
|
|
- PropertyUtils.copyProperties(live_broadcast,liveBroadcastEditDto);
|
|
232
|
|
- live_broadcast.setRoomId(String.valueOf(liveBroadcastEditDto.getId()));
|
|
|
392
|
+ PropertyUtils.copyProperties(live_broadcast,liveBroadcastDto);
|
|
233
|
393
|
liveBroadModel.broadcastRoomEdit(live_broadcast);
|
|
234
|
394
|
} catch (Exception e) {
|
|
235
|
395
|
e.printStackTrace();
|
|
|
@@ -246,20 +406,152 @@ public class LiveBroadController extends BaseController {
|
|
246
|
406
|
try {
|
|
247
|
407
|
String access_token = getToken();
|
|
248
|
408
|
//校验
|
|
249
|
|
- String url = WxLiveUrlEnum.GET_PUSH_LIVE.getUrl()+access_token;
|
|
250
|
|
- String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(new HashMap<>().put("id",roomId)));
|
|
|
409
|
+ String url = WxLiveUrlEnum.GET_PUSH_LIVE.getUrl()+access_token+"&roomId"+roomId;
|
|
|
410
|
+ String reStr = HttpClientUtil.sendGet(url);
|
|
|
411
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
412
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
413
|
+ if (!"0".equals(errCode)){
|
|
|
414
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
415
|
+ }
|
|
251
|
416
|
return SldResponse.success(reStr);
|
|
252
|
417
|
} catch (Exception e) {
|
|
253
|
418
|
e.printStackTrace();
|
|
254
|
419
|
}
|
|
255
|
|
- return SldResponse.success("查询失败");
|
|
|
420
|
+ return SldResponse.success("查询成功");
|
|
|
421
|
+ }
|
|
|
422
|
+
|
|
|
423
|
+ @ApiOperation("获取直播间分享二维码")
|
|
|
424
|
+ @ApiImplicitParams({
|
|
|
425
|
+ @ApiImplicitParam(name = "roomId", value = "房间ID", paramType = "query"),
|
|
|
426
|
+ })
|
|
|
427
|
+ @GetMapping("/getSharedCode")
|
|
|
428
|
+ public JsonResult getSharedCode(HttpServletRequest request,Integer roomId) {
|
|
|
429
|
+ try {
|
|
|
430
|
+ String access_token = getToken();
|
|
|
431
|
+ //校验
|
|
|
432
|
+ String url = WxLiveUrlEnum.GET_SHARED_CODE.getUrl()+access_token+"&roomId"+roomId;
|
|
|
433
|
+ String reStr = HttpClientUtil.sendGet(url);
|
|
|
434
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
435
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
436
|
+ if (!"0".equals(errCode)){
|
|
|
437
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
438
|
+ }
|
|
|
439
|
+ return SldResponse.success(reStr);
|
|
|
440
|
+ } catch (Exception e) {
|
|
|
441
|
+ e.printStackTrace();
|
|
|
442
|
+ }
|
|
|
443
|
+ return SldResponse.success("查询成功");
|
|
|
444
|
+ }
|
|
|
445
|
+
|
|
|
446
|
+ @ApiOperation("开启/关闭直播间官方收录")
|
|
|
447
|
+ @ApiImplicitParams({
|
|
|
448
|
+ @ApiImplicitParam(name = "roomId", value = "房间ID", paramType = "query"),
|
|
|
449
|
+ @ApiImplicitParam(name = "isFeedsPublic", value = "是否开启官方收录 【1: 开启,0:关闭】", paramType = "query"),
|
|
|
450
|
+ })
|
|
|
451
|
+ @GetMapping("/updateFeedPublic")
|
|
|
452
|
+ public JsonResult updateFeedPublic(HttpServletRequest request,Integer roomId,Integer isFeedsPublic) {
|
|
|
453
|
+ try {
|
|
|
454
|
+ String access_token = getToken();
|
|
|
455
|
+ //校验
|
|
|
456
|
+ String url = WxLiveUrlEnum.UPDATE_FEED_PUBLIC.getUrl()+access_token;
|
|
|
457
|
+ HashMap<Object, Object> hashMap = new HashMap<>();
|
|
|
458
|
+ hashMap.put("roomId",roomId);
|
|
|
459
|
+ hashMap.put("isFeedsPublic",isFeedsPublic);
|
|
|
460
|
+ String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(hashMap));
|
|
|
461
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
462
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
463
|
+ if (!"0".equals(errCode)){
|
|
|
464
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
465
|
+ }
|
|
|
466
|
+ } catch (Exception e) {
|
|
|
467
|
+ e.printStackTrace();
|
|
|
468
|
+ }
|
|
|
469
|
+ return SldResponse.success("成功");
|
|
|
470
|
+ }
|
|
|
471
|
+
|
|
|
472
|
+ @ApiOperation("开启/关闭回放功能")
|
|
|
473
|
+ @ApiImplicitParams({
|
|
|
474
|
+ @ApiImplicitParam(name = "roomId", value = "房间ID", paramType = "query"),
|
|
|
475
|
+ @ApiImplicitParam(name = "closeReplay", value = "是否关闭回放 【0:开启,1:关闭】", paramType = "query"),
|
|
|
476
|
+ })
|
|
|
477
|
+ @GetMapping("/updateReplay")
|
|
|
478
|
+ public JsonResult updateReplay(HttpServletRequest request,Integer roomId,Integer closeReplay) {
|
|
|
479
|
+ try {
|
|
|
480
|
+ String access_token = getToken();
|
|
|
481
|
+ //校验
|
|
|
482
|
+ String url = WxLiveUrlEnum.UPDATE_REPLAY.getUrl()+access_token;
|
|
|
483
|
+ HashMap<Object, Object> hashMap = new HashMap<>();
|
|
|
484
|
+ hashMap.put("roomId",roomId);
|
|
|
485
|
+ hashMap.put("closeReplay",closeReplay);
|
|
|
486
|
+ String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(hashMap));
|
|
|
487
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
488
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
489
|
+ if (!"0".equals(errCode)){
|
|
|
490
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
491
|
+ }
|
|
|
492
|
+ } catch (Exception e) {
|
|
|
493
|
+ e.printStackTrace();
|
|
|
494
|
+ }
|
|
|
495
|
+ return SldResponse.success("成功");
|
|
|
496
|
+ }
|
|
|
497
|
+
|
|
|
498
|
+ @ApiOperation("开启/关闭客服功能")
|
|
|
499
|
+ @ApiImplicitParams({
|
|
|
500
|
+ @ApiImplicitParam(name = "roomId", value = "房间ID", paramType = "query"),
|
|
|
501
|
+ @ApiImplicitParam(name = "closeKf", value = "是否关闭客服 【0:开启,1:关闭】", paramType = "query"),
|
|
|
502
|
+ })
|
|
|
503
|
+ @GetMapping("/updateKf")
|
|
|
504
|
+ public JsonResult updateKf(HttpServletRequest request,Integer roomId,Integer closeKf) {
|
|
|
505
|
+ try {
|
|
|
506
|
+ String access_token = getToken();
|
|
|
507
|
+ //校验
|
|
|
508
|
+ String url = WxLiveUrlEnum.UPDATE_KF.getUrl()+access_token;
|
|
|
509
|
+ HashMap<Object, Object> hashMap = new HashMap<>();
|
|
|
510
|
+ hashMap.put("roomId",roomId);
|
|
|
511
|
+ hashMap.put("closeKf",closeKf);
|
|
|
512
|
+ String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(hashMap));
|
|
|
513
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
514
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
515
|
+ if (!"0".equals(errCode)){
|
|
|
516
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
517
|
+ }
|
|
|
518
|
+ } catch (Exception e) {
|
|
|
519
|
+ e.printStackTrace();
|
|
|
520
|
+ }
|
|
|
521
|
+ return SldResponse.success("成功");
|
|
|
522
|
+ }
|
|
|
523
|
+
|
|
|
524
|
+ @ApiOperation("开启/关闭直播间全局禁言")
|
|
|
525
|
+ @ApiImplicitParams({
|
|
|
526
|
+ @ApiImplicitParam(name = "roomId", value = "房间ID", paramType = "query"),
|
|
|
527
|
+ @ApiImplicitParam(name = "banComment", value = "1-禁言,0-取消禁言", paramType = "query"),
|
|
|
528
|
+ })
|
|
|
529
|
+ @GetMapping("/updateComment")
|
|
|
530
|
+ public JsonResult updateComment(HttpServletRequest request,Integer roomId,Integer banComment) {
|
|
|
531
|
+ try {
|
|
|
532
|
+ String access_token = getToken();
|
|
|
533
|
+ //校验
|
|
|
534
|
+ String url = WxLiveUrlEnum.UPDATE_COMMENT.getUrl()+access_token;
|
|
|
535
|
+ HashMap<Object, Object> hashMap = new HashMap<>();
|
|
|
536
|
+ hashMap.put("roomId",roomId);
|
|
|
537
|
+ hashMap.put("banComment",banComment);
|
|
|
538
|
+ String reStr = HttpClientUtil.sendJsonPostNew(url,JSON.toJSONString(hashMap));
|
|
|
539
|
+ JSONObject jsonObject = JSONObject.parseObject(reStr);
|
|
|
540
|
+ String errCode = jsonObject.getString("errcode");
|
|
|
541
|
+ if (!"0".equals(errCode)){
|
|
|
542
|
+ return SldResponse.fail(WxCodeError.WX_CODE.get(errCode));
|
|
|
543
|
+ }
|
|
|
544
|
+ } catch (Exception e) {
|
|
|
545
|
+ e.printStackTrace();
|
|
|
546
|
+ }
|
|
|
547
|
+ return SldResponse.success("成功");
|
|
256
|
548
|
}
|
|
257
|
549
|
|
|
258
|
|
- public static void main(String[] args) {
|
|
259
|
|
- Map map = new HashMap();
|
|
260
|
|
- map.put("start",1);
|
|
261
|
|
- map.put("limit",10);
|
|
262
|
|
- System.out.println(JSON.toJSONString(map));
|
|
|
550
|
+ public static void main(String[] args) throws Exception {
|
|
|
551
|
+ String a = "s";
|
|
|
552
|
+ System.out.println(a.length());
|
|
|
553
|
+ String b = "是";
|
|
|
554
|
+ System.out.println(b.length());
|
|
263
|
555
|
}
|
|
264
|
556
|
|
|
265
|
557
|
}
|