完成小程序直播添加相关功能
This commit is contained in:
@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.domain;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import javax.validation.constraints.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
@Data
|
||||
@TableName("yx_wechat_live")
|
||||
public class YxWechatLive implements Serializable {
|
||||
|
||||
/** 直播间id */
|
||||
@TableId
|
||||
private Long roomid;
|
||||
|
||||
|
||||
/** 直播间标题 */
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
|
||||
/** 背景图 */
|
||||
@TableField(exist = false)
|
||||
private String coverImg;
|
||||
|
||||
|
||||
/** 分享图片 */
|
||||
@TableField(exist = false)
|
||||
private String shareImg;
|
||||
|
||||
/** 背景图 */
|
||||
@NotBlank
|
||||
private String coverImge;
|
||||
|
||||
|
||||
/** 分享图片 */
|
||||
@NotBlank
|
||||
private String shareImge;
|
||||
|
||||
/** 主播头像 */
|
||||
private String anchorImge;
|
||||
|
||||
|
||||
|
||||
/** 直播间状态 */
|
||||
private Integer liveStatus;
|
||||
|
||||
|
||||
/** 开始时间 */
|
||||
private Long startTime;
|
||||
|
||||
|
||||
/** 预计结束时间 */
|
||||
private Long endTime;
|
||||
|
||||
|
||||
/** 开始时间 */
|
||||
@NotNull
|
||||
@TableField(exist = false)
|
||||
private Date startDate;
|
||||
|
||||
|
||||
/** 预计结束时间 */
|
||||
@NotNull
|
||||
@TableField(exist = false)
|
||||
private Date endDate;
|
||||
/** 主播昵称 */
|
||||
@NotBlank
|
||||
private String anchorName;
|
||||
|
||||
|
||||
/** 主播微信号 */
|
||||
@NotBlank
|
||||
private String anchorWechat;
|
||||
|
||||
|
||||
/** 主播头像 */
|
||||
@TableField(exist = false)
|
||||
private String anchorImg;
|
||||
|
||||
|
||||
/** 直播间类型 1:推流 0:手机直播 */
|
||||
@NotNull
|
||||
private Integer type;
|
||||
|
||||
|
||||
/** 横屏、竖屏 【1:横屏,0:竖屏】 */
|
||||
@NotNull
|
||||
private Integer screenType;
|
||||
|
||||
|
||||
/** 是否关闭点赞 【0:开启,1:关闭】 */
|
||||
@NotNull
|
||||
private Integer closeLike;
|
||||
|
||||
|
||||
/** 是否关闭货架 【0:开启,1:关闭】 */
|
||||
@NotNull
|
||||
private Integer closeGoods;
|
||||
|
||||
/** 是否关闭评论 【0:开启,1:关闭】 */
|
||||
@NotNull
|
||||
private Integer closeComment;
|
||||
|
||||
|
||||
public void copy(YxWechatLive source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.rest;
|
||||
import java.util.Arrays;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLive;
|
||||
import co.yixiang.modules.wechat.service.YxWechatLiveService;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveQueryCriteria;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveDto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Api(tags = "wxlive管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/yxWechatLive")
|
||||
public class YxWechatLiveController {
|
||||
|
||||
private final YxWechatLiveService yxWechatLiveService;
|
||||
private final IGenerator generator;
|
||||
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLive:list')")
|
||||
public void download(HttpServletResponse response, YxWechatLiveQueryCriteria criteria) throws IOException {
|
||||
yxWechatLiveService.download(generator.convert(yxWechatLiveService.queryAll(criteria), YxWechatLiveDto.class), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询wxlive")
|
||||
@ApiOperation("查询wxlive")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLive:list')")
|
||||
public ResponseEntity<Object> getYxWechatLives(YxWechatLiveQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(yxWechatLiveService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增wxlive")
|
||||
@ApiOperation("新增wxlive")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLive:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody YxWechatLive resources){
|
||||
return new ResponseEntity<>(yxWechatLiveService.saveLive(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改wxlive")
|
||||
@ApiOperation("修改wxlive")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLive:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody YxWechatLive resources){
|
||||
yxWechatLiveService.updateById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除wxlive")
|
||||
@ApiOperation("删除wxlive")
|
||||
@PreAuthorize("@el.check('admin','yxWechatLive:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
|
||||
Arrays.asList(ids).forEach(id->{
|
||||
yxWechatLiveService.removeById(id);
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package co.yixiang.modules.wechat.service;
|
||||
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 直播间商品相关操作接口
|
||||
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/commodity-api.html
|
||||
* Created by lipengjun on 2020/6/29.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/lipengjun92">lipengjun (939961241@qq.com)</a>
|
||||
*/
|
||||
public interface WxMaLiveGoodsService {
|
||||
String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add";
|
||||
String RESET_AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit";
|
||||
String AUDIT_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/audit";
|
||||
String DELETE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete";
|
||||
String UPDATE_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/update";
|
||||
String GET_GOODS_WARE_HOUSE = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse";
|
||||
String GET_APPROVED_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved";
|
||||
|
||||
/**
|
||||
* 商品添加并提审
|
||||
* <pre>
|
||||
* 调用此接口上传并提审需要直播的商品信息,审核通过后商品录入【小程序直播】商品库
|
||||
* 注意:开发者必须保存【商品ID】与【审核单ID】,如果丢失,则无法调用其他相关接口
|
||||
* 调用额度:500次/一天
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=ACCESS_TOKEN
|
||||
* </pre>
|
||||
*
|
||||
* @param goods 商品
|
||||
* @return 返回auditId、goodsId
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 撤回审核
|
||||
* <pre>
|
||||
* 调用此接口,可撤回直播商品的提审申请,消耗的提审次数不返还
|
||||
* 调用额度:500次/一天
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/resetaudit?access_token=ACCESS_TOKEN
|
||||
* <pre>
|
||||
* @param auditId 审核单ID
|
||||
* @param goodsId 商品ID
|
||||
* @return 撤回审核是否成功
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 重新提交审核
|
||||
* <pre>
|
||||
* 调用此接口,可撤回直播商品的提审申请,消耗的提审次数不返还
|
||||
* 调用额度:500次/一天(与接口'商品添加并提审'共用500次限制)
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/audit?access_token=ACCESS_TOKEN
|
||||
* <pre>
|
||||
* @param goodsId 商品ID
|
||||
* @return 审核单ID
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
String auditGoods(Integer goodsId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* <pre>
|
||||
* 调用此接口,可删除【小程序直播】商品库中的商品,删除后直播间上架的该商品也将被同步删除,不可恢复;
|
||||
* 调用额度:1000次/一天
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=ACCESS_TOKEN
|
||||
* <pre>
|
||||
* @param goodsId 商品ID
|
||||
* @return 删除商品是否成功
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
boolean deleteGoods(Integer goodsId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新商品
|
||||
* <pre>
|
||||
* 调用此接口可以更新商品信息,审核通过的商品仅允许更新价格类型与价格,审核中的商品不允许更新,未审核的商品允许更新所有字段, 只传入需要更新的字段。
|
||||
* 调用额度:1000次/一天
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/goods/update?access_token=ACCESS_TOKEN
|
||||
* </pre>
|
||||
*
|
||||
* @param goods 商品
|
||||
* @return 更新商品是否成功
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取商品状态
|
||||
* <pre>
|
||||
* 调用此接口可获取商品的信息与审核状态
|
||||
* 调用额度:1000次/一天
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=ACCESS_TOKEN
|
||||
* <pre>
|
||||
* @param goodsIds 商品ID集
|
||||
* @return 商品状态信息
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取商品列表
|
||||
* <pre>
|
||||
* 调用此接口可获取商品列表
|
||||
* 调用额度:10000次/一天
|
||||
* http请求方式:GET https://api.weixin.qq.com/wxaapi/broadcast/goods/getapproved?access_token=ACCESS_TOKEN
|
||||
* <pre>
|
||||
* @param offset 分页条数起点
|
||||
* @param limit 分页大小,默认30,不超过100
|
||||
* @param status 商品状态,0:未审核。1:审核中,2:审核通过,3:审核驳回
|
||||
* @return 商品列表
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException;
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
package co.yixiang.modules.wechat.service;
|
||||
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 直播相关操作接口.
|
||||
* Created by yjwang on 2020/4/5.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/yjwang3300300">yjwang</a>
|
||||
*/
|
||||
public interface WxMaLiveService {
|
||||
String GET_LIVE_INFO = "https://api.weixin.qq.com/wxa/business/getliveinfo";
|
||||
String CREATE_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/create";
|
||||
String ADD_GOODS = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods";
|
||||
|
||||
/**
|
||||
* 创建直播间
|
||||
* <pre>
|
||||
* 调用此接口创建直播间,创建成功后将在直播间列表展示,调用额度:10000次/一天
|
||||
* 文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/liveplayer/studio-api.html#1
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=ACCESS_TOKEN
|
||||
* </pre>
|
||||
*
|
||||
* @param roomInfo 直播间信息
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取直播房间列表.(分页)
|
||||
*
|
||||
* @param start 起始拉取房间,start = 0 表示从第 1 个房间开始拉取
|
||||
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取所有直播间信息(没有分页直接获取全部)
|
||||
*
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取直播房间回放数据信息.
|
||||
*
|
||||
* @param action 获取回放
|
||||
* @param roomId 直播间 id
|
||||
* @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取
|
||||
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取直播房间回放数据信息.
|
||||
* <p>
|
||||
* 获取回放 (默认:get_replay)
|
||||
*
|
||||
* @param roomId 直播间 id
|
||||
* @param start 起始拉取视频,start = 0 表示从第 1 个视频片段开始拉取
|
||||
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 直播间导入商品
|
||||
* <p>
|
||||
* 调用接口往指定直播间导入已入库的商品
|
||||
* 调用频率
|
||||
* 调用额度:10000次/一天
|
||||
* <p>
|
||||
* http请求方式:POST https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods?access_token=ACCESS_TOKEN
|
||||
* <pre>
|
||||
* @param roomId 房间ID
|
||||
* @param goodsIds 数组列表,可传入多个,里面填写 商品 ID
|
||||
* @return 导入商品是否成功
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service;
|
||||
import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLive;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveDto;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
public interface YxWechatLiveService extends BaseService<YxWechatLive>{
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(YxWechatLiveQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<YxWechatLiveDto>
|
||||
*/
|
||||
List<YxWechatLive> queryAll(YxWechatLiveQueryCriteria criteria);
|
||||
|
||||
|
||||
boolean saveLive(YxWechatLive resources);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<YxWechatLiveDto> all, HttpServletResponse response) throws IOException;
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package co.yixiang.modules.wechat.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
/**
|
||||
* 直播接口入参
|
||||
*/
|
||||
@Data
|
||||
public class WxMaLiveInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7285263767524755887L;
|
||||
|
||||
/**
|
||||
* 直播列表
|
||||
*/
|
||||
@Data
|
||||
public static class RoomInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7745775280267417154L;
|
||||
/**
|
||||
* 直播间名字,最短3个汉字,最长17个汉字,1个汉字相当于2个字符
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 直播房间id
|
||||
*/
|
||||
private Integer roomid;
|
||||
/**
|
||||
* 背景图,填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,
|
||||
* 请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;
|
||||
* 直播间背景图,图片规则:建议像素1080*1920,大小不超过2M
|
||||
*/
|
||||
private String coverImg;
|
||||
|
||||
/**
|
||||
* 分享图,填入mediaID(mediaID获取后,三天内有效);图片mediaID的获取,请参考以下文档: https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html;直播间分享图,图片规则:建议像素800*640,大小不超过1M;
|
||||
*/
|
||||
private String shareImg;
|
||||
|
||||
private Integer liveStatus;
|
||||
/**
|
||||
* 直播计划开始时间(开播时间需要在当前时间的10分钟后 并且 开始时间不能在 6 个月后)
|
||||
*/
|
||||
private Long startTime;
|
||||
/**
|
||||
* 直播计划结束时间(开播时间和结束时间间隔不得短于30分钟,不得超过24小时)
|
||||
*/
|
||||
private Long endTime;
|
||||
/**
|
||||
* 主播昵称,最短2个汉字,最长15个汉字,1个汉字相当于2个字符
|
||||
*/
|
||||
private String anchorName;
|
||||
/**
|
||||
* 主播微信号,如果未实名认证,需要先前往“小程序直播”小程序进行实名验证, 小程序二维码链接:https://res.wx.qq.com/op_res/BbVNeczA1XudfjVqCVoKgfuWe7e3aUhokktRVOqf_F0IqS6kYR--atCpVNUUC3zr
|
||||
*/
|
||||
private String anchorWechat;
|
||||
|
||||
/**
|
||||
* 主播头像
|
||||
*/
|
||||
private String anchorImg;
|
||||
/**
|
||||
* 直播间类型 【1: 推流,0:手机直播】
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 横屏、竖屏 【1:横屏,0:竖屏】(横屏:视频宽高比为16:9、4:3、1.85:1 ;竖屏:视频宽高比为9:16、2:3)
|
||||
*/
|
||||
private Integer screenType;
|
||||
/**
|
||||
* 是否关闭点赞 【0:开启,1:关闭】(若关闭,直播开始后不允许开启)
|
||||
*/
|
||||
private Integer closeLike;
|
||||
/**
|
||||
* 是否关闭货架 【0:开启,1:关闭】(若关闭,直播开始后不允许开启)
|
||||
*/
|
||||
private Integer closeGoods;
|
||||
/**
|
||||
* 是否关闭评论 【0:开启,1:关闭】(若关闭,直播开始后不允许开启)
|
||||
*/
|
||||
private Integer closeComment;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private List<Goods> goods;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
*/
|
||||
@Data
|
||||
public static class Goods implements Serializable {
|
||||
private static final long serialVersionUID = 5769245932149287574L;
|
||||
private Integer goodsId;
|
||||
private String coverImgUrl;
|
||||
private String url;
|
||||
private Integer priceType;
|
||||
private String price;
|
||||
private String price2;
|
||||
private String name;
|
||||
/**
|
||||
* 1, 2:表示是为api添加商品,否则是在MP添加商品
|
||||
*/
|
||||
private String thirdPartyTag;
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package co.yixiang.modules.wechat.service.dto;
|
||||
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
/**
|
||||
* <pre>
|
||||
* 直播间操作返回结果
|
||||
* Created by lipengjun on 2020/6/29.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/lipengjun92">lipengjun (939961241@qq.com)</a>
|
||||
*/
|
||||
@Data
|
||||
public class WxMaLiveResult implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Integer errcode;
|
||||
private String errmsg;
|
||||
private Integer total;
|
||||
private Integer auditId;
|
||||
private Integer goodsId;
|
||||
private List<Goods> goods;
|
||||
|
||||
/**
|
||||
* 直播间列表
|
||||
*/
|
||||
@SerializedName("room_info")
|
||||
private List<RoomInfo> roomInfos;
|
||||
|
||||
/**
|
||||
* 获取回放源视频列表
|
||||
*/
|
||||
@SerializedName("live_replay")
|
||||
private List<LiveReplay> liveReplay;
|
||||
|
||||
public static WxMaLiveResult fromJson(String json) {
|
||||
return WxMaGsonBuilder.create().fromJson(json, WxMaLiveResult.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
*/
|
||||
@Data
|
||||
public static class Goods implements Serializable {
|
||||
private static final long serialVersionUID = 5769245932149287574L;
|
||||
@SerializedName("goods_id")
|
||||
private Integer goodsId;
|
||||
/**
|
||||
* 获取商品列表返回的商品图片
|
||||
*/
|
||||
@SerializedName("cover_img_url")
|
||||
private String coverImgUrl;
|
||||
/**
|
||||
* 获取直播间列表返回的商品图片
|
||||
*/
|
||||
@SerializedName("cover_img")
|
||||
private String coverImg;
|
||||
private String name;
|
||||
private String url;
|
||||
@SerializedName("price_type")
|
||||
private Integer priceType;
|
||||
/**
|
||||
* 0:未审核,1:审核中,2:审核通过,3审核失败
|
||||
*/
|
||||
@SerializedName("audit_status")
|
||||
private Integer auditStatus;
|
||||
private String price;
|
||||
private String price2;
|
||||
/**
|
||||
* 1, 2:表示是为api添加商品,否则是在MP添加商品
|
||||
*/
|
||||
@SerializedName("third_party_tag")
|
||||
private String thirdPartyTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直播列表
|
||||
*/
|
||||
@Data
|
||||
public static class RoomInfo implements Serializable {
|
||||
private static final long serialVersionUID = 7745775280267417154L;
|
||||
private String name;
|
||||
@SerializedName("roomid")
|
||||
private Integer roomId;
|
||||
@SerializedName("cover_img")
|
||||
private String coverImg;
|
||||
@SerializedName("share_img")
|
||||
private String shareImg;
|
||||
@SerializedName("live_status")
|
||||
private Integer liveStatus;
|
||||
@SerializedName("start_time")
|
||||
private Long startTime;
|
||||
@SerializedName("end_time")
|
||||
private Long endTime;
|
||||
@SerializedName("anchor_name")
|
||||
private String anchorName;
|
||||
@SerializedName("anchor_wechat")
|
||||
private String anchorWechat;
|
||||
@SerializedName("anchor_img")
|
||||
private String anchorImg;
|
||||
private Integer type;
|
||||
@SerializedName("screen_type")
|
||||
private Integer screenType;
|
||||
@SerializedName("close_like")
|
||||
private Integer closeLike;
|
||||
@SerializedName("closeGoods")
|
||||
private Integer closeGoods;
|
||||
@SerializedName("close_comment")
|
||||
private Integer closeComment;
|
||||
private List<Goods> goods;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回放数据列表
|
||||
*/
|
||||
@Data
|
||||
public static class LiveReplay implements Serializable {
|
||||
private static final long serialVersionUID = 7683927205627536320L;
|
||||
@SerializedName("expire_time")
|
||||
private String expireTime;
|
||||
@SerializedName("create_time")
|
||||
private String createTime;
|
||||
@SerializedName("media_url")
|
||||
private String mediaUrl;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
@Data
|
||||
public class YxWechatLiveDto implements Serializable {
|
||||
|
||||
/** 直播间id */
|
||||
/** 防止精度丢失 */
|
||||
@JsonSerialize(using= ToStringSerializer.class)
|
||||
private Long roomId;
|
||||
|
||||
/** 直播间标题 */
|
||||
private String name;
|
||||
|
||||
/** 背景图 */
|
||||
private String coverImg;
|
||||
|
||||
/** 分享图片 */
|
||||
private String shareImg;
|
||||
|
||||
/** 直播间状态 */
|
||||
private Integer liveStatus;
|
||||
|
||||
/** 开始时间 */
|
||||
private Long startTime;
|
||||
|
||||
/** 预计结束时间 */
|
||||
private Long endTime;
|
||||
|
||||
/** 主播昵称 */
|
||||
private String anchorName;
|
||||
|
||||
/** 主播微信号 */
|
||||
private String anchorWechat;
|
||||
|
||||
/** 主播头像 */
|
||||
private String anchorImg;
|
||||
|
||||
/** 直播间类型 1:推流 0:手机直播 */
|
||||
private Integer type;
|
||||
|
||||
/** 横屏、竖屏 【1:横屏,0:竖屏】 */
|
||||
private Integer screenType;
|
||||
|
||||
/** 是否关闭货架 【0:开启,1:关闭】 */
|
||||
private Integer closeLike;
|
||||
|
||||
/** 是否关闭评论 【0:开启,1:关闭】 */
|
||||
private Integer closeComment;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
import co.yixiang.annotation.Query;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
@Data
|
||||
public class YxWechatLiveQueryCriteria{
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
package co.yixiang.modules.wechat.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import co.yixiang.modules.wechat.service.WxMaLiveGoodsService;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveResult;
|
||||
import co.yixiang.tools.config.WxMaConfiguration;
|
||||
import co.yixiang.utils.GsonParser;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService {
|
||||
|
||||
@Value("${file.path}")
|
||||
private String uploadDirStr;
|
||||
@Override
|
||||
public WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("goodsInfo", goods);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveGoodsService.ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resetAudit(Integer auditId, Integer goodsId) throws WxErrorException {
|
||||
Map<String, Integer> map = new HashMap<>(4);
|
||||
map.put("auditId", auditId);
|
||||
map.put("goodsId", goodsId);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveGoodsService.RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String auditGoods(Integer goodsId) throws WxErrorException {
|
||||
Map<String, Integer> map = new HashMap<>(2);
|
||||
map.put("goodsId", goodsId);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveGoodsService.AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return jsonObject.get("auditId").getAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteGoods(Integer goodsId) throws WxErrorException {
|
||||
Map<String, Integer> map = new HashMap<>(2);
|
||||
map.put("goodsId", goodsId);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveGoodsService.DELETE_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateGoods(WxMaLiveInfo.Goods goods) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("goodsInfo", goods);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveGoodsService.UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaLiveResult getGoodsWareHouse(List<Integer> goodsIds) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("goods_ids", goodsIds);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveGoodsService.GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException {
|
||||
ImmutableMap<String, ? extends Serializable> params = ImmutableMap.of("status", status, "offset", offset, "limit", limit);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.get(WxMaLiveGoodsService.GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
JsonArray goodsArr = jsonObject.getAsJsonArray("goods");
|
||||
if (goodsArr.size() > 0) {
|
||||
for (int i = 0; i < goodsArr.size(); i++) {
|
||||
// 接口返回key是驼峰
|
||||
JsonObject goods = (JsonObject) goodsArr.get(i);
|
||||
goods.addProperty("goods_id", goods.get("goodsId").getAsInt());
|
||||
goods.addProperty("cover_img_url", goods.get("coverImgUrl").getAsString());
|
||||
goods.addProperty("price_type", goods.get("priceType").getAsInt());
|
||||
goods.addProperty("third_party_tag", goods.get("thirdPartyTag").getAsInt());
|
||||
goods.addProperty("audit_status", status);
|
||||
}
|
||||
}
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传临时素材
|
||||
* @param wxMaService WxMaService
|
||||
* @param picPath 图片路径
|
||||
* @return WxMpMaterialUploadResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
private WxMediaUploadResult uploadPhotoToWx(WxMaService wxMaService, String picPath) throws WxErrorException {
|
||||
String filename = String.valueOf( (int)System.currentTimeMillis() ) + ".png";
|
||||
String downloadPath = uploadDirStr + filename;
|
||||
long size = HttpUtil.downloadFile(picPath, cn.hutool.core.io.FileUtil.file(downloadPath));
|
||||
picPath = downloadPath;
|
||||
File picFile = new File( picPath );
|
||||
log.info( "picFile name : {}", picFile.getName() );
|
||||
WxMediaUploadResult wxMediaUploadResult = wxMaService.getMediaService().uploadMedia( WxConsts.MediaFileType.IMAGE, picFile );
|
||||
log.info( "wxMpMaterialUploadResult : {}", JSONUtil.toJsonStr( wxMediaUploadResult ) );
|
||||
return wxMediaUploadResult;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
package co.yixiang.modules.wechat.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import co.yixiang.modules.wechat.service.WxMaLiveService;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveResult;
|
||||
import co.yixiang.tools.config.WxMaConfiguration;
|
||||
import co.yixiang.utils.GsonParser;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Created by yjwang on 2020/4/5.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/yjwang3300300">yjwang</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WxMaLiveServiceImpl implements WxMaLiveService {
|
||||
|
||||
@Value("${file.path}")
|
||||
private String uploadDirStr;
|
||||
@Override
|
||||
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveService.CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return jsonObject.get("roomId").getAsInt();
|
||||
}
|
||||
/**
|
||||
* 获取直播房间列表.(分页)
|
||||
*
|
||||
* @param start 起始拉取房间,start = 0 表示从第 1 个房间开始拉取
|
||||
* @param limit 每次拉取的个数上限,不要设置过大,建议 100 以内
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
@Override
|
||||
public WxMaLiveResult getLiveInfo(Integer start, Integer limit) throws WxErrorException {
|
||||
JsonObject jsonObject = getLiveInfo(start, limit, null);
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
}
|
||||
/**
|
||||
* 获取所有直播间信息(没有分页直接获取全部)
|
||||
*
|
||||
* @return .
|
||||
* @throws WxErrorException .
|
||||
*/
|
||||
@Override
|
||||
public List<WxMaLiveResult.RoomInfo> getLiveInfos() throws WxErrorException {
|
||||
List<WxMaLiveResult.RoomInfo> results = new ArrayList<>();
|
||||
int start = 0;
|
||||
Integer limit = 80;
|
||||
Integer total = 0;
|
||||
WxMaLiveResult liveInfo;
|
||||
do {
|
||||
if (total != 0 && total <= start) {
|
||||
break;
|
||||
}
|
||||
liveInfo = getLiveInfo(start, limit);
|
||||
if (liveInfo == null) {
|
||||
return null;
|
||||
}
|
||||
results.addAll(liveInfo.getRoomInfos());
|
||||
total = liveInfo.getTotal();
|
||||
start = results.size();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("InterruptedException", e);
|
||||
}
|
||||
} while (results.size() <= total);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaLiveResult getLiveReplay(String action, Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(4);
|
||||
map.put("action", action);
|
||||
map.put("room_id", roomId);
|
||||
JsonObject jsonObject = getLiveInfo(start, limit, map);
|
||||
return WxMaLiveResult.fromJson(jsonObject.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMaLiveResult getLiveReplay(Integer roomId, Integer start, Integer limit) throws WxErrorException {
|
||||
return getLiveReplay("get_replay", roomId, start, limit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addGoodsToRoom(Integer roomId, List<Integer> goodsIds) throws WxErrorException {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("roomId", roomId);
|
||||
map.put("ids", goodsIds);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveService.ADD_GOODS, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private JsonObject getLiveInfo(Integer start, Integer limit, Map<String, Object> map) throws WxErrorException {
|
||||
if (map == null) {
|
||||
map = new HashMap(2);
|
||||
}
|
||||
map.put("start", start);
|
||||
map.put("limit", limit);
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
String responseContent = wxMaService.post(WxMaLiveService.GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map));
|
||||
JsonObject jsonObject = GsonParser.parse(responseContent);
|
||||
if (jsonObject.get("errcode").getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLive;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.modules.wechat.service.WxMaLiveService;
|
||||
import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo;
|
||||
import co.yixiang.tools.config.WxMaConfiguration;
|
||||
import co.yixiang.utils.DateUtils;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import co.yixiang.common.utils.QueryHelpPlus;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import co.yixiang.modules.wechat.service.YxWechatLiveService;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveDto;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatLiveQueryCriteria;
|
||||
import co.yixiang.modules.wechat.service.mapper.YxWechatLiveMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
// 默认不使用缓存
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
//import org.springframework.cache.annotation.CacheEvict;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
@Service
|
||||
//@CacheConfig(cacheNames = "yxWechatLive")
|
||||
@Slf4j
|
||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
|
||||
public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper, YxWechatLive> implements YxWechatLiveService {
|
||||
|
||||
private final IGenerator generator;
|
||||
@Value("${file.path}")
|
||||
private String uploadDirStr;
|
||||
private final WxMaLiveService wxMaLiveService;
|
||||
|
||||
public YxWechatLiveServiceImpl(IGenerator generator, WxMaLiveService wxMaLiveService) {
|
||||
this.generator = generator;
|
||||
this.wxMaLiveService = wxMaLiveService;
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
public Map<String, Object> queryAll(YxWechatLiveQueryCriteria criteria, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<YxWechatLive> page = new PageInfo<>(queryAll(criteria));
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", generator.convert(page.getList(), YxWechatLiveDto.class));
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
}
|
||||
@Override
|
||||
public boolean saveLive(YxWechatLive resources){
|
||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
try {
|
||||
resources.setStartTime(Long.valueOf(OrderUtil.dateToTimestamp(resources.getStartDate())));
|
||||
resources.setEndTime(Long.valueOf(OrderUtil.dateToTimestamp(resources.getEndDate())));
|
||||
resources.setAnchorImg(uploadPhotoToWx(wxMaService,resources.getAnchorImge()).getMediaId());
|
||||
resources.setCoverImg(uploadPhotoToWx(wxMaService,resources.getCoverImge()).getMediaId());
|
||||
resources.setShareImg(uploadPhotoToWx(wxMaService,resources.getShareImge()).getMediaId());
|
||||
WxMaLiveInfo.RoomInfo roomInfo = generator.convert(resources, WxMaLiveInfo.RoomInfo.class);
|
||||
Integer status = wxMaLiveService.createRoom(roomInfo);
|
||||
resources.setRoomid(Long.valueOf(status));
|
||||
this.save(resources);
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
public List<YxWechatLive> queryAll(YxWechatLiveQueryCriteria criteria){
|
||||
return baseMapper.selectList(QueryHelpPlus.getPredicate(YxWechatLive.class, criteria));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void download(List<YxWechatLiveDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (YxWechatLiveDto yxWechatLive : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("直播间标题", yxWechatLive.getName());
|
||||
map.put("背景图", yxWechatLive.getCoverImg());
|
||||
map.put("分享图片", yxWechatLive.getShareImg());
|
||||
map.put("直播间状态", yxWechatLive.getLiveStatus());
|
||||
map.put("开始时间", yxWechatLive.getStartTime());
|
||||
map.put("预计结束时间", yxWechatLive.getEndTime());
|
||||
map.put("主播昵称", yxWechatLive.getAnchorName());
|
||||
map.put("主播微信号", yxWechatLive.getAnchorWechat());
|
||||
map.put("主播头像", yxWechatLive.getAnchorImg());
|
||||
map.put("直播间类型 1:推流 0:手机直播", yxWechatLive.getType());
|
||||
map.put("横屏、竖屏 【1:横屏,0:竖屏】", yxWechatLive.getScreenType());
|
||||
map.put("是否关闭货架 【0:开启,1:关闭】", yxWechatLive.getCloseLike());
|
||||
map.put("是否关闭评论 【0:开启,1:关闭】", yxWechatLive.getCloseComment());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传临时素材
|
||||
* @param wxMaService WxMaService
|
||||
* @param picPath 图片路径
|
||||
* @return WxMpMaterialUploadResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
private WxMediaUploadResult uploadPhotoToWx(WxMaService wxMaService, String picPath) throws WxErrorException {
|
||||
String filename = String.valueOf( (int)System.currentTimeMillis() ) + ".png";
|
||||
String downloadPath = uploadDirStr + filename;
|
||||
long size = HttpUtil.downloadFile(picPath, cn.hutool.core.io.FileUtil.file(downloadPath));
|
||||
picPath = downloadPath;
|
||||
File picFile = new File( picPath );
|
||||
log.info( "picFile name : {}", picFile.getName() );
|
||||
WxMediaUploadResult wxMediaUploadResult = wxMaService.getMediaService().uploadMedia( WxConsts.MediaFileType.IMAGE, picFile );
|
||||
log.info( "wxMpMaterialUploadResult : {}", JSONUtil.toJsonStr( wxMediaUploadResult ) );
|
||||
return wxMediaUploadResult;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.wechat.service.mapper;
|
||||
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatLive;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-08-10
|
||||
*/
|
||||
@Repository
|
||||
public interface YxWechatLiveMapper extends CoreMapper<YxWechatLive> {
|
||||
|
||||
}
|
Reference in New Issue
Block a user