最新代码

This commit is contained in:
admin
2024-04-19 17:20:40 +08:00
parent e4032a0183
commit 993f975edd
82 changed files with 2618 additions and 248 deletions

View File

@@ -1,30 +1,40 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import com.google.common.annotations.VisibleForTesting;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.starry.admin.common.aspect.ClerkUserLogin;
import com.starry.admin.common.conf.ThreadLocalRequestDetail;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.clear.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clear.module.entity.*;
import com.starry.admin.modules.clear.module.vo.PlayClerkCommodityEditVo;
import com.starry.admin.modules.clear.module.vo.PlayClerkCommodityQueryVo;
import com.starry.admin.modules.clear.service.IPlayClerkClassificationInfoService;
import com.starry.admin.modules.clear.service.IPlayClerkCommodityService;
import com.starry.admin.modules.clear.service.IPlayClerkLevelInfoService;
import com.starry.admin.modules.clear.service.IPlayClerkUserInfoService;
import com.starry.admin.modules.clear.service.impl.PlayClerkDataReviewInfoServiceImpl;
import com.starry.admin.modules.clear.service.impl.PlayClerkUserInfoServiceImpl;
import com.starry.admin.modules.weichat.entity.PlayClerkUserAddVo;
import com.starry.admin.modules.weichat.entity.PlayClerkUserBindCodeVo;
import com.starry.admin.modules.weichat.entity.PlayClerkUserSendCodeVo;
import com.starry.admin.modules.weichat.entity.*;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.redis.RedisCache;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import com.starry.common.utils.VerificationCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* @author admin
@@ -38,12 +48,53 @@ public class WxClerkController {
@Resource
RedisCache redisCache;
@Resource
private PlayClerkUserInfoServiceImpl playClerkUserInfoService;
@Resource
private PlayClerkDataReviewInfoServiceImpl dataReviewInfoService;
@Resource
private IPlayClerkLevelInfoService playClerkLevelInfoService;
@Resource
private IPlayClerkClassificationInfoService playClerkClassificationInfoService;
@Resource
private IPlayClerkUserInfoService clerkUserInfoService;
@Resource
private IPlayClerkCommodityService playClerkCommodityService;
@ClerkUserLogin
@GetMapping("/user/queryById")
public R sendCode(@RequestParam("id") String id) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(id);
if (entity == null) {
throw new CustomException("用户不存在");
}
return R.ok(clerkUserInfoService.getVo(entity));
}
@ClerkUserLogin
@GetMapping("/user/deleteNotReviewInfo")
public R deleteNotReviewInfo(@RequestParam("id") String id) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(id);
if (entity == null) {
throw new CustomException("用户不存在");
}
LambdaQueryWrapper<PlayClerkDataReviewInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PlayClerkDataReviewInfoEntity::getPlayUserId, entity.getOpenid());
dataReviewInfoService.remove(queryWrapper);
return R.ok("成功");
}
@ClerkUserLogin
@PostMapping("/user/sendCode")
public R sendCode(@VisibleForTesting @RequestBody PlayClerkUserSendCodeVo vo) {
public R sendCode(@Valid @RequestBody PlayClerkUserSendCodeVo vo) {
String codeKey = "login_codes:" + SecurityUtils.getTenantId() + "_" + SecureUtil.md5(vo.getAreaCode() + vo.getPhone());
String code = VerificationCodeUtils.getVerificationCode(4);
redisCache.setCacheObject(codeKey, code, 5L, TimeUnit.MINUTES);
@@ -53,26 +104,277 @@ public class WxClerkController {
@ClerkUserLogin
@PostMapping("/user/bindCode")
public R bindCode(@VisibleForTesting @RequestBody PlayClerkUserBindCodeVo vo) {
public R bindCode(@Valid @RequestBody PlayClerkUserBindCodeVo vo) {
String codeKey = "login_codes:" + SecurityUtils.getTenantId() + "_" + SecureUtil.md5(vo.getAreaCode() + vo.getPhone());
String code = redisCache.getCacheObject(codeKey);
if (code == null || !code.equals(vo.getCode())) {
throw new CustomException("验证码错误");
}
redisCache.deleteObject(codeKey);
// 账号绑定操作
String id = ThreadLocalRequestDetail.getClerkUserInfo().getId();
PlayClerkUserInfoEntity clerkUserInfoEntity = new PlayClerkUserInfoEntity();
clerkUserInfoEntity.setId(id);
clerkUserInfoEntity.setPhone(vo.getPhone());
playClerkUserInfoService.update(clerkUserInfoEntity);
// 删除验证码缓存
redisCache.deleteObject(codeKey);
return R.ok("成功");
}
@ClerkUserLogin
@PostMapping("/user/add")
public R userAdd(@Valid @RequestBody PlayClerkUserAddVo vo) {
PlayClerkUserInfoEntity entity = ThreadLocalRequestDetail.getClerkUserInfo();
BeanUtils.copyProperties(vo, entity);
entity.setPlayUserId("0001");
playClerkUserInfoService.update(entity);
public R userAdd(@Valid @RequestBody PlayClerkUserByWxAddVo vo) {
String playUserId = ThreadLocalRequestDetail.getClerkUserInfo().getId();
PlayClerkUserInfoEntity userInfo = playClerkUserInfoService.selectById(playUserId);
if (userInfo == null) {
throw new CustomException("系统错误,用户不存在");
}
if (userInfo.getClerkState().equals("1")) {
throw new CustomException("当前用户已经是店员");
}
PlayClerkDataReviewInfoEntity dataReviewInfo = new PlayClerkDataReviewInfoEntity();
dataReviewInfo.setPlayUserId(userInfo.getId());
dataReviewInfo.setState("0");
dataReviewInfo.setDataType("0");
if (!dataReviewInfoService.queryList(dataReviewInfo).isEmpty()) {
throw new CustomException("已有申请未审核");
}
dataReviewInfo.setContent(JSONObject.toJSONString(vo));
dataReviewInfo.setAddTime(new Date());
dataReviewInfoService.create(dataReviewInfo);
return R.ok("申请成功");
}
@ClerkUserLogin
@PostMapping("/user/updateAvatar")
public R updateAvatar(@Valid @RequestBody PlayClerkUserAvatarVo vo) {
PlayClerkUserInfoEntity userInfo = ThreadLocalRequestDetail.getClerkUserInfo();
PlayClerkDataReviewInfoEntity dataReviewInfo = new PlayClerkDataReviewInfoEntity();
dataReviewInfo.setPlayUserId(userInfo.getId());
dataReviewInfo.setState("0");
dataReviewInfo.setDataType("1");
if (!dataReviewInfoService.queryList(dataReviewInfo).isEmpty()) {
throw new CustomException("已有申请未审核");
}
dataReviewInfo.setContent(JSONObject.toJSONString(vo));
dataReviewInfo.setAddTime(new Date());
dataReviewInfoService.create(dataReviewInfo);
return R.ok("申请成功");
}
@ClerkUserLogin
@PostMapping("/user/updateAlbum")
public R updateAlbum(@Valid @RequestBody PlayClerkUserAlbumVo vo) {
PlayClerkUserInfoEntity userInfo = ThreadLocalRequestDetail.getClerkUserInfo();
PlayClerkDataReviewInfoEntity dataReviewInfo = new PlayClerkDataReviewInfoEntity();
dataReviewInfo.setPlayUserId(userInfo.getId());
dataReviewInfo.setState("0");
dataReviewInfo.setDataType("2");
if (!dataReviewInfoService.queryList(dataReviewInfo).isEmpty()) {
throw new CustomException("已有申请未审核");
}
dataReviewInfo.setContent(JSONObject.toJSONString(vo));
dataReviewInfoService.create(dataReviewInfo);
return R.ok("申请成功");
}
@ClerkUserLogin
@PostMapping("/user/updateAudio")
public R updateAudio(@Valid @RequestBody PlayClerkUserAudioVo vo) {
PlayClerkUserInfoEntity userInfo = ThreadLocalRequestDetail.getClerkUserInfo();
PlayClerkDataReviewInfoEntity dataReviewInfo = new PlayClerkDataReviewInfoEntity();
dataReviewInfo.setPlayUserId(userInfo.getId());
dataReviewInfo.setState("0");
dataReviewInfo.setDataType("3");
if (!dataReviewInfoService.queryList(dataReviewInfo).isEmpty()) {
throw new CustomException("已有申请未审核");
}
dataReviewInfo.setContent(JSONObject.toJSONString(vo));
dataReviewInfoService.create(dataReviewInfo);
return R.ok("申请成功");
}
@ClerkUserLogin
@PostMapping("/user/updateOnlineState")
public R updateAudio(@Valid @RequestBody PlayClerkUserOnlineStateVo vo) {
String userId = ThreadLocalRequestDetail.getClerkUserInfo().getId();
PlayClerkUserInfoEntity entity = new PlayClerkUserInfoEntity();
entity.setOnlineState(vo.getOnlineState());
entity.setId(userId);
playClerkUserInfoService.update(entity);
return R.ok("修改成功");
}
@ClerkUserLogin
@PostMapping("/user/updateCommodity")
public R updateAudio(@Valid @RequestBody PlayClerkCommodityEditVo vo) {
playClerkCommodityService.startStopClerkItem(vo.getCommodityType(), vo.getEnablingState());
return R.ok("成功");
}
@ClerkUserLogin
@PostMapping("/user/updateOther")
public R updateOther(@Valid @RequestBody PlayClerkUserOtherVo vo) {
PlayClerkUserInfoEntity userInfo = ConvertUtil.entityToVo(vo, PlayClerkUserInfoEntity.class);
userInfo.setId(ThreadLocalRequestDetail.getClerkUserInfo().getId());
playClerkUserInfoService.update(userInfo);
return R.ok("申请成功");
}
/**
* 查询陪玩服务项目列表
*/
@GetMapping("/user/listAllCommodity")
public R listAllCommodity() {
List<PlayClerkCommodityEntity> list = playClerkCommodityService.selectAll();
return R.ok(ConvertUtil.entityToVoList(list, PlayClerkCommodityQueryVo.class));
}
/**
* 分页获取店员列表
*
* @param vo PlayClerkUserInfoQueryVo
* @return 店员礼列表
*/
@PostMapping("/user/queryByPage")
public R queryByPage(@RequestBody PlayClerkUserInfoQueryVo vo) {
IPage<PlayClerkUserInfoEntity> page = playClerkUserInfoService.selectPlayClerkUserInfoByPage(vo);
List<PlayClerkUserListResultVo> resultVos = new ArrayList<>();
for (PlayClerkUserInfoEntity record : page.getRecords()) {
PlayClerkUserListResultVo item = ConvertUtil.entityToVo(record, PlayClerkUserListResultVo.class);
List<String> list = playClerkCommodityService.selectByUser(record.getId()).stream().map(PlayClerkCommodityEntity::getCommodityType).collect(Collectors.toList());
item.setCommodity(list);
resultVos.add(item);
}
IPage<PlayClerkUserListResultVo> resultPage = new Page<>();
resultPage.setRecords(resultVos);
// 设置分页参数
resultPage.setCurrent(page.getCurrent());
resultPage.setSize(page.getSize());
resultPage.setTotal(resultVos.size()); // 假设total和实际情况一致
return R.ok(resultPage);
}
/**
* 获取店员礼物信息
*
* @param id 店员ID
* @return 店员礼物
*/
@GetMapping("/user/queryGiftById")
public R queryGiftById(@RequestParam("id") String id) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(id);
if (entity == null) {
throw new CustomException("用户不存在");
}
List<PlayGiftInfoEntity> list = new ArrayList<>();
list.add(new PlayGiftInfoEntity(IdUtil.fastSimpleUUID(), "礼物1", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", 0, "0"));
list.add(new PlayGiftInfoEntity(IdUtil.fastSimpleUUID(), "礼物2", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", 1, "0"));
list.add(new PlayGiftInfoEntity(IdUtil.fastSimpleUUID(), "礼物3", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", 2, "1"));
list.add(new PlayGiftInfoEntity(IdUtil.fastSimpleUUID(), "礼物4", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", 3, "1"));
list.add(new PlayGiftInfoEntity(IdUtil.fastSimpleUUID(), "礼物5", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", 4, "1"));
return R.ok(list);
}
/**
* 获取店员价格
*
* @param id 店员ID
* @return 店员价格
*/
@GetMapping("/user/queryPriceById")
public R queryDetailById(@RequestParam("id") String id) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(id);
if (entity == null) {
throw new CustomException("用户不存在");
}
return R.ok(playClerkCommodityService.selectByUser(entity.getId()));
}
/**
* 分页获取店员动态
*
* @param id 店员ID
* @return 店员动态
*/
@GetMapping("/user/queryTrendsById")
public R queryTrendsById(@RequestParam("id") String id) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(id);
if (entity == null) {
throw new CustomException("用户不存在");
}
List<PlayClarkUserTrendsInfoEntity> entities = new ArrayList<>();
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态1", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/0596854e16ae4a268eab4c08e2a9f762.mp3", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态2", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/0596854e16ae4a268eab4c08e2a9f762.mp3", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态3", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/0596854e16ae4a268eab4c08e2a9f762.mp3", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态4", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/0596854e16ae4a268eab4c08e2a9f762.mp3", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态5", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/0596854e16ae4a268eab4c08e2a9f762.mp3", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态6", "0", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态7", "0", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", new Date()));
entities.add(new PlayClarkUserTrendsInfoEntity(IdUtil.fastSimpleUUID(), "动态8", "0", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", new Date()));
IPage<PlayClarkUserTrendsInfoEntity> resultPage = new Page<>();
resultPage.setRecords(entities);
// 设置分页参数
resultPage.setCurrent(1);
resultPage.setSize(1);
resultPage.setTotal(5); // 假设total和实际情况一致
return R.ok(resultPage);
}
/**
* 分页获取店员评价
*
* @param id 店员ID
* @return 店员评价
*/
@GetMapping("/user/queryEvaluateById")
public R queryEvaluateById(@RequestParam("id") String id) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(id);
if (entity == null) {
throw new CustomException("用户不存在");
}
List<PlayClarkUserEvaluateInfoEntity> entities = new ArrayList<>();
entities.add(new PlayClarkUserEvaluateInfoEntity(IdUtil.fastSimpleUUID(), IdUtil.fastSimpleUUID(), "评价人1昵称", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", "评价内容", new Date(), IdUtil.fastSimpleUUID(), "店员昵称", IdUtil.fastSimpleUUID(), "文字语音条", "一小时"));
entities.add(new PlayClarkUserEvaluateInfoEntity(IdUtil.fastSimpleUUID(), IdUtil.fastSimpleUUID(), "评价人2昵称", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", "评价内容", new Date(), IdUtil.fastSimpleUUID(), "店员昵称", IdUtil.fastSimpleUUID(), "文字语音条", "一小时"));
entities.add(new PlayClarkUserEvaluateInfoEntity(IdUtil.fastSimpleUUID(), IdUtil.fastSimpleUUID(), "评价人3昵称", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", "评价内容", new Date(), IdUtil.fastSimpleUUID(), "店员昵称", IdUtil.fastSimpleUUID(), "文字语音条", "一小时"));
entities.add(new PlayClarkUserEvaluateInfoEntity(IdUtil.fastSimpleUUID(), IdUtil.fastSimpleUUID(), "评价人4昵称", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", "评价内容", new Date(), IdUtil.fastSimpleUUID(), "店员昵称", IdUtil.fastSimpleUUID(), "文字语音条", "一小时"));
entities.add(new PlayClarkUserEvaluateInfoEntity(IdUtil.fastSimpleUUID(), IdUtil.fastSimpleUUID(), "评价人5昵称", "https://live-cloud-cvoon.oss-cn-hangzhou.aliyuncs.com/d8e929c041e94075b93cfc6338a83d4c/2024/04/15/fc09da2f923d46e6951292ff8f34f6aa.png", "评价内容", new Date(), IdUtil.fastSimpleUUID(), "店员昵称", IdUtil.fastSimpleUUID(), "文字语音条", "一小时"));
IPage<PlayClarkUserEvaluateInfoEntity> resultPage = new Page<>();
resultPage.setRecords(entities);
// 设置分页参数
resultPage.setCurrent(1);
resultPage.setSize(1);
resultPage.setTotal(5); // 假设total和实际情况一致
return R.ok(resultPage);
}
@GetMapping("/level/queryAll")
public R userAdd() {
return R.ok(playClerkLevelInfoService.selectAll());
}
@GetMapping("/class/queryAll")
public R queryClassAll() {
return R.ok(playClerkClassificationInfoService.selectAll());
}
}

View File

@@ -1,16 +1,33 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.core.io.FastByteArrayOutputStream;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.common.oss.service.IOssFileService;
import com.starry.admin.modules.system.service.ISysAdministrativeAreaDictInfoService;
import com.starry.admin.modules.weichat.service.WxAccessTokenService;
import com.starry.admin.modules.weichat.utils.WxFileUtils;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
/**
* @author 杭州世平信息科技有限公司-xuhq
* @author admin
* @since 2024/4/10 16:18
**/
@Slf4j
@@ -18,12 +35,72 @@ import javax.annotation.Resource;
@RequestMapping("/wx/common/")
public class WxCommonController {
@Resource
private IOssFileService ossFileService;
@Resource
private ISysAdministrativeAreaDictInfoService areaDictInfoService;
@Resource
WxAccessTokenService wxAccessTokenService;
@GetMapping("area/tree")
public R list() {
public R areaTree() {
return R.ok(areaDictInfoService.selectTree("2"));
}
@PostMapping("file/upload")
public R fileUpload(@RequestParam("file") MultipartFile file) throws IOException {
String fileAddress = ossFileService.upload(file.getInputStream(), SecurityUtils.getTenantId(), file.getOriginalFilename());
return R.ok(fileAddress);
}
@GetMapping("audio/upload")
public R audioUpload(@RequestParam("mediaId") String mediaId) throws IOException, WxErrorException {
if (StrUtil.isBlankIfStr(mediaId)) {
throw new CustomException("mediaId不能为空");
}
String accessToken = wxAccessTokenService.getAccessToken();
// 下载录音文件并转化为InputStream
InputStream inputStream = WxFileUtils.getTemporaryMaterial(accessToken, mediaId);
try {
FastByteArrayOutputStream read = IoUtil.read(inputStream, false);
String str = new String(read.toByteArray(), StandardCharsets.UTF_8);
JSONObject jsonObject = JSONObject.parseObject(str);
if (jsonObject.containsKey("errcode")) {
throw new CustomException("获取微信素材异常" + jsonObject.getString("errmsg"));
}
} catch (Exception e) {
log.error("获取微信素材异常,", e);
throw new CustomException("获取微信素材异常");
}
File tempFile = FileUtil.createTempFile("wx_" + SecurityUtils.getTenantId(), IdUtil.fastSimpleUUID() + ".tmp", null).toFile();
// 可以在这里对临时文件进行操作
log.debug("tempFile = {}", tempFile.getPath());
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
// 读取InputStream并写入到FileOutputStream
while ((bytesRead = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
}
if (FileUtil.size(tempFile) <= 0) {
throw new CustomException("音频文件上传失败,文件不存在");
}
//将下载的微信素材文件转化为MP3文件
File targetFile = FileUtil.createTempFile("wx_" + SecurityUtils.getTenantId(), IdUtil.fastSimpleUUID() + ".mp3", null).toFile();
log.debug("targetFile = {}", targetFile.getPath());
WxFileUtils.audioConvert2Mp3(tempFile, targetFile);
//将MP3文件上传到OSS
String fileAddress = ossFileService.upload(Files.newInputStream(targetFile.toPath()), SecurityUtils.getTenantId(), IdUtil.fastSimpleUUID() + ".mp3");
//删除临时文件
FileUtil.del(tempFile);
FileUtil.del(targetFile);
return R.ok(fileAddress);
}
}

View File

@@ -0,0 +1,31 @@
package com.starry.admin.modules.weichat.controller;
import com.starry.admin.modules.clear.service.IPlayClerkLevelInfoService;
import com.starry.admin.modules.clear.service.impl.PlayClerkUserInfoServiceImpl;
import com.starry.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author admin
*/
@Slf4j
@RestController
@RequestMapping("/wx/custom/")
public class WxCustomController {
@Resource
private PlayClerkUserInfoServiceImpl playClerkUserInfoService;
}

View File

@@ -0,0 +1,41 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.core.util.StrUtil;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.platform.entity.SysTenantEntity;
import com.starry.admin.modules.platform.service.impl.SysTenantServiceImpl;
import com.starry.admin.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.config.impl.WxMpMapConfigImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Slf4j
@Service
public class WxCustomService {
@Resource
private WxMpService wxMpService;
@Resource
private SysTenantServiceImpl tenantService;
public WxMpService proxyWxMpService() {
String tenantId = SecurityUtils.getTenantId();
if (StrUtil.isBlankIfStr(tenantId)) {
throw new CustomException("系统错误,租户ID不能为空");
}
SysTenantEntity entity = tenantService.selectSysTenantByTenantId(tenantId);
if (entity == null) {
throw new CustomException("系统错误,租户ID不能为空");
}
WxMpMapConfigImpl config = new WxMpMapConfigImpl();
config.setAppId(entity.getAppId());
config.setSecret(entity.getSecret());
wxMpService.addConfigStorage(entity.getAppId(), config);
return wxMpService.switchoverTo(entity.getAppId());
}
}

View File

@@ -1,12 +1,12 @@
package com.starry.admin.modules.weichat.controller;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.starry.admin.common.aspect.ClerkUserLogin;
import com.starry.admin.common.aspect.CustomUserLogin;
import com.starry.admin.common.conf.ThreadLocalRequestDetail;
import com.starry.admin.common.exception.CustomException;
import com.starry.admin.modules.clear.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clear.service.IPlayClerkUserInfoService;
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
@@ -15,10 +15,11 @@ import com.starry.admin.modules.weichat.entity.WxUserLoginVo;
import com.starry.admin.modules.weichat.entity.WxUserQueryAddressVo;
import com.starry.admin.modules.weichat.service.WxOauthService;
import com.starry.admin.modules.weichat.service.WxTokenService;
import com.starry.admin.utils.SecurityUtils;
import com.starry.common.redis.RedisCache;
import com.starry.common.result.R;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -40,7 +41,7 @@ public class WxOauthController {
@Resource
private WxMpService wxMpService;
private WxCustomService wxCustomService;
@Resource
private IPlayCustomUserInfoService customUserInfoService;
@@ -54,6 +55,20 @@ public class WxOauthController {
@Resource
private WxOauthService wxOauthService;
@Resource
private RedisCache redisCache;
@PostMapping("/getConfigAddress")
public R getConfigAddress(@RequestBody WxUserQueryAddressVo vo) throws WxErrorException {
// 默认回调地址
String defaultAddress = "http://july.hucs.top/api/wx/oauth2/clerkLoginCallback";
if (!StrUtil.isBlankIfStr(vo.getUrl())) {
defaultAddress = vo.getUrl();
}
WxJsapiSignature wxJsapiSignature = wxCustomService.proxyWxMpService().createJsapiSignature(defaultAddress);
return R.ok(wxJsapiSignature);
}
@PostMapping("/getClerkLoginAddress")
public R getClerkLoginAddress(@RequestBody WxUserQueryAddressVo vo) {
@@ -62,7 +77,7 @@ public class WxOauthController {
if (!StrUtil.isBlankIfStr(vo.getUrl())) {
defaultAddress = vo.getUrl();
}
String url = wxMpService.getOAuth2Service().buildAuthorizationUrl(defaultAddress, "snsapi_userinfo", "STATE");
String url = wxCustomService.proxyWxMpService().getOAuth2Service().buildAuthorizationUrl(defaultAddress, "snsapi_userinfo", "STATE");
return R.ok(url);
}
@@ -76,23 +91,34 @@ public class WxOauthController {
public R clerkLogin(@Valid @RequestBody WxUserLoginVo vo) {
String userId = wxOauthService.clarkUserLogin(vo.getCode());
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(userId);
// 线程塞入租户ID
SecurityUtils.setTenantId(Convert.toStr(entity.getTenantId()));
JSONObject jsonObject = JSONObject.from(entity);
String tokenForMiniUser = tokenService.createWxUserToken(entity.getId());
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenForMiniUser);
if (entity == null) {
throw new CustomException("用户不存在");
}
// 缓存租户信息
String redisKey = "TENANT_INFO:" + entity.getId();
redisCache.setCacheObject(redisKey, entity.getTenantId());
String tokenValue = tokenService.createWxUserToken(entity.getId());
JSONObject jsonObject = JSONObject.from(clerkUserInfoService.getVo(entity));
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenValue);
jsonObject.put("tokenName", CLERK_USER_LOGIN_TOKEN);
jsonObject.put("loginDate", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
clerkUserInfoService.updateTokenById(entity.getId(), tokenValue);
return R.ok(jsonObject);
}
@PostMapping("/clark/loginById")
public R loginById(@Valid @RequestBody WxUserLoginVo vo) {
PlayClerkUserInfoEntity entity = clerkUserInfoService.selectById(vo.getCode());
JSONObject jsonObject = JSONObject.from(entity);
if (entity == null) {
throw new CustomException("用户不存在");
}
// 缓存租户信息
String redisKey = "TENANT_INFO:" + entity.getId();
redisCache.setCacheObject(redisKey, entity.getTenantId());
JSONObject jsonObject = JSONObject.from(clerkUserInfoService.getVo(entity));
String tokenValue = tokenService.createWxUserToken(entity.getId());
jsonObject.put("tokenValue", tokenValue);
jsonObject.put("tokenName", TOKEN_PREFIX + CLERK_USER_LOGIN_TOKEN);
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenValue);
jsonObject.put("tokenName", CLERK_USER_LOGIN_TOKEN);
jsonObject.put("loginDate", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
clerkUserInfoService.updateTokenById(entity.getId(), tokenValue);
return R.ok(jsonObject);
@@ -113,7 +139,7 @@ public class WxOauthController {
if (!StrUtil.isBlankIfStr(vo.getUrl())) {
defaultAddress = vo.getUrl();
}
String url = wxMpService.getOAuth2Service().buildAuthorizationUrl(defaultAddress, "snsapi_userinfo", "STATE");
String url = wxCustomService.proxyWxMpService().getOAuth2Service().buildAuthorizationUrl(defaultAddress, "snsapi_userinfo", "STATE");
return R.ok(url);
}
@@ -127,6 +153,12 @@ public class WxOauthController {
public R customLogin(@Valid @RequestBody WxUserLoginVo vo) {
String userId = wxOauthService.customUserLogin(vo.getCode());
PlayCustomUserInfoEntity entity = customUserInfoService.selectById(userId);
if (entity == null) {
throw new CustomException("用户不存在");
}
// 缓存租户信息
String redisKey = "TENANT_INFO:" + entity.getId();
redisCache.setCacheObject(redisKey, entity.getTenantId());
JSONObject jsonObject = JSONObject.from(entity);
String tokenValue = tokenService.createWxUserToken(entity.getId());
jsonObject.put("tokenValue", TOKEN_PREFIX + tokenValue);

View File

@@ -0,0 +1,22 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* 店员相册实体
*
* @author admin
* @since 2024/4/11 11:19
**/
@Data
public class PlayClerkUserAlbumVo {
@NotNull(message = "照片不能为空")
@Size(min = 1, max = 5, message = "照片必须为1-5张")
private List<String> album;
}

View File

@@ -0,0 +1,22 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 店员录音文件
*
* @author admin
* @since 2024/4/11 11:19
**/
@Data
public class PlayClerkUserAudioVo {
/**
* 录音
*/
@NotNull(message = "录音文件不能为空")
private String audio;
}

View File

@@ -0,0 +1,27 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 店员头像信息
*
* @author admin
* @since 2024/4/11 11:19
**/
@Data
public class PlayClerkUserAvatarVo {
/**
* 头像
*/
@NotNull(message = "头像不能为空")
private String avatar;
/**
* 头像框
*/
private String avatarFrameId;
}

View File

@@ -4,13 +4,17 @@ import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
/**
* 微信端申请成为店员
*
* @author admin
*/
@Data
public class PlayClerkUserAddVo {
public class PlayClerkUserByWxAddVo {
/**
@@ -20,57 +24,40 @@ public class PlayClerkUserAddVo {
private String nickname;
/**
* 店员等级
*/
@NotBlank(message = "等级不能为空")
private String levelId;
/**
* 店员性别10
* 店员性别0:未知;1:;2:
*/
@NotNull(message = "性别不能为空")
private Integer sex;
/**
* 头像
*/
@NotBlank(message = "头像不能为空")
private String avatar;
/**
* 音频
*/
@NotBlank(message = "音频不能为空")
private String audioFrequency;
/**
* 星座
*/
@NotBlank(message = "星座不能为空")
private String constellation;
/**
* 标签
*/
private String label;
/**
* 个性签名
*/
@NotBlank(message = "签名不能为空")
private String signature;
private String sex;
/**
* 年龄
*/
@NotNull(message = "年龄不能为空")
private Long age;
@NotNull(message = "性别不能为空")
private Integer age;
/**
* 微信号码
*/
@NotNull(message = "微信号码不能为空")
private String weiChatCode;
/**
* 手机号码区号
*/
@NotBlank(message = "手机号码区号不能为空")
private String areaCode;
/**
* 手机号码
*/
@NotBlank(message = "手机号码不能为空")
private String phone;
/**
* 所在国家
*/
@NotBlank(message = "家不能为空")
private String country;
private String country = "";
/**
* 所在省份
@@ -84,6 +71,17 @@ public class PlayClerkUserAddVo {
@NotBlank(message = "城市不能为空")
private String city;
/**
* 音频
*/
@NotBlank(message = "音频不能为空")
private String audio;
@NotNull(message = "album不能为空")
@Size(min = 1, max = 5, message = "照片必须为1-5张")
private List<String> album;
/**
* 备注
*/

View File

@@ -0,0 +1,123 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 微信端申请成为店员
*
* @author admin
*/
@Data
public class PlayClerkUserByWxEditVo {
/**
* 店员昵称
*/
@NotBlank(message = "昵称不能为空")
private String nickname;
/**
* 店员性别0:未知;1:男;2:女)
*/
@NotNull(message = "性别不能为空")
private Integer sex;
/**
* 年龄
*/
@NotNull(message = "性别不能为空")
private Integer age;
/**
* 微信号码
*/
@NotNull(message = "微信号码不能为空")
private Integer weiChatCode;
/**
* 手机号码区号
*/
@NotBlank(message = "手机号码区号不能为空")
private String areaCode;
/**
* 手机号码
*/
@NotBlank(message = "手机号码不能为空")
private String phone;
/**
* 所在国家
*/
private String country = "中国";
/**
* 所在省份
*/
@NotBlank(message = "省份不能为空")
private String province;
/**
* 所在城市
*/
@NotBlank(message = "城市不能为空")
private String city;
/**
* 音频
*/
@NotBlank(message = "音频不能为空")
private String audioFrequency;
/**
* 图片1
**/
private String image1;
/**
* 图片2
**/
private String image2;
/**
* 图片3
**/
private String image3;
/**
* 图片4
**/
private String image4;
/**
* 图片4
**/
private String image5;
/**
* 微信二维码
**/
private String weChatCodeImage;
/**
* 支付宝收款码图片
**/
private String weChatPayImage;
/**
* 支付宝收款码图片
**/
private String alipayImage;
/**
* 备注
*/
private String remark;
}

View File

@@ -0,0 +1,134 @@
package com.starry.admin.modules.weichat.entity;
import com.starry.admin.modules.clear.module.vo.PlayClerkCommodityQueryVo;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 微信端店员登录返回值
*
* @author admin
*/
@Data
public class PlayClerkUserLoginResponseVo {
/**
* UUID
*/
private String id;
/**
* 店员昵称
*/
private String nickname;
/**
* 头像
*/
private String avatar;
/**
* 头像是否可编辑
*/
private boolean avatarAllowEdit = true;
/**
* 相册
*/
private List<String> album = new ArrayList<>();
/**
* 相册是否运行编辑
*/
private boolean albumAllowEdit = true;
/**
* 音频
*/
private String audio;
/**
* 音频是否可修改
*/
private boolean audioAllowEdit = true;
/**
* 店员性别0:未知;1:男;2:女)
*/
private String sex;
/**
* 年龄
*/
private Integer age;
/**
* 个性签名
*/
private String signature;
/**
* 星座
*/
private String constellation;
/**
* 地区
*/
private String area;
/**
* 标签
*/
private List<String> labels = new ArrayList<>();
/**
* 分类
*/
private String typeId;
/**
* 微信二维码
**/
private String weChatCodeImage;
/**
* 微信收款码图片
**/
private String weChatPayImage;
/**
* 支付宝收款码图片
**/
private String alipayImage;
/**
* 是否必须实名【1必须实名0非必须实名】
*/
private String mandatoryRealState;
/**
* 在线状态【1在线0离线】
*/
private String onlineState;
/**
* 员工状态【1是陪玩0不是陪玩】
*/
private String clerkState;
/**
* 允许申请陪玩
*/
private boolean clerkAllowEdit = true;
/**
* 服务项目
*/
private List<PlayClerkCommodityQueryVo> commodity = new ArrayList<>();
}

View File

@@ -0,0 +1,24 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* 店员在线状态【1在线0离线】
*
* @author admin
* @since 2024/4/11 11:19
**/
@Data
public class PlayClerkUserOnlineStateVo {
/**
* 在线状态
*/
@NotNull(message = "在线状态不能为空")
@Pattern(regexp = "[01]", message = "在线状态必须为0或1")
private String onlineState;
}

View File

@@ -0,0 +1,79 @@
package com.starry.admin.modules.weichat.entity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 店员录音文件
*
* @author admin
* @since 2024/4/11 11:19
**/
@Data
public class PlayClerkUserOtherVo {
/**
* 店员性别0:未知;1:男;2:女)
*/
private Integer sex;
/**
* 年龄
*/
private Integer age;
/**
* 个性签名
*/
private String signature;
/**
* 星座
*/
private String constellation;
/**
* 所在国家
*/
private String country = "中国";
/**
* 所在省份
*/
private String province;
/**
* 所在城市
*/
private String city;
/**
* 标签
*/
private List<String> labels = new ArrayList<>();
/**
* 分类
*/
private String typeId;
/**
* 微信二维码
**/
private String weChatCodeImage;
/**
* 微信收款码图片
**/
private String weChatPayImage;
/**
* 支付宝收款码图片
**/
private String alipayImage;
}

View File

@@ -0,0 +1,37 @@
package com.starry.admin.modules.weichat.entity;
import com.starry.common.domain.BasePageEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 微信端分页查询店员文件
*
* @author admin
* @since 2024/4/11 11:19
**/
@EqualsAndHashCode(callSuper = true)
@Data
public class PlayClerkUserQueryVo extends BasePageEntity {
/**
* 分类
*/
private String typeId;
/**
* 等级
**/
private String levelId;
/**
* 性别[0:未知;1:男;2:女]
**/
private Integer sex;
/**
* 省
**/
private String province;
}

View File

@@ -0,0 +1,38 @@
package com.starry.admin.modules.weichat.service;
import com.starry.admin.modules.weichat.controller.WxCustomService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 微信公众号开发
*
* @author admin
*/
@Slf4j
@Service
public class WxAccessTokenService {
@Resource
private WxCustomService wxCustomService;
/**
* 获取微信AccessToken
*
* @return access_token
*/
public String getAccessToken() throws WxErrorException {
String token = wxCustomService.proxyWxMpService().getAccessToken();
log.error("token = " + token);
//缓存业务处理
return token;
}
}

View File

@@ -8,12 +8,12 @@ import com.starry.admin.modules.clear.module.entity.PlayClerkUserInfoEntity;
import com.starry.admin.modules.clear.service.IPlayClerkUserInfoService;
import com.starry.admin.modules.custom.module.entity.PlayCustomUserInfoEntity;
import com.starry.admin.modules.custom.service.IPlayCustomUserInfoService;
import com.starry.admin.modules.weichat.controller.WxCustomService;
import com.starry.common.utils.ConvertUtil;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -24,7 +24,7 @@ public class WxOauthService {
@Resource
private WxMpService wxMpService;
private WxCustomService wxCustomService;
@Resource
@@ -33,14 +33,22 @@ public class WxOauthService {
@Resource
private IPlayClerkUserInfoService clerkUserInfoService;
@Resource
private WxTokenService tokenService;
/**
* 微信用户登录
* 如果用户不存在,初始化用户并登录
*
* @param code 微信授权code
* @return String 用户ID
* @author admin
* @since 2024/4/15 11:01
**/
public String clarkUserLogin(String code) {
WxOAuth2AccessToken token = getWxOAuth2AccessToken(code);
log.info("token = " + token);
String openId = getOpenId(token);
WxOAuth2UserInfo userInfo = new WxOAuth2UserInfo();
log.info("openId = " + openId);
WxOAuth2UserInfo userInfo = getWxOAuth2UserInfo(token);
PlayClerkUserInfoEntity item = clerkUserInfoService.selectByOpenid(openId);
if (item == null) {
PlayClerkUserInfoEntity entity = ConvertUtil.entityToVo(userInfo, PlayClerkUserInfoEntity.class);
@@ -49,8 +57,6 @@ public class WxOauthService {
clerkUserInfoService.create(entity);
return entity.getId();
} else {
item.setAvatar(userInfo.getHeadImgUrl());
clerkUserInfoService.update(item);
return item.getId();
}
}
@@ -95,7 +101,7 @@ public class WxOauthService {
}
synchronized (code.intern()) {
try {
return wxMpService.getOAuth2Service().getAccessToken(code);
return wxCustomService.proxyWxMpService().getOAuth2Service().getAccessToken(code);
} catch (WxErrorException e) {
throw new RuntimeException(e);
}
@@ -134,7 +140,7 @@ public class WxOauthService {
throw new ServiceException("获取微信授权异常WxOAuth2AccessToken不能为空");
}
try {
return wxMpService.getOAuth2Service().getUserInfo(token, null);
return wxCustomService.proxyWxMpService().getOAuth2Service().getUserInfo(token, null);
} catch (WxErrorException e) {
throw new RuntimeException(e);
}

View File

@@ -49,14 +49,12 @@ public class WxTokenService {
protected static final long MILLIS_SECOND = 1000;
/**
* 根据微信用户id创建token
*
* @param userId 微信用户ID
* @return String token
* @author 杭州世平信息科技有限公司-xuhq
* @author admin
* @since 2024/4/10 11:21
**/
public String createWxUserToken(String userId) {
@@ -74,13 +72,16 @@ public class WxTokenService {
*
* @param token token
* @return String 微信用户ID
* @author 杭州世平信息科技有限公司-xuhq
* @author admin
* @since 2024/4/10 11:24
**/
public String getWxUserIdByToken(String token) {
if (StringUtils.isEmpty(token)) {
throw new RuntimeException("token不能为空");
}
if (token.startsWith(Constants.TOKEN_PREFIX)) {
token = token.replace(Constants.TOKEN_PREFIX, "");
}
Claims claims = parseToken(token);
return claims.get(Constants.LOGIN_USER_KEY_WX).toString();
}
@@ -91,10 +92,10 @@ public class WxTokenService {
* @param token token
* @param identity 用户身份0:租户1:顾客)
* @return String 微信用户租户ID
* @author 杭州世平信息科技有限公司-xuhq
* @author admin
* @since 2024/4/10 11:24
**/
public String getWxUserTenantIdByToken(String token, String identity) {
public String getWxUserTenantIdByToken(String token) {
if (StringUtils.isEmpty(token)) {
throw new RuntimeException("token不能为空");
}
@@ -205,7 +206,7 @@ public class WxTokenService {
// */
// private String getToken(HttpServletRequest request) {
// String token = request.getHeader(header);
// if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) {
// if (StrUtil.isNotBlank(token) && token.startsWith(Constants.TOKEN_PREFIX)) {
// token = token.replace(Constants.TOKEN_PREFIX, "");
// }
// return token;

View File

@@ -0,0 +1,74 @@
package com.starry.admin.modules.weichat.utils;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson2.JSONObject;
import com.starry.admin.common.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import ws.schild.jave.Encoder;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
@Slf4j
public class WxFileUtils {
/**
* 下载微信临时素材文件
*
* @param access_token 微信token
* @param mediaId 素材ID
* @return InputStream
* @throws IOException IOException
*/
public static InputStream getTemporaryMaterial(String access_token, String mediaId) throws IOException {
String url = "https://api.weixin.qq.com/cgi-bin/media/get?" + access_token + "=ACCESS_TOKEN&media_id=" + mediaId;
// 请求参数
HashMap<String, String> param = new HashMap<>();
param.put("media_id", mediaId);
// 获取到http连接对象
HttpPost httpPost = new HttpPost(url);
StringEntity stringEntity = new StringEntity(JSONObject.toJSONString(param));
httpPost.setEntity(stringEntity);
// 打开链接发送请求 获取到返回的流
CloseableHttpClient build = HttpClients.custom().build();
CloseableHttpResponse execute = build.execute(httpPost);
return execute.getEntity().getContent();
}
public static void audioConvert2Mp3(File source, File target) {
if (FileUtil.isEmpty(source)) {
log.error("从微信下载的临时素材文件为空");
throw new CustomException("音频文件上传失败");
}
FileUtil.touch("/tmp/jave/ffmpeg-amd64-3.5.0/");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(128000);
audio.setChannels(2);
audio.setSamplingRate(44100);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setOutputFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
MultimediaObject multimediaObject = new MultimediaObject(source);
try {
encoder.encode(multimediaObject, target, attrs);
} catch (Exception ex) {
log.error("音频文件格式转化失败", ex);
throw new CustomException("音频文件格式转化失败");
}
}
}