|
|
@@ -1,7 +1,17 @@
|
|
|
package com.izouma.tcg.web;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.izouma.tcg.domain.User;
|
|
|
+import com.izouma.tcg.domain.card.CardCase;
|
|
|
+import com.izouma.tcg.exception.BusinessException;
|
|
|
+import com.izouma.tcg.repo.UserRepo;
|
|
|
+import com.izouma.tcg.repo.card.CardCaseRepo;
|
|
|
+import com.izouma.tcg.utils.RestUtil;
|
|
|
+import com.izouma.tcg.utils.SecurityUtils;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import me.chanjar.weixin.common.bean.WxAccessToken;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
@@ -11,9 +21,48 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
@RestController
|
|
|
@RequestMapping("/live")
|
|
|
public class LiveController {
|
|
|
+ private final UserRepo userRepo;
|
|
|
+ private final CardCaseRepo cardCaseRepo;
|
|
|
|
|
|
+ //返回一串二维码链接说明用户未在微信直播小程序实名认证,需要先实名认证
|
|
|
@PostMapping("/applyAnchor")
|
|
|
- public String applyAnchor(String wxUsername) {
|
|
|
- return "String";
|
|
|
+ @ApiOperation(value = "申请主播账号")
|
|
|
+ public String applyAnchor(String wxUsername, String wxAccessToken) {
|
|
|
+ User user = SecurityUtils.getAuthenticatedUser();
|
|
|
+ user.setWxUserName(wxUsername);
|
|
|
+ userRepo.save(user);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("username", wxUsername);
|
|
|
+ jsonObject.put("role", 2);
|
|
|
+ return RestUtil.doPost("https://api.weixin.qq.com/wxaapi/broadcast/role/addrole?access_token=" + wxAccessToken
|
|
|
+ , jsonObject);
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/createRoom")
|
|
|
+ @ApiOperation(value = "创建直播间")
|
|
|
+ public String applyAnchor(Long cardCaseId, String wxAccessToken) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ CardCase cardCase = cardCaseRepo.findById(cardCaseId).orElseThrow(new BusinessException("暂无卡箱信息"));
|
|
|
+ jsonObject.put("username", cardCaseId);
|
|
|
+ jsonObject.put("coverImg", "");
|
|
|
+ jsonObject.put("name", "测试直播房间1");
|
|
|
+ jsonObject.put("startTime", 1588237130);
|
|
|
+ jsonObject.put("endTime", 1588237130);
|
|
|
+ jsonObject.put("anchorName", "william");
|
|
|
+ jsonObject.put("anchorWechat", "wyssII07");
|
|
|
+ jsonObject.put("subAnchorWechat", "wyssII07");
|
|
|
+ jsonObject.put("createrWechat", "wyssII07");
|
|
|
+ jsonObject.put("shareImg", "");
|
|
|
+ jsonObject.put("feedsImg", "");
|
|
|
+ jsonObject.put("isFeedsPublic", 1);
|
|
|
+ jsonObject.put("type", 1);
|
|
|
+ jsonObject.put("closeLike", 0);
|
|
|
+ jsonObject.put("closeGoods", 0);
|
|
|
+ jsonObject.put("closeComment", 0);
|
|
|
+ jsonObject.put("closeShare", 0);
|
|
|
+ jsonObject.put("closeKf", 0);
|
|
|
+ return RestUtil.doPost("https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=" + wxAccessToken
|
|
|
+ , jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
}
|