修改微信直播接口

This commit is contained in:
xuwenbo
2020-09-11 08:24:37 +08:00
parent 9d62fadbba
commit 46a46111e2
7 changed files with 239 additions and 4 deletions

View File

@ -27,7 +27,7 @@ import java.util.List;
@Repository @Repository
public interface YxStoreCombinationMapper extends CoreMapper<YxStoreCombination> { public interface YxStoreCombinationMapper extends CoreMapper<YxStoreCombination> {
@Select("SELECT c.id,c.effective_time as effectiveTime,c.image,c.people,c.price, s.sales as sales," + @Select("SELECT c.id,c.effective_time as effectiveTime,c.info,c.image,c.people,c.price, s.sales as sales," +
"c.title,c.unit_name as unitName,s.price as productPrice FROM yx_store_combination c " + "c.title,c.unit_name as unitName,s.price as productPrice FROM yx_store_combination c " +
"INNER JOIN yx_store_product s ON s.id=c.product_id " + "INNER JOIN yx_store_product s ON s.id=c.product_id " +
" WHERE c.is_show = 1 AND c.is_del = 0 AND c.start_time < now() " + " WHERE c.is_show = 1 AND c.is_del = 0 AND c.start_time < now() " +

View File

@ -122,6 +122,12 @@ public class YxWechatLive implements Serializable {
/** 是否关闭评论 【0开启1关闭】 */ /** 是否关闭评论 【0开启1关闭】 */
@NotNull @NotNull
private Integer closeComment; private Integer closeComment;
@NotNull
private Integer closeReplay ; // 是否关闭回放 1 关闭
@NotNull
private Integer closeShare ; // 是否关闭分享 1 关闭
@NotNull
private Integer closeKf ; // 是否关闭客服1 关闭
private String productId; private String productId;

View File

@ -10,11 +10,12 @@ package co.yixiang.modules.mp.service;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult; import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import co.yixiang.common.service.BaseService; import co.yixiang.common.service.BaseService;
import co.yixiang.modules.mp.service.dto.WxMaLiveInfo;
import co.yixiang.modules.mp.service.dto.YxWechatLiveDto; import co.yixiang.modules.mp.service.dto.YxWechatLiveDto;
import co.yixiang.modules.mp.service.dto.YxWechatLiveQueryCriteria; import co.yixiang.modules.mp.service.dto.YxWechatLiveQueryCriteria;
import co.yixiang.modules.mp.vo.WechatLiveVo; import co.yixiang.modules.mp.vo.WechatLiveVo;
import co.yixiang.modules.mp.domain.YxWechatLive; import co.yixiang.modules.mp.domain.YxWechatLive;
import co.yixiang.modules.product.vo.YxStoreProductQueryVo; import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -62,6 +63,21 @@ public interface YxWechatLiveService extends BaseService<YxWechatLive>{
*/ */
void download(List<YxWechatLiveDto> all, HttpServletResponse response) throws IOException; void download(List<YxWechatLiveDto> all, HttpServletResponse response) throws IOException;
/**
* 创建直播间
* <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 roomId * @param roomId

View File

@ -0,0 +1,58 @@
package co.yixiang.modules.mp.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class WxMaLiveInfo {
private static final long serialVersionUID = 7285263767524755887L;
/**
* 直播列表
*/
@Data
public static class RoomInfo implements Serializable {
private static final long serialVersionUID = 7745775280267417154L;
private String name;
private Integer roomid;
private String coverImg;
private String shareImg;
private Integer liveStatus;
private Long startTime;
private Long endTime;
private String anchorName;
private String anchorWechat;
private String anchorImg;
private Integer type;
private Integer screenType;
private Integer closeLike;
private Integer closeGoods;
private Integer closeComment;
private Integer closeReplay ; // 是否关闭回放 1 关闭
private Integer closeShare ; // 是否关闭分享 1 关闭
private Integer closeKf ; // 是否关闭客服1 关闭
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;
}
}

View File

@ -0,0 +1,131 @@
package co.yixiang.modules.mp.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<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.Goods> goods;
/**
* 直播间列表
*/
@SerializedName("room_info")
private List<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.RoomInfo> roomInfos;
/**
* 获取回放源视频列表
*/
@SerializedName("live_replay")
private List<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.LiveReplay> liveReplay;
public static cn.binarywang.wx.miniapp.bean.WxMaLiveResult fromJson(String json) {
return WxMaGsonBuilder.create().fromJson(json, cn.binarywang.wx.miniapp.bean.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<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.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;
}
}

View File

@ -88,6 +88,12 @@ public class YxWechatLiveDto implements Serializable {
/** 是否关闭货架 【0开启1关闭】 */ /** 是否关闭货架 【0开启1关闭】 */
@ApiModelProperty(value = "是否关闭货架 【0开启1关闭】") @ApiModelProperty(value = "是否关闭货架 【0开启1关闭】")
private Integer closeGoods; private Integer closeGoods;
private Integer closeReplay ; // 是否关闭回放 1 关闭
private Integer closeShare ; // 是否关闭分享 1 关闭
private Integer closeKf ; // 是否关闭客服1 关闭
/** /**
* 关联商品id多个隔开 * 关联商品id多个隔开
*/ */

View File

@ -9,8 +9,8 @@
package co.yixiang.modules.mp.service.impl; package co.yixiang.modules.mp.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult; import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import co.yixiang.common.service.impl.BaseServiceImpl; import co.yixiang.common.service.impl.BaseServiceImpl;
@ -21,6 +21,7 @@ import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.mp.domain.YxWechatLiveGoods; import co.yixiang.modules.mp.domain.YxWechatLiveGoods;
import co.yixiang.modules.mp.service.YxWechatLiveGoodsService; import co.yixiang.modules.mp.service.YxWechatLiveGoodsService;
import co.yixiang.modules.mp.service.YxWechatLiveService; import co.yixiang.modules.mp.service.YxWechatLiveService;
import co.yixiang.modules.mp.service.dto.WxMaLiveInfo;
import co.yixiang.modules.mp.service.dto.YxWechatLiveDto; import co.yixiang.modules.mp.service.dto.YxWechatLiveDto;
import co.yixiang.modules.mp.service.dto.YxWechatLiveGoodsDto; import co.yixiang.modules.mp.service.dto.YxWechatLiveGoodsDto;
import co.yixiang.modules.mp.service.dto.YxWechatLiveQueryCriteria; import co.yixiang.modules.mp.service.dto.YxWechatLiveQueryCriteria;
@ -39,10 +40,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.GsonParser;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -57,6 +62,8 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static cn.binarywang.wx.miniapp.api.WxMaLiveService.CREATE_ROOM;
/** /**
* @author hupeng * @author hupeng
* @date 2020-08-10 * @date 2020-08-10
@ -139,7 +146,7 @@ public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper,
resources.setCoverImg(uploadPhotoToWx(wxMaService,resources.getCoverImge()).getMediaId()); resources.setCoverImg(uploadPhotoToWx(wxMaService,resources.getCoverImge()).getMediaId());
resources.setShareImg(uploadPhotoToWx(wxMaService,resources.getShareImge()).getMediaId()); resources.setShareImg(uploadPhotoToWx(wxMaService,resources.getShareImge()).getMediaId());
WxMaLiveInfo.RoomInfo roomInfo = generator.convert(resources, WxMaLiveInfo.RoomInfo.class); WxMaLiveInfo.RoomInfo roomInfo = generator.convert(resources, WxMaLiveInfo.RoomInfo.class);
Integer status = wxMaService.getLiveService().createRoom(roomInfo); Integer status = this.createRoom(roomInfo);
resources.setRoomId(Long.valueOf(status)); resources.setRoomId(Long.valueOf(status));
if(StringUtils.isNotBlank(resources.getProductId())){ if(StringUtils.isNotBlank(resources.getProductId())){
String[] productIds = resources.getProductId().split(","); String[] productIds = resources.getProductId().split(",");
@ -199,6 +206,17 @@ public class YxWechatLiveServiceImpl extends BaseServiceImpl<YxWechatLiveMapper,
FileUtil.downloadExcel(list, response); FileUtil.downloadExcel(list, response);
} }
@Override
public Integer createRoom(WxMaLiveInfo.RoomInfo roomInfo) throws WxErrorException {
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
String responseContent = wxMaService.post(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 wxMaService WxMaService * @param wxMaService WxMaService