wexin-java升级4.0.0

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

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("测试直播间");
}
}