优化代码,修改发送短信
This commit is contained in:
@@ -369,7 +369,6 @@ public class SmsServiceImpl implements SmsService {
|
||||
Integer code = CrmebUtil.randomCount(111111, 999999);
|
||||
HashMap<String, Object> justPram = new HashMap<>();
|
||||
justPram.put("code", code);
|
||||
justPram.put("time", codeExpireStr);
|
||||
push(phone,SmsConstants.SMS_CONFIG_VERIFICATION_CODE,
|
||||
SmsConstants.SMS_CONFIG_VERIFICATION_CODE_TEMP_ID,false,justPram);
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ public class SystemCityServiceImpl extends ServiceImpl<SystemCityDao, SystemCity
|
||||
lambdaQueryWrapper.in(SystemCity::getIsShow, true);
|
||||
return dao.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
* @param id integer id
|
||||
|
||||
@@ -150,6 +150,7 @@ public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigDao, System
|
||||
//修改之前的数据
|
||||
updateStatusByFormId(systemFormCheckRequest.getId());
|
||||
|
||||
//批量插入
|
||||
saveBatch(systemConfigList);
|
||||
|
||||
//删除之前隐藏的数据
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.controller;
|
||||
|
||||
import com.common.CommonResult;
|
||||
import com.zbkj.crmeb.wechat.service.WechatMediaService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 微信回复表 前端控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("api/admin/wechat/media")
|
||||
@Api(tags = "微信开放平台 -- 素材")
|
||||
public class WechatMediaController {
|
||||
|
||||
@Autowired
|
||||
private WechatMediaService wechatMediaService;
|
||||
|
||||
/**
|
||||
* 上传
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "上传")
|
||||
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
||||
public CommonResult<Map<String, String>> upload(
|
||||
@RequestParam("media") @ApiParam(name = "media", value = "待上传素材图片文件", required = true) MultipartFile file,
|
||||
@RequestParam("type") @ApiParam(name = "type", value = "媒体文件类型,分别有图片(image)、语音(voice", required = true, allowableValues = "range[image,voice]") String type
|
||||
) throws Exception {
|
||||
return CommonResult.success(wechatMediaService.upload(file, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据素材id查询素材
|
||||
* @param mediaId String 关键字
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "根据素材id查询素材")
|
||||
@RequestMapping(value = "/get", method = RequestMethod.GET)
|
||||
public CommonResult<Map<String, Object>> get(@RequestParam(value = "mediaId") String mediaId){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String code = wechatMediaService.getMedia(mediaId);
|
||||
map.put("code", code);
|
||||
return CommonResult.success(map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.controller;
|
||||
|
||||
import com.common.CommonPage;
|
||||
import com.common.CommonResult;
|
||||
import com.common.PageParamRequest;
|
||||
import com.zbkj.crmeb.wechat.request.WechatMessageRequest;
|
||||
import com.zbkj.crmeb.wechat.request.WechatMessageSearchRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.zbkj.crmeb.wechat.service.WechatMessageService;
|
||||
import com.zbkj.crmeb.wechat.model.WechatMessage;
|
||||
|
||||
|
||||
/**
|
||||
* 用户行为记录表 前端控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("api/admin/wechat/user/log")
|
||||
@Api(tags = "微信开放平台 -- 用户行为记录")
|
||||
public class WechatMessageController {
|
||||
|
||||
@Autowired
|
||||
private WechatMessageService wechatMessageService;
|
||||
|
||||
/**
|
||||
* 分页显示用户行为记录表
|
||||
* @param request 搜索条件
|
||||
* @param pageParamRequest 分页参数
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "分页列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public CommonResult<CommonPage<WechatMessage>> getList(@Validated WechatMessageSearchRequest request, @Validated PageParamRequest pageParamRequest){
|
||||
CommonPage<WechatMessage> wechatMessageCommonPage = CommonPage.restPage(wechatMessageService.getList(request, pageParamRequest));
|
||||
return CommonResult.success(wechatMessageCommonPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户行为记录表
|
||||
* @param wechatMessageRequest 新增参数
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "新增")
|
||||
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
||||
public CommonResult<String> save(@Validated WechatMessageRequest wechatMessageRequest){
|
||||
WechatMessage wechatMessage = new WechatMessage();
|
||||
BeanUtils.copyProperties(wechatMessageRequest, wechatMessage);
|
||||
|
||||
if(wechatMessageService.save(wechatMessage)){
|
||||
return CommonResult.success();
|
||||
}else{
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户行为记录表
|
||||
* @param id Integer
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "删除")
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.GET)
|
||||
public CommonResult<String> delete(@RequestParam(value = "id") Integer id){
|
||||
if(wechatMessageService.removeById(id)){
|
||||
return CommonResult.success();
|
||||
}else{
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户行为记录表
|
||||
* @param id integer id
|
||||
* @param wechatMessageRequest 修改参数
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "修改")
|
||||
@RequestMapping(value = "/update", method = RequestMethod.POST)
|
||||
public CommonResult<String> update(@RequestParam Integer id, @Validated WechatMessageRequest wechatMessageRequest){
|
||||
WechatMessage wechatMessage = new WechatMessage();
|
||||
BeanUtils.copyProperties(wechatMessageRequest, wechatMessage);
|
||||
wechatMessage.setId(id);
|
||||
|
||||
if(wechatMessageService.updateById(wechatMessage)){
|
||||
return CommonResult.success();
|
||||
}else{
|
||||
return CommonResult.failed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户行为记录表信息
|
||||
* @param id Integer
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@ApiOperation(value = "详情")
|
||||
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
||||
public CommonResult<WechatMessage> info(@RequestParam(value = "id") Integer id){
|
||||
WechatMessage wechatMessage = wechatMessageService.getById(id);
|
||||
return CommonResult.success(wechatMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.dao;
|
||||
|
||||
import com.zbkj.crmeb.wechat.model.WechatMedia;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 微信回复表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
public interface WechatMediaDao extends BaseMapper<WechatMedia> {
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.dao;
|
||||
|
||||
import com.zbkj.crmeb.wechat.model.WechatMessage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户行为记录表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
public interface WechatMessageDao extends BaseMapper<WechatMessage> {
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 微信回复表
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("eb_wechat_media")
|
||||
@ApiModel(value="WechatMedia对象", description="微信回复表")
|
||||
public class WechatMedia implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "微信视频音频id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "回复类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "文件路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty(value = "微信服务器返回的id")
|
||||
private String mediaId;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "是否永久或者临时 0永久1临时")
|
||||
private Boolean temporary;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户行为记录表
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("eb_wechat_message")
|
||||
@ApiModel(value="WechatMessage对象", description="用户行为记录表")
|
||||
public class WechatMessage implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "用户行为记录id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "用户openid")
|
||||
private String openid;
|
||||
|
||||
@ApiModelProperty(value = "操作类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "操作详细记录")
|
||||
private String result;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.request;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 微信回复表
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("eb_wechat_media")
|
||||
@ApiModel(value="WechatMedia对象", description="微信回复表")
|
||||
public class WechatMediaRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "回复类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "文件路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty(value = "微信服务器返回的id")
|
||||
private String mediaId;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "是否永久或者临时 0永久1临时")
|
||||
private Boolean temporary;
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.request;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 微信回复表
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("eb_wechat_media")
|
||||
@ApiModel(value="WechatMedia对象", description="微信回复表")
|
||||
public class WechatMediaSearchRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "微信视频音频id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "回复类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "文件路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty(value = "微信服务器返回的id")
|
||||
private String mediaId;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "是否永久或者临时 0永久1临时")
|
||||
private Boolean temporary;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.request;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户行为记录表
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("eb_wechat_message")
|
||||
@ApiModel(value="WechatMessage对象", description="用户行为记录表")
|
||||
public class WechatMessageRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "用户openid")
|
||||
private String openid;
|
||||
|
||||
@ApiModelProperty(value = "操作类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "操作详细记录")
|
||||
private String result;
|
||||
|
||||
@ApiModelProperty(value = "操作时间")
|
||||
private Integer addTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.request;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户行为记录表
|
||||
* </p>
|
||||
*
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("eb_wechat_message")
|
||||
@ApiModel(value="WechatMessage对象", description="用户行为记录表")
|
||||
public class WechatMessageSearchRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID=1L;
|
||||
|
||||
@ApiModelProperty(value = "用户openid")
|
||||
private String openid;
|
||||
|
||||
@ApiModelProperty(value = "操作类型")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "操作详细记录")
|
||||
private String result;
|
||||
|
||||
@ApiModelProperty(value = "操作时间")
|
||||
private Integer addTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Mr.Zhang
|
||||
* @Description WechatMediaService 接口
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
public interface WechatMediaService{
|
||||
Map<String, String> upload(MultipartFile file, String type) throws Exception;
|
||||
|
||||
String getMedia(String mediaId);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.service;
|
||||
|
||||
import com.common.PageParamRequest;
|
||||
import com.zbkj.crmeb.wechat.model.WechatMessage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zbkj.crmeb.wechat.request.WechatMessageSearchRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Mr.Zhang
|
||||
* @Description WechatMessageService 接口
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
public interface WechatMessageService extends IService<WechatMessage> {
|
||||
|
||||
List<WechatMessage> getList(WechatMessageSearchRequest request, PageParamRequest pageParamRequest);
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.exception.CrmebException;
|
||||
import com.utils.CrmebUtil;
|
||||
import com.utils.RestTemplateUtil;
|
||||
import com.utils.UploadWeChatMediaUtil;
|
||||
import com.zbkj.crmeb.wechat.service.WeChatService;
|
||||
import com.zbkj.crmeb.wechat.service.WechatMediaService;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Mr.Zhang
|
||||
* @Description WechatMediaServiceImpl 接口实现
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Data
|
||||
@Service
|
||||
public class WechatMediaServiceImpl implements WechatMediaService {
|
||||
|
||||
@Autowired
|
||||
private WeChatService weChatService;
|
||||
|
||||
@Autowired
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
|
||||
private static final long maxSizeImage = 1024 * 1024 * 10;
|
||||
|
||||
private static final String suffixNameImage = "bmp,png,jpeg,jpg,gif";
|
||||
|
||||
private static final long maxSizeVoice = 1024 * 1024 * 2;
|
||||
|
||||
private static final String suffixNameVoice = "mp3,wma,wav,amr";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传素材到微信素材库
|
||||
* @param file MultipartFile 上传文件
|
||||
* @param type String 类型 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
* @return String
|
||||
*/
|
||||
public Map<String, String> upload(MultipartFile file, String type) throws Exception{
|
||||
try{
|
||||
String[] split = Objects.requireNonNull(file.getOriginalFilename()).split("\\.");
|
||||
String suffixName = split[split.length-1];
|
||||
isValidPic(file.getSize(), suffixName, type);
|
||||
|
||||
String url = weChatService.getUploadMedia() + "&type=" + type;
|
||||
JSONObject response = UploadWeChatMediaUtil.uploadFile(url, file.getResource().getInputStream(), file.getOriginalFilename());
|
||||
if(null == response || !response.containsKey("media_id")){
|
||||
assert response != null;
|
||||
throw new CrmebException("素材上传失败" + response.getString("errmsg"));
|
||||
}
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("mediaId", response.getString("media_id"));
|
||||
map.put("url", response.getString("url"));
|
||||
map.put("name", file.getOriginalFilename().replace(suffixName, ""));
|
||||
|
||||
return map;
|
||||
|
||||
// String mediaId = response.getString("media_id") ; //媒体文件id
|
||||
// int count = weChatService.getMediaCount(type); //总数
|
||||
//
|
||||
// if(count == 0){
|
||||
// throw new CrmebException("素材图片上传失败, 没有从微信服务器上找到相关信息");
|
||||
// }
|
||||
//
|
||||
// //获取最新的5个素材来对比
|
||||
// JSONObject info = weChatService.getMediaInfo(type, count-1, 5); //微信返回数据是倒序排序,所以拿到最新的5个即可,这里考虑到并发上传的问题,如果不存在并发只需要拿最新的一个即可
|
||||
// if(null == info){
|
||||
// throw new CrmebException("素材图片上传失败, 没有从微信服务器上找到相关信息1");
|
||||
// }
|
||||
// String mediaUrl = "";
|
||||
// List<MediaDetailVo> list = JSONObject.parseArray(info.toJSONString(), MediaDetailVo.class);
|
||||
// for (MediaDetailVo mediaDetailVo : list) {
|
||||
// if(mediaId.equals(mediaDetailVo.getMediaId())){
|
||||
// mediaUrl = mediaDetailVo.getUrl();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(StringUtils.isBlank(mediaUrl)){
|
||||
// throw new CrmebException("素材图片上传失败, 没有从微信服务器上找到相关信息2");
|
||||
// }
|
||||
//
|
||||
// Map<String, String> map = new HashMap<>();
|
||||
// map.put("mediaId", mediaId);
|
||||
// map.put("mediaUrl", mediaUrl);
|
||||
//
|
||||
// return map;
|
||||
|
||||
}catch (Exception e){
|
||||
throw new CrmebException(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据素材id查询素材
|
||||
* @param mediaId String 关键字
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String getMedia(String mediaId) {
|
||||
String url = weChatService.getUploadMedia();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("media_id", mediaId);
|
||||
byte[] bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, JSONObject.parseObject("{\"media_id\", mediaId}"));
|
||||
return CrmebUtil.getBase64Image(Base64.encodeBase64String(bytes));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否符合微信规范
|
||||
* @param size long 文件大小
|
||||
* @param suffixName String 后缀名
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
private void isValidPic(long size, String suffixName, String type) {
|
||||
JSONObject config = getConfig();
|
||||
if(!config.containsKey(type)){
|
||||
throw new CrmebException("不支持此类型");
|
||||
}
|
||||
|
||||
long supportSize = config.getJSONObject(type).getLong("size");
|
||||
if(supportSize < size){
|
||||
throw new CrmebException("文件大小不能超过" + supportSize);
|
||||
}
|
||||
String supportNameSuffix = config.getJSONObject(type).getString("suffix");
|
||||
List<String> suffixNameList = CrmebUtil.stringToArrayStr(supportNameSuffix);
|
||||
if(!suffixNameList.contains(suffixName)){
|
||||
throw new CrmebException("文件格式必须是" + supportSize);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数配置
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
* @return JSONObject
|
||||
*/
|
||||
private JSONObject getConfig(){
|
||||
String data = "{" +
|
||||
"image:{size:\""+maxSizeImage+"\", suffix: \""+suffixNameImage+"\"}, " +
|
||||
"voice:{size:\""+maxSizeVoice+"\", suffix: \""+suffixNameVoice+"\"}" +
|
||||
"}";
|
||||
return JSONObject.parseObject(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.zbkj.crmeb.wechat.service.impl;
|
||||
|
||||
import com.common.PageParamRequest;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.utils.CrmebUtil;
|
||||
|
||||
import com.zbkj.crmeb.wechat.model.WechatMessage;
|
||||
import com.zbkj.crmeb.wechat.dao.WechatMessageDao;
|
||||
import com.zbkj.crmeb.wechat.request.WechatMessageSearchRequest;
|
||||
import com.zbkj.crmeb.wechat.service.WechatMessageService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Mr.Zhang
|
||||
* @Description WechatMessageServiceImpl 接口实现
|
||||
* @since 2020-04-18
|
||||
*/
|
||||
@Service
|
||||
public class WechatMessageServiceImpl extends ServiceImpl<WechatMessageDao, WechatMessage> implements WechatMessageService {
|
||||
|
||||
@Resource
|
||||
private WechatMessageDao dao;
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param request 请求参数
|
||||
* @param pageParamRequest 分页类参数
|
||||
* @author Mr.Zhang
|
||||
* @since 2020-04-18
|
||||
* @return List<WechatMessage>
|
||||
*/
|
||||
@Override
|
||||
public List<WechatMessage> getList(WechatMessageSearchRequest request, PageParamRequest pageParamRequest) {
|
||||
PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
|
||||
return dao.selectList(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user