From 834b6128ebe34be6bdd981e695af4563b02500f1 Mon Sep 17 00:00:00 2001 From: xuwenbo <717567226@qq.com> Date: Tue, 11 Aug 2020 11:25:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E6=B7=BB=E5=8A=A0=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/menu.sql | 19 +++ sql/yx_wechat_live.sql | 43 +++++ .../yixiang/modules/services/AuthService.java | 3 - .../rest/controller/WechatController.java | 2 +- .../test/java/co/yixiang/test/BaseTest.java | 9 ++ yshop-common/pom.xml | 18 +++ .../modules/wechat/domain/YxWechatLive.java | 125 +++++++++++++++ .../wechat/rest/YxWechatLiveController.java | 85 ++++++++++ .../wechat}/service/WxMaLiveGoodsService.java | 6 +- .../wechat}/service/WxMaLiveService.java | 6 +- .../wechat/service/YxWechatLiveService.java | 51 ++++++ .../wechat/service/dto}/WxMaLiveInfo.java | 42 ++++- .../wechat/service/dto}/WxMaLiveResult.java | 2 +- .../wechat/service/dto/YxWechatLiveDto.java | 66 ++++++++ .../dto/YxWechatLiveQueryCriteria.java | 21 +++ .../impl/WxMaLiveGoodsServiceImpl.java | 58 +++++-- .../service/impl/WxMaLiveServiceImpl.java | 46 ++++-- .../service/impl/YxWechatLiveServiceImpl.java | 148 ++++++++++++++++++ .../service/mapper/YxWechatLiveMapper.java | 23 +++ .../shop/rest/SystemConfigController.java | 2 +- .../tools}/config/WxMaConfiguration.java | 5 +- yshop-weixin/pom.xml | 19 --- 22 files changed, 738 insertions(+), 61 deletions(-) create mode 100644 sql/menu.sql create mode 100644 sql/yx_wechat_live.sql create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/domain/YxWechatLive.java create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/rest/YxWechatLiveController.java rename {yshop-weixin/src/main/java/co/yixiang/mp => yshop-mall/src/main/java/co/yixiang/modules/wechat}/service/WxMaLiveGoodsService.java (96%) rename {yshop-weixin/src/main/java/co/yixiang/mp => yshop-mall/src/main/java/co/yixiang/modules/wechat}/service/WxMaLiveService.java (95%) create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/service/YxWechatLiveService.java rename {yshop-weixin/src/main/java/co/yixiang/mp/bean => yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto}/WxMaLiveInfo.java (53%) rename {yshop-weixin/src/main/java/co/yixiang/mp/bean => yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto}/WxMaLiveResult.java (98%) create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveDto.java create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveQueryCriteria.java rename {yshop-weixin/src/main/java/co/yixiang/mp => yshop-mall/src/main/java/co/yixiang/modules/wechat}/service/impl/WxMaLiveGoodsServiceImpl.java (66%) rename {yshop-weixin/src/main/java/co/yixiang/mp => yshop-mall/src/main/java/co/yixiang/modules/wechat}/service/impl/WxMaLiveServiceImpl.java (73%) create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/YxWechatLiveServiceImpl.java create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/wechat/service/mapper/YxWechatLiveMapper.java rename {yshop-weixin/src/main/java/co/yixiang/mp => yshop-tools/src/main/java/co/yixiang/tools}/config/WxMaConfiguration.java (95%) diff --git a/sql/menu.sql b/sql/menu.sql new file mode 100644 index 00000000..1176a7ee --- /dev/null +++ b/sql/menu.sql @@ -0,0 +1,19 @@ +/* + Navicat Premium Data Transfer + + Source Server : 本地 + Source Server Type : MySQL + Source Server Version : 50729 + Source Host : localhost:3306 + Source Schema : yshopb2c + + Target Server Type : MySQL + Target Server Version : 50729 + File Encoding : 65001 + + Date: 11/08/2020 11:23:45 +*/ + + +INSERT INTO `menu` VALUES (242, b'0', '直播管理', 'wechat/live/index', 48, 999, 'weixin', 'wxlive', b'0', b'0', 'Wxlive', '2020-08-10 17:20:54', NULL, 1, NULL, 0); + diff --git a/sql/yx_wechat_live.sql b/sql/yx_wechat_live.sql new file mode 100644 index 00000000..17ba7d26 --- /dev/null +++ b/sql/yx_wechat_live.sql @@ -0,0 +1,43 @@ +/* + Navicat Premium Data Transfer + + Source Server : 本地 + Source Server Type : MySQL + Source Server Version : 50729 + Source Host : localhost:3306 + Source Schema : yshopb2c + + Target Server Type : MySQL + Target Server Version : 50729 + File Encoding : 65001 + + Date: 11/08/2020 11:22:41 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for yx_wechat_live +-- ---------------------------- +DROP TABLE IF EXISTS `yx_wechat_live`; +CREATE TABLE `yx_wechat_live` ( + `roomid` bigint(11) NOT NULL COMMENT '直播间id', + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '直播间标题', + `cover_imge` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '背景图', + `share_imge` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '分享图片', + `live_status` int(9) NULL DEFAULT NULL COMMENT '直播间状态', + `start_time` bigint(11) NOT NULL COMMENT '开始时间', + `end_time` bigint(11) NOT NULL COMMENT '预计结束时间', + `anchor_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主播昵称', + `anchor_wechat` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主播微信号', + `anchor_imge` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '主播头像', + `type` tinyint(1) NOT NULL COMMENT '直播间类型 1:推流 0:手机直播', + `screen_type` tinyint(1) NOT NULL COMMENT '横屏、竖屏 【1:横屏,0:竖屏】', + `close_like` tinyint(1) NOT NULL COMMENT '是否关闭点赞 【0:开启,1:关闭】', + `close_comment` tinyint(1) NOT NULL COMMENT '是否关闭评论 【0:开启,1:关闭】', + `close_goods` tinyint(1) NOT NULL COMMENT '是否关闭货架 【0:开启,1:关闭】', + PRIMARY KEY (`roomid`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java b/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java index fb45ce04..8701e683 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java +++ b/yshop-app/src/main/java/co/yixiang/modules/services/AuthService.java @@ -17,7 +17,6 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import co.yixiang.api.YshopException; import co.yixiang.common.util.IpUtil; -import co.yixiang.common.util.JwtToken; import co.yixiang.constant.ShopConstants; import co.yixiang.enums.AppFromEnum; import co.yixiang.modules.auth.param.LoginParam; @@ -31,10 +30,8 @@ import co.yixiang.utils.EncryptUtils; import co.yixiang.utils.RedisUtils; import co.yixiang.utils.ShopKeyUtils; import co.yixiang.utils.StringUtils; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.vdurmont.emoji.EmojiParser; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; diff --git a/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WechatController.java b/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WechatController.java index d250832e..8fcacb02 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WechatController.java +++ b/yshop-app/src/main/java/co/yixiang/modules/wechat/rest/controller/WechatController.java @@ -26,7 +26,7 @@ import co.yixiang.modules.shop.service.YxSystemConfigService; import co.yixiang.modules.user.domain.YxUserRecharge; import co.yixiang.modules.user.service.YxUserRechargeService; -import co.yixiang.mp.config.WxMaConfiguration; +import co.yixiang.tools.config.WxMaConfiguration; import co.yixiang.mp.config.WxMpConfiguration; import co.yixiang.mp.config.WxPayConfiguration; import co.yixiang.utils.BigNum; diff --git a/yshop-app/src/test/java/co/yixiang/test/BaseTest.java b/yshop-app/src/test/java/co/yixiang/test/BaseTest.java index 66345551..08e306a5 100644 --- a/yshop-app/src/test/java/co/yixiang/test/BaseTest.java +++ b/yshop-app/src/test/java/co/yixiang/test/BaseTest.java @@ -1,12 +1,21 @@ package co.yixiang.test; +import co.yixiang.modules.wechat.service.dto.WxMaLiveInfo; +import co.yixiang.modules.wechat.service.WxMaLiveService; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class BaseTest { + @Autowired + private WxMaLiveService wxMaLiveService; + public void test(){ + WxMaLiveInfo.RoomInfo roomInfo = new WxMaLiveInfo.RoomInfo(); + roomInfo.setName("测试直播间"); + } } diff --git a/yshop-common/pom.xml b/yshop-common/pom.xml index 45712b2f..43d0f3f2 100644 --- a/yshop-common/pom.xml +++ b/yshop-common/pom.xml @@ -11,7 +11,25 @@ yshop-common 公共模块 + + 3.8.0 + + + com.github.binarywang + weixin-java-mp + ${weixin-java.version} + + + com.github.binarywang + weixin-java-pay + ${weixin-java.version} + + + com.github.binarywang + wx-java-miniapp-spring-boot-starter + ${weixin-java.version} + net.sf.dozer dozer-spring diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/domain/YxWechatLive.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/domain/YxWechatLive.java new file mode 100644 index 00000000..20a50f3a --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/domain/YxWechatLive.java @@ -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)); + } +} diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/rest/YxWechatLiveController.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/rest/YxWechatLiveController.java new file mode 100644 index 00000000..4d298d43 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/rest/YxWechatLiveController.java @@ -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 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 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 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 deleteAll(@RequestBody Long[] ids) { + Arrays.asList(ids).forEach(id->{ + yxWechatLiveService.removeById(id); + }); + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/service/WxMaLiveGoodsService.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/WxMaLiveGoodsService.java similarity index 96% rename from yshop-weixin/src/main/java/co/yixiang/mp/service/WxMaLiveGoodsService.java rename to yshop-mall/src/main/java/co/yixiang/modules/wechat/service/WxMaLiveGoodsService.java index a68f24da..a42a346a 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/service/WxMaLiveGoodsService.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/WxMaLiveGoodsService.java @@ -1,7 +1,7 @@ -package co.yixiang.mp.service; +package co.yixiang.modules.wechat.service; -import co.yixiang.mp.bean.WxMaLiveInfo; -import co.yixiang.mp.bean.WxMaLiveResult; +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; diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/service/WxMaLiveService.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/WxMaLiveService.java similarity index 95% rename from yshop-weixin/src/main/java/co/yixiang/mp/service/WxMaLiveService.java rename to yshop-mall/src/main/java/co/yixiang/modules/wechat/service/WxMaLiveService.java index 026718ff..beb0a8a2 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/service/WxMaLiveService.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/WxMaLiveService.java @@ -1,7 +1,7 @@ -package co.yixiang.mp.service; +package co.yixiang.modules.wechat.service; -import co.yixiang.mp.bean.WxMaLiveInfo; -import co.yixiang.mp.bean.WxMaLiveResult; +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; diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/YxWechatLiveService.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/YxWechatLiveService.java new file mode 100644 index 00000000..593e0324 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/YxWechatLiveService.java @@ -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{ + +/** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(YxWechatLiveQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(YxWechatLiveQueryCriteria criteria); + + + boolean saveLive(YxWechatLive resources); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/bean/WxMaLiveInfo.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/WxMaLiveInfo.java similarity index 53% rename from yshop-weixin/src/main/java/co/yixiang/mp/bean/WxMaLiveInfo.java rename to yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/WxMaLiveInfo.java index 45eb617f..f2ac30f3 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/bean/WxMaLiveInfo.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/WxMaLiveInfo.java @@ -1,4 +1,4 @@ -package co.yixiang.mp.bean; +package co.yixiang.modules.wechat.service.dto; import lombok.Data; @@ -31,18 +31,58 @@ public class WxMaLiveInfo implements Serializable { * 直播间背景图,图片规则:建议像素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; } diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/bean/WxMaLiveResult.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/WxMaLiveResult.java similarity index 98% rename from yshop-weixin/src/main/java/co/yixiang/mp/bean/WxMaLiveResult.java rename to yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/WxMaLiveResult.java index 403b1783..d0437d5f 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/bean/WxMaLiveResult.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/WxMaLiveResult.java @@ -1,4 +1,4 @@ -package co.yixiang.mp.bean; +package co.yixiang.modules.wechat.service.dto; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; import com.google.gson.annotations.SerializedName; diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveDto.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveDto.java new file mode 100644 index 00000000..30db2412 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveDto.java @@ -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; +} diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveQueryCriteria.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveQueryCriteria.java new file mode 100644 index 00000000..ad3089e7 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/dto/YxWechatLiveQueryCriteria.java @@ -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{ +} diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/service/impl/WxMaLiveGoodsServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/WxMaLiveGoodsServiceImpl.java similarity index 66% rename from yshop-weixin/src/main/java/co/yixiang/mp/service/impl/WxMaLiveGoodsServiceImpl.java rename to yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/WxMaLiveGoodsServiceImpl.java index 2141c509..c3b9d281 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/service/impl/WxMaLiveGoodsServiceImpl.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/WxMaLiveGoodsServiceImpl.java @@ -1,35 +1,45 @@ -package co.yixiang.mp.service.impl; +package co.yixiang.modules.wechat.service.impl; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; -import co.yixiang.mp.bean.WxMaLiveInfo; -import co.yixiang.mp.bean.WxMaLiveResult; -import co.yixiang.mp.config.WxMaConfiguration; -import co.yixiang.mp.service.WxMaLiveGoodsService; +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.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.io.Serializable; import java.util.HashMap; import java.util.List; import java.util.Map; -@AllArgsConstructor +@Slf4j +@Service public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { + @Value("${file.path}") + private String uploadDirStr; @Override public WxMaLiveResult addGoods(WxMaLiveInfo.Goods goods) throws WxErrorException { Map map = new HashMap<>(2); map.put("goodsInfo", goods); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -43,7 +53,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { map.put("auditId", auditId); map.put("goodsId", goodsId); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(RESET_AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -56,7 +66,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { Map map = new HashMap<>(2); map.put("goodsId", goodsId); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(AUDIT_GOODS, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -69,7 +79,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { Map map = new HashMap<>(2); map.put("goodsId", goodsId); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(DELETE_GOODS, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -82,7 +92,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { Map map = new HashMap<>(2); map.put("goodsInfo", goods); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(UPDATE_GOODS, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -95,7 +105,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { Map map = new HashMap<>(2); map.put("goods_ids", goodsIds); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(GET_GOODS_WARE_HOUSE, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -107,7 +117,7 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { public WxMaLiveResult getApprovedGoods(Integer offset, Integer limit, Integer status) throws WxErrorException { ImmutableMap params = ImmutableMap.of("status", status, "offset", offset, "limit", limit); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.get(GET_APPROVED_GOODS, Joiner.on("&").withKeyValueSeparator("=").join(params)); + 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)); @@ -127,4 +137,24 @@ public class WxMaLiveGoodsServiceImpl implements WxMaLiveGoodsService { 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; + } + } diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/service/impl/WxMaLiveServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/WxMaLiveServiceImpl.java similarity index 73% rename from yshop-weixin/src/main/java/co/yixiang/mp/service/impl/WxMaLiveServiceImpl.java rename to yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/WxMaLiveServiceImpl.java index 88b8a0c8..88635683 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/service/impl/WxMaLiveServiceImpl.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/WxMaLiveServiceImpl.java @@ -1,19 +1,26 @@ -package co.yixiang.mp.service.impl; +package co.yixiang.modules.wechat.service.impl; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; -import co.yixiang.mp.bean.WxMaLiveInfo; -import co.yixiang.mp.bean.WxMaLiveResult; -import co.yixiang.mp.config.WxMaConfiguration; -import co.yixiang.mp.service.WxMaLiveService; +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; @@ -27,27 +34,40 @@ import java.util.Map; * @author yjwang */ @Slf4j -@AllArgsConstructor +@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(CREATE_ROOM, WxMaGsonBuilder.create().toJson(roomInfo)); + 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 getLiveInfos() throws WxErrorException { List results = new ArrayList<>(); @@ -96,7 +116,7 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { map.put("roomId", roomId); map.put("ids", goodsIds); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(ADD_GOODS, WxMaGsonBuilder.create().toJson(map)); + 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)); @@ -111,11 +131,13 @@ public class WxMaLiveServiceImpl implements WxMaLiveService { map.put("start", start); map.put("limit", limit); WxMaService wxMaService = WxMaConfiguration.getWxMaService(); - String responseContent = wxMaService.post(GET_LIVE_INFO, WxMaGsonBuilder.create().toJson(map)); + 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; } + + } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/YxWechatLiveServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/YxWechatLiveServiceImpl.java new file mode 100644 index 00000000..57e50af8 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/impl/YxWechatLiveServiceImpl.java @@ -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 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 queryAll(YxWechatLiveQueryCriteria criteria, Pageable pageable) { + getPage(pageable); + PageInfo page = new PageInfo<>(queryAll(criteria)); + Map 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 queryAll(YxWechatLiveQueryCriteria criteria){ + return baseMapper.selectList(QueryHelpPlus.getPredicate(YxWechatLive.class, criteria)); + } + + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (YxWechatLiveDto yxWechatLive : all) { + Map 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; + } +} diff --git a/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/mapper/YxWechatLiveMapper.java b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/mapper/YxWechatLiveMapper.java new file mode 100644 index 00000000..90f93968 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/wechat/service/mapper/YxWechatLiveMapper.java @@ -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 { + +} diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/SystemConfigController.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/SystemConfigController.java index 9267ae86..b913ff20 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/SystemConfigController.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/SystemConfigController.java @@ -16,7 +16,7 @@ import co.yixiang.modules.aop.ForbidSubmit; import co.yixiang.modules.shop.domain.YxSystemConfig; import co.yixiang.modules.shop.service.YxSystemConfigService; import co.yixiang.modules.shop.service.dto.YxSystemConfigQueryCriteria; -import co.yixiang.mp.config.WxMaConfiguration; +import co.yixiang.tools.config.WxMaConfiguration; import co.yixiang.mp.config.WxMpConfiguration; import co.yixiang.mp.config.WxPayConfiguration; import co.yixiang.utils.RedisUtil; diff --git a/yshop-weixin/src/main/java/co/yixiang/mp/config/WxMaConfiguration.java b/yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java similarity index 95% rename from yshop-weixin/src/main/java/co/yixiang/mp/config/WxMaConfiguration.java rename to yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java index 73c07ed7..06017930 100644 --- a/yshop-weixin/src/main/java/co/yixiang/mp/config/WxMaConfiguration.java +++ b/yshop-tools/src/main/java/co/yixiang/tools/config/WxMaConfiguration.java @@ -1,11 +1,10 @@ -package co.yixiang.mp.config; +package co.yixiang.tools.config; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import cn.binarywang.wx.miniapp.message.WxMaMessageHandler; import cn.binarywang.wx.miniapp.message.WxMaMessageRouter; -import co.yixiang.mp.handler.LogHandler; import co.yixiang.utils.RedisUtil; import co.yixiang.utils.RedisUtils; import co.yixiang.utils.ShopKeyUtils; @@ -29,7 +28,7 @@ public class WxMaConfiguration { return routers.get(appid); } @Autowired - public WxMaConfiguration(RedisUtils redisUtils, LogHandler logHandler) { + public WxMaConfiguration(RedisUtils redisUtils) { this.redisUtils = redisUtils; this.wxMaMessageHandler = wxMaMessageHandler; } diff --git a/yshop-weixin/pom.xml b/yshop-weixin/pom.xml index ccbf78bb..c9515643 100644 --- a/yshop-weixin/pom.xml +++ b/yshop-weixin/pom.xml @@ -12,26 +12,7 @@ yshop-weixin 微信模块 - - 3.8.0 - - - - com.github.binarywang - weixin-java-mp - ${weixin-java.version} - - - com.github.binarywang - weixin-java-pay - ${weixin-java.version} - - - com.github.binarywang - wx-java-miniapp-spring-boot-starter - ${weixin-java.version} - co.yixiang yshop-mall