微信小程序直播V0.2
This commit is contained in:
parent
0173ba814e
commit
02827a2f8b
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ -15,10 +14,10 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author liushuai(liushuai711 @ gmail.com)
|
||||
* @version v4.1
|
||||
* @Description:
|
||||
* @since 2021/5/17 3:10 下午
|
||||
* 直播商品
|
||||
*
|
||||
* @author Bulbasaur
|
||||
* @date: 2021/5/18 5:42 下午
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@ -41,8 +40,8 @@ public class StudioCommodity {
|
||||
@ApiModelProperty(value = "商品ID")
|
||||
private Integer goodsId;
|
||||
|
||||
public StudioCommodity(Integer roomId,Integer goodsId){
|
||||
this.roomId=roomId;
|
||||
this.goodsId=goodsId;
|
||||
public StudioCommodity(Integer roomId, Integer goodsId) {
|
||||
this.roomId = roomId;
|
||||
this.goodsId = goodsId;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
package cn.lili.modules.broadcast.entity.dto;
|
||||
|
||||
/**
|
||||
* @author liushuai(liushuai711 @ gmail.com)
|
||||
* @version v4.1
|
||||
* @Description:
|
||||
* @since 2021/5/17 11:34 上午
|
||||
*/
|
||||
public enum CommodityAuditStatusEnum {
|
||||
|
||||
/**
|
||||
* 未审核
|
||||
*/
|
||||
WAIT_AUDIT("0"),
|
||||
/**
|
||||
* 审核中
|
||||
*/
|
||||
AUDITING("1"),
|
||||
/**
|
||||
* 审核通过
|
||||
*/
|
||||
AUDIT_PASS("2"),
|
||||
/**
|
||||
* 审核失败
|
||||
*/
|
||||
AUDIT_REJECTION("3");
|
||||
|
||||
private final String status;
|
||||
|
||||
CommodityAuditStatusEnum(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package cn.lili.modules.broadcast.util;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.Method;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.lili.modules.base.entity.enums.ClientTypeEnum;
|
||||
import cn.lili.modules.broadcast.entity.dos.Commodity;
|
||||
@ -15,16 +12,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信小程序直播工具类
|
||||
*
|
||||
* @author Bulbasaur
|
||||
* @date: 2021/5/17 10:16 上午
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ -33,31 +29,19 @@ public class WechatLivePlayerUtil {
|
||||
@Autowired
|
||||
private WechatAccessTokenUtil wechatAccessTokenUtil;
|
||||
|
||||
private void test(Studio studio){
|
||||
HttpRequest httpRequest = new HttpRequest("https://api.weixin.qq.com/cgi-bin/media/upload");
|
||||
httpRequest.setMethod(Method.POST);
|
||||
File logoFile = new File(studio.getMediaUrl());
|
||||
httpRequest.setConnectionTimeout(30000);
|
||||
httpRequest.form("access_token",wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP));
|
||||
httpRequest.form("type", "image");
|
||||
httpRequest.form("media", logoFile);
|
||||
HttpResponse reqResult = httpRequest.execute();
|
||||
System.out.println(reqResult.body());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建小程序直播间
|
||||
*
|
||||
* @param studio 小程序直播
|
||||
* @return 房间ID
|
||||
*/
|
||||
public Integer create(Studio studio){
|
||||
test(studio);
|
||||
public Integer create(Studio studio) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token="+ token;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=" + token;
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// 背景图
|
||||
map.put("coverImg", studio.getCoverImg());
|
||||
// 分享图
|
||||
@ -82,7 +66,7 @@ public class WechatLivePlayerUtil {
|
||||
// 是否关闭货架
|
||||
map.put("closeGoods", "0");
|
||||
// 是否关闭评论
|
||||
map.put("closeComment","0");
|
||||
map.put("closeComment", "0");
|
||||
// 直播间名字
|
||||
map.put("closeReplay", "0");
|
||||
|
||||
@ -94,14 +78,15 @@ public class WechatLivePlayerUtil {
|
||||
|
||||
/**
|
||||
* 获取直播间回放
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @return 回放地址
|
||||
*/
|
||||
public String getLiveInfo(String roomId){
|
||||
public String getLiveInfo(String roomId) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token="+ token;
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=" + token;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// 获取回放
|
||||
map.put("action", "get_replay");
|
||||
@ -121,15 +106,16 @@ public class WechatLivePlayerUtil {
|
||||
|
||||
/**
|
||||
* 推送直播间商品
|
||||
* @param roomId 房间ID
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @param goodsId 商品ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
public Boolean pushGoods(Integer roomId,Integer goodsId){
|
||||
public Boolean pushGoods(Integer roomId, Integer goodsId) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/push?access_token="+ token;
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/push?access_token=" + token;
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
// 直播间回放
|
||||
map.put("goodsId", goodsId);
|
||||
@ -143,15 +129,16 @@ public class WechatLivePlayerUtil {
|
||||
|
||||
/**
|
||||
* 删除直播间商品
|
||||
* @param roomId 房间ID
|
||||
*
|
||||
* @param roomId 房间ID
|
||||
* @param goodsId 商品ID
|
||||
* @return 操作结果
|
||||
*/
|
||||
public Boolean goodsDeleteInRoom(Integer roomId,Integer goodsId){
|
||||
public Boolean goodsDeleteInRoom(Integer roomId, Integer goodsId) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom?access_token="+ token;
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom?access_token=" + token;
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
// 直播间回放
|
||||
map.put("goodsId", goodsId);
|
||||
@ -165,15 +152,16 @@ public class WechatLivePlayerUtil {
|
||||
|
||||
/**
|
||||
* 添加直播商品
|
||||
*
|
||||
* @param commodity 直播商品
|
||||
* @return 添加结果
|
||||
*/
|
||||
public JSONObject addGoods(Commodity commodity){
|
||||
public JSONObject addGoods(Commodity commodity) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token="+ token;
|
||||
GoodsInfo goodsInfo=new GoodsInfo(commodity);
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=" + token;
|
||||
GoodsInfo goodsInfo = new GoodsInfo(commodity);
|
||||
String content = HttpUtils.doPostWithJson(url, goodsInfo);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序添加直播商品结果:" + content);
|
||||
@ -182,14 +170,15 @@ public class WechatLivePlayerUtil {
|
||||
|
||||
/**
|
||||
* 删除直播商品
|
||||
*
|
||||
* @param goodsId 商品ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
public JSONObject deleteGoods(String goodsId){
|
||||
public JSONObject deleteGoods(String goodsId) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token="+ token;
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=" + token;
|
||||
String content = HttpUtils.doPostWithJson(url, goodsId);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序删除直播商品结果:" + content);
|
||||
@ -198,14 +187,15 @@ public class WechatLivePlayerUtil {
|
||||
|
||||
/**
|
||||
* 查询直播商品状态
|
||||
*
|
||||
* @param goodsIdList 商品ID列表
|
||||
* @return 删除结果
|
||||
*/
|
||||
public JSONObject deleteGoods(List<String> goodsIdList){
|
||||
public JSONObject deleteGoods(List<String> goodsIdList) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token="+ token;
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=" + token;
|
||||
String content = HttpUtils.doPostWithJson(url, goodsIdList);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序查询直播商品结果:" + content);
|
||||
|
@ -162,7 +162,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
|
||||
private Member findMember(String userName) {
|
||||
QueryWrapper<Member> queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq("username", userName).or().eq("mobile", userName);
|
||||
return memberMapper.selectOne(queryWrapper);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lili.controller.member;
|
||||
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
@ -53,7 +54,7 @@ public class MemberGradeManagerController {
|
||||
if (memberGradeService.updateById(memberGrade)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除会员等级")
|
||||
@ -61,10 +62,10 @@ public class MemberGradeManagerController {
|
||||
@PutMapping(value = "/delete/{id}")
|
||||
public ResultMessage<IPage<Object>> delete(@PathVariable String id) {
|
||||
if(memberGradeService.getById(id).getIsDefault()){
|
||||
return ResultUtil.error(ResultCode.USER_GRADE_IS_DEFAULT);
|
||||
throw new ServiceException(ResultCode.USER_GRADE_IS_DEFAULT);
|
||||
}else if(memberGradeService.removeById(id)){
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lili.controller.other.broadcast;
|
||||
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
@ -16,9 +17,9 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 店铺端,直播商品接口
|
||||
*
|
||||
* @author Bulbasaur
|
||||
* @date: 2021/5/17 2:05 下午
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "店铺端,直播商品接口")
|
||||
@ -37,18 +38,18 @@ public class CommodityController {
|
||||
@ApiOperation(value = "添加店铺直播商品")
|
||||
@PostMapping
|
||||
public ResultMessage<Object> addCommodity(@Validated Commodity commodity) {
|
||||
if(commodityService.addCommodity(commodity)){
|
||||
if (commodityService.addCommodity(commodity)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除店铺直播商品")
|
||||
@DeleteMapping
|
||||
public ResultMessage<Object> delete(String goodsId) {
|
||||
if(commodityService.deleteCommodity(goodsId)){
|
||||
if (commodityService.deleteCommodity(goodsId)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
package cn.lili.controller.other.broadcast;
|
||||
|
||||
import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.common.utils.ResultUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.common.vo.ResultMessage;
|
||||
import cn.lili.modules.base.entity.enums.ClientTypeEnum;
|
||||
import cn.lili.modules.broadcast.entity.dos.Studio;
|
||||
import cn.lili.modules.broadcast.service.StudioService;
|
||||
import cn.lili.modules.message.util.WechatAccessTokenUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -19,9 +22,9 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 店铺端,直播间接口
|
||||
*
|
||||
* @author Bulbasaur
|
||||
* @date: 2021/5/17 2:05 下午
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "店铺端,直播间接口")
|
||||
@ -30,6 +33,8 @@ public class StudioController {
|
||||
|
||||
@Autowired
|
||||
private StudioService studioService;
|
||||
@Autowired
|
||||
private WechatAccessTokenUtil wechatAccessTokenUtil;
|
||||
|
||||
@ApiOperation(value = "获取店铺直播间列表")
|
||||
@GetMapping
|
||||
@ -47,10 +52,10 @@ public class StudioController {
|
||||
@ApiOperation(value = "添加直播间")
|
||||
@PostMapping
|
||||
public ResultMessage<Object> add(@Validated Studio studio) {
|
||||
if(studioService.create(studio)){
|
||||
if (studioService.create(studio)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "店铺直播间添加商品")
|
||||
@ -59,23 +64,29 @@ public class StudioController {
|
||||
@ApiImplicitParam(name = "liveGoodsId", value = "直播商品ID", required = true, dataType = "Integer", paramType = "path")
|
||||
})
|
||||
@PutMapping(value = "/push/{roomId}/{liveGoodsId}")
|
||||
public ResultMessage<Studio> push(@PathVariable Integer roomId,@PathVariable Integer liveGoodsId) {
|
||||
if(studioService.push(roomId,liveGoodsId)){
|
||||
public ResultMessage<Studio> push(@PathVariable Integer roomId, @PathVariable Integer liveGoodsId) {
|
||||
if (studioService.push(roomId, liveGoodsId)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "店铺直播间删除商品")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "roomId", value = "房间ID", required = true, dataType = "Integer", paramType = "path"),
|
||||
@ApiImplicitParam(name = "liveGoodsId", value = "直播商品ID", required = true, dataType = "Integer", paramType = "path")
|
||||
@ApiImplicitParam(name = "roomId", value = "房间ID", required = true, dataType = "Integer", paramType = "path"),
|
||||
@ApiImplicitParam(name = "liveGoodsId", value = "直播商品ID", required = true, dataType = "Integer", paramType = "path")
|
||||
})
|
||||
@Delete(value = "/deleteInRoom/{roomId}/{liveGoodsId}")
|
||||
public ResultMessage<Studio> deleteInRoom(@PathVariable Integer roomId,@PathVariable Integer liveGoodsId) {
|
||||
if(studioService.goodsDeleteInRoom(roomId,liveGoodsId)){
|
||||
public ResultMessage<Studio> deleteInRoom(@PathVariable Integer roomId, @PathVariable Integer liveGoodsId) {
|
||||
if (studioService.goodsDeleteInRoom(roomId, liveGoodsId)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
return ResultUtil.error(ResultCode.ERROR);
|
||||
throw new ServiceException(ResultCode.ERROR);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取素材,调用接口凭证")
|
||||
@PutMapping(value = "/getCgiAccessToken")
|
||||
public ResultMessage<Object> getCgiAccessToken() {
|
||||
return ResultUtil.data(wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user