wexin-java升级4.0.0

springboot升级2.4.1
This commit is contained in:
xuwenbo
2020-12-21 13:10:53 +08:00
parent 4222a6e41a
commit a9ae138f04
20 changed files with 48 additions and 193 deletions

10
pom.xml
View File

@ -28,7 +28,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<version>2.4.1</version>
</parent>
<properties>
@ -56,7 +56,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
@ -81,7 +85,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.1</version>
<version>3.3.0</version>
</dependency>
<!--Spring boot end-->

View File

@ -1,22 +0,0 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
*/
package co.yixiang;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class EladminSystemApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -1,25 +0,0 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
*/
package co.yixiang;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class YshopSystemApplicationTests {
@Test
public void contextLoads() {
}
public static void main(String[] args) {
}
}

View File

@ -13,6 +13,7 @@ import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.params.SetParams;
import java.util.Collections;
@ -47,7 +48,8 @@ public class RedisLock {
public boolean tryLock(String lockKey, String clientId, long seconds) {
return redisTemplate.execute((RedisCallback<Boolean>) redisConnection -> {
Jedis jedis = (Jedis) redisConnection.getNativeConnection();
String result = jedis.set(lockKey, clientId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, seconds);
SetParams setParams = new SetParams();
String result = jedis.set(lockKey, clientId, setParams.nx().px(seconds));
if (LOCK_SUCCESS.equals(result)) {
return true;
}

View File

@ -14,7 +14,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.api.YshopException;
import co.yixiang.common.util.IpUtil;
import co.yixiang.constant.ShopConstants;
@ -31,24 +30,19 @@ import co.yixiang.modules.mp.config.WxMpConfiguration;
import co.yixiang.modules.mp.config.WxMaConfiguration;
import co.yixiang.utils.*;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.vdurmont.emoji.EmojiParser;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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 me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -175,8 +169,9 @@ public class AuthService {
public YxUser wechatLogin(String code,String spread){
try {
WxMpService wxService = WxMpConfiguration.getWxMpService();
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.getOAuth2Service().getAccessToken(code);
WxMpUser wxMpUser = wxService.getOAuth2Service().getUserInfo(wxMpOAuth2AccessToken, null);
WxOAuth2AccessToken wxOAuth2AccessToken = wxService.getOAuth2Service().getAccessToken(code);
WxOAuth2UserInfo wxOAuth2UserInfo = wxService.getOAuth2Service().getUserInfo(wxOAuth2AccessToken, null);
WxMpUser wxMpUser = wxService.getUserService().userInfo(wxOAuth2UserInfo.getOpenid());
String openid = wxMpUser.getOpenId();
//如果开启了UnionId

View File

@ -8,7 +8,7 @@
*/
package co.yixiang.modules.wechat.rest.controller;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import co.yixiang.api.ApiResult;
import co.yixiang.modules.mp.service.YxWechatLiveService;
import co.yixiang.modules.mp.service.dto.YxWechatLiveQueryCriteria;

View File

@ -9,7 +9,6 @@
package co.yixiang.modules.wechat.rest.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.hutool.core.util.StrUtil;
import co.yixiang.api.ApiResult;
@ -98,7 +97,7 @@ public class WxMaUserController {
String phone = "";
try {
String sessionKey = RedisUtil.get(ShopConstants.YSHOP_MINI_SESSION_KET+ user.getUid()).toString();
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService()
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService()
.getPhoneNoInfo(sessionKey, param.getEncryptedData(), param.getIv());
phone = phoneNoInfo.getPhoneNumber();
user.setPhone(phone);

View File

@ -2,16 +2,15 @@ server:
port: 8008
servlet:
context-path: /api
encoding:
charset: UTF-8
enabled: true
force: true
tomcat:
uri-encoding: UTF-8
spring:
http:
encoding:
charset: UTF-8
enabled: true
force: true
freemarker:
check-template-location: false
profiles:

View File

@ -1,21 +0,0 @@
package co.yixiang.test;
import cn.binarywang.wx.miniapp.api.WxMaLiveService;
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
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("测试直播间");
}
}

View File

@ -12,7 +12,7 @@
<artifactId>yshop-common</artifactId>
<name>公共模块</name>
<properties>
<weixin-java.version>3.9.0</weixin-java.version>
<weixin-java.version>4.0.0</weixin-java.version>
</properties>
<dependencies>
<dependency>

View File

@ -8,6 +8,7 @@ package co.yixiang.utils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("unchecked")
@ -66,7 +67,7 @@ public class RedisUtil {
if(key.length==1){
redisTemplate.delete(key[0]);
}else{
redisTemplate.delete(CollectionUtils.arrayToList(key));
redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));
}
}
}

View File

@ -1,36 +0,0 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
*/
package co.yixiang.utils;
import org.junit.Assert;
import org.junit.Test;
public class EncryptUtilsTest {
/**
* 对称加密
*/
@Test
public void testDesEncrypt() {
try {
Assert.assertEquals("7772841DC6099402", EncryptUtils.desEncrypt("123456"));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 对称解密
*/
@Test
public void testDesDecrypt() {
try {
Assert.assertEquals("123456", EncryptUtils.desDecrypt("7772841DC6099402"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,41 +0,0 @@
/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
*/
package co.yixiang.utils;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.mock.web.MockMultipartFile;
import static org.junit.Assert.assertEquals;
public class FileUtilTest {
@Test
public void testToFile() {
long retval = FileUtil.toFile(new MockMultipartFile("foo", (byte[]) null)).getTotalSpace();
assertEquals(500695072768L, retval);
}
@Test
public void testGetExtensionName() {
Assert.assertEquals("foo", FileUtil.getExtensionName("foo"));
Assert.assertEquals("exe", FileUtil.getExtensionName("bar.exe"));
}
@Test
public void testGetFileNameNoEx() {
Assert.assertEquals("foo", FileUtil.getFileNameNoEx("foo"));
Assert.assertEquals("bar", FileUtil.getFileNameNoEx("bar.txt"));
}
@Test
public void testGetSize() {
Assert.assertEquals("1000B ", FileUtil.getSize(1000));
Assert.assertEquals("1.00KB ", FileUtil.getSize(1024));
Assert.assertEquals("1.00MB ", FileUtil.getSize(1048576));
Assert.assertEquals("1.00GB ", FileUtil.getSize(1073741824));
}
}

View File

@ -13,11 +13,10 @@ import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
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 me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@ -91,10 +90,10 @@ public class QrCodeController {
throw new IllegalArgumentException("未找到对应配置的服务,请核实!");
}
try {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wxService.getOAuth2Service().getAccessToken(code);
WxMpUser wxMpUser = wxService.getOAuth2Service().getUserInfo(wxMpOAuth2AccessToken, "zh_CN");
RedisUtil.set("qrCode:" + key, wxMpOAuth2AccessToken.getOpenId() + ":" + wxMpUser.getNickname());
log.info("【微信网页授权】wxMpUser={}", wxMpUser);
WxOAuth2AccessToken wxOAuth2AccessToken = wxService.getOAuth2Service().getAccessToken(code);
WxOAuth2UserInfo wxOAuth2UserInfo = wxService.getOAuth2Service().getUserInfo(wxOAuth2AccessToken, "zh_CN");
RedisUtil.set("qrCode:" + key, wxOAuth2UserInfo.getOpenid() + ":" + wxOAuth2UserInfo.getNickname());
log.info("【微信网页授权】wxMpUser={}", wxOAuth2UserInfo);
} catch (WxErrorException e) {
log.info("【微信网页授权】{}", e);
throw new Exception(e.getError().getErrorMsg());
@ -114,4 +113,4 @@ public class QrCodeController {
}
return new ResponseEntity(HttpStatus.OK);
}
}
}

View File

@ -55,7 +55,7 @@ public class SystemGroupDataController {
@PreAuthorize("hasAnyRole('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_SELECT')")
public ResponseEntity getYxSystemGroupDatas(YxSystemGroupDataQueryCriteria criteria,
Pageable pageable){
Sort sort = new Sort(Sort.Direction.DESC, "sort");
Sort sort = Sort.by(Sort.Direction.DESC, "sort");
Pageable pageableT = PageRequest.of(pageable.getPageNumber(),
pageable.getPageSize(),
sort);

View File

@ -48,7 +48,7 @@ public class SystemUserTaskController {
@PreAuthorize("hasAnyRole('admin','YXSYSTEMUSERTASK_ALL','YXSYSTEMUSERTASK_SELECT')")
public ResponseEntity getYxSystemUserTasks(YxSystemUserTaskQueryCriteria criteria,
Pageable pageable){
Sort sort = new Sort(Sort.Direction.ASC, "level_id");
Sort sort = Sort.by(Sort.Direction.ASC, "level_id");
Pageable pageableT = PageRequest.of(pageable.getPageNumber(),
pageable.getPageSize(),
sort);

View File

@ -8,7 +8,7 @@
*/
package co.yixiang.modules.mp.service;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import co.yixiang.common.service.BaseService;
import co.yixiang.modules.mp.service.dto.UpdateGoodsDto;
import co.yixiang.modules.mp.service.dto.WxMaLiveInfo;

View File

@ -1,6 +1,6 @@
package co.yixiang.modules.mp.service.dto;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
@ -23,22 +23,22 @@ public class WxMaLiveResult implements Serializable {
private Integer total;
private Integer auditId;
private Integer goodsId;
private List<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.Goods> goods;
private List<cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult.Goods> goods;
/**
* 直播间列表
*/
@SerializedName("room_info")
private List<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.RoomInfo> roomInfos;
private List<cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult.RoomInfo> roomInfos;
/**
* 获取回放源视频列表
*/
@SerializedName("live_replay")
private List<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.LiveReplay> liveReplay;
private List<cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult.LiveReplay> liveReplay;
public static cn.binarywang.wx.miniapp.bean.WxMaLiveResult fromJson(String json) {
return WxMaGsonBuilder.create().fromJson(json, cn.binarywang.wx.miniapp.bean.WxMaLiveResult.class);
public static cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult fromJson(String json) {
return WxMaGsonBuilder.create().fromJson(json, cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult.class);
}
/**
@ -111,7 +111,7 @@ public class WxMaLiveResult implements Serializable {
private Integer closeGoods;
@SerializedName("close_comment")
private Integer closeComment;
private List<cn.binarywang.wx.miniapp.bean.WxMaLiveResult.Goods> goods;
private List<cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult.Goods> goods;
}
/**

View File

@ -9,8 +9,8 @@
package co.yixiang.modules.mp.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaLiveInfo;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveGoodInfo;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
@ -19,6 +19,7 @@ import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.enums.LiveGoodsEnum;
import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.mp.service.dto.WxMaLiveInfo;
import co.yixiang.modules.mp.service.mapper.YxWechatLiveGoodsMapper;
import co.yixiang.modules.mp.domain.YxWechatLiveGoods;
import co.yixiang.modules.mp.service.YxWechatLiveGoodsService;
@ -102,7 +103,7 @@ public class YxWechatLiveGoodsServiceImpl extends BaseServiceImpl<YxWechatLiveGo
YxWechatLiveGoods wechatLiveGoods = this.getById(resources.getGoodsId());
try {
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
WxMaLiveInfo.Goods goods = generator.convert(resources, WxMaLiveInfo.Goods.class);
WxMaLiveGoodInfo goods = generator.convert(resources, WxMaLiveGoodInfo.class);
if(ObjectUtil.isNotEmpty(wechatLiveGoods)){
/** 审核状态 0未审核1审核中2:审核通过3审核失败 */
if(LiveGoodsEnum.IS_Audit_2.getValue().equals(wechatLiveGoods.getAuditStatus())){
@ -193,7 +194,7 @@ public class YxWechatLiveGoodsServiceImpl extends BaseServiceImpl<YxWechatLiveGo
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
try {
resources.setCoverImgUrl(uploadPhotoToWx(wxMaService,resources.getCoverImgeUrl()).getMediaId());
WxMaLiveInfo.Goods goods = generator.convert(resources, WxMaLiveInfo.Goods.class);
WxMaLiveGoodInfo goods = generator.convert(resources, WxMaLiveGoodInfo.class);
WxMaLiveResult wxMaLiveResult = wxMaService.getLiveGoodsService().addGoods(goods);
resources.setGoodsId(Long.valueOf(wxMaLiveResult.getGoodsId()));
resources.setAuditId(Long.valueOf(wxMaLiveResult.getAuditId()));

View File

@ -9,8 +9,8 @@
package co.yixiang.modules.mp.service.impl;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaLiveResult;
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
import cn.binarywang.wx.miniapp.bean.live.WxMaLiveResult;
import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import co.yixiang.common.service.impl.BaseServiceImpl;