Commit 4bb14474 by fanjiaxin

集成微信小店Token认证

parent 3e578ca1
Pipeline #71561 passed with stages
in 1 minute 12 seconds
...@@ -26,9 +26,9 @@ import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo; ...@@ -26,9 +26,9 @@ import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo;
import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerProductCommission; import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerProductCommission;
import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerProductCommissionRecord; import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerProductCommissionRecord;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSetSharerCommissionRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSetSharerCommissionRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSetSharerProductCommissionRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSetSharerProductCommissionRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSharerListRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSharerListRequest;
import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.CommissionTypeEnum; import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.CommissionTypeEnum;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatSharerInfoVO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatSharerInfoVO;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatSharerListVO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatSharerListVO;
...@@ -60,9 +60,9 @@ public class DrmSharerConfig { ...@@ -60,9 +60,9 @@ public class DrmSharerConfig {
private final SharerInfoMapper sharerInfoMapper; private final SharerInfoMapper sharerInfoMapper;
private final SharerProductCommissionMapper sharerProductCommissionMapper; private final SharerProductCommissionMapper sharerProductCommissionMapper;
private final SharerProductCommissionRecordMapper sharerProdutcCommissionRecordMapper; private final SharerProductCommissionRecordMapper sharerProdutcCommissionRecordMapper;
private final WeChatSharerListRequest weChatSharerListRequest; private final WeChatShopSharerListRequest weChatShopSharerListRequest;
private final WeChatSetSharerCommissionRequest weChatSetSharerCommissionRequest; private final WeChatShopSetSharerCommissionRequest weChatShopSetSharerCommissionRequest;
private final WeChatSetSharerProductCommissionRequest weChatSetSharerProductCommissionRequest; private final WeChatShopSetSharerProductCommissionRequest weChatShopSetSharerProductCommissionRequest;
private final Map<String, String> sharerAppidMap = new ConcurrentHashMap<>(0); private final Map<String, String> sharerAppidMap = new ConcurrentHashMap<>(0);
...@@ -122,7 +122,7 @@ public class DrmSharerConfig { ...@@ -122,7 +122,7 @@ public class DrmSharerConfig {
String nextKey = null; String nextKey = null;
int pageSize = 10; int pageSize = 10;
while (true) { while (true) {
WeChatSharerListVO sharerListVO = weChatSharerListRequest.handle(null, nextKey, pageSize); WeChatSharerListVO sharerListVO = weChatShopSharerListRequest.handle(null, nextKey, pageSize);
if (sharerListVO == null) { if (sharerListVO == null) {
break; // 如果返回值为空,直接终止循环 break; // 如果返回值为空,直接终止循环
} }
...@@ -149,7 +149,7 @@ public class DrmSharerConfig { ...@@ -149,7 +149,7 @@ public class DrmSharerConfig {
boolean isSuccess = false; boolean isSuccess = false;
try { try {
// 设置推客分佣比例 // 设置推客分佣比例
weChatSetSharerCommissionRequest.handle(sharerInfoVO.getSharer_appid(), commissionRatio.toPlainString()); weChatShopSetSharerCommissionRequest.handle(sharerInfoVO.getSharer_appid(), commissionRatio.toPlainString());
isSuccess = true; isSuccess = true;
} catch (Exception e) { } catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e); log.error("设置推客的的分佣类型和比例信息失败", e);
...@@ -212,7 +212,7 @@ public class DrmSharerConfig { ...@@ -212,7 +212,7 @@ public class DrmSharerConfig {
boolean isSuccess = false; boolean isSuccess = false;
try { try {
// 设置推客分佣比例 // 设置推客分佣比例
weChatSetSharerCommissionRequest.handle(sharerAppid, commissionRatio.toPlainString()); weChatShopSetSharerCommissionRequest.handle(sharerAppid, commissionRatio.toPlainString());
isSuccess = true; isSuccess = true;
} catch (Exception e) { } catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e); log.error("设置推客的的分佣类型和比例信息失败", e);
...@@ -240,7 +240,7 @@ public class DrmSharerConfig { ...@@ -240,7 +240,7 @@ public class DrmSharerConfig {
boolean isSuccess = false; boolean isSuccess = false;
try { try {
// 设置推客分佣比例 // 设置推客分佣比例
weChatSetSharerCommissionRequest.handle(sharerAppid, commissionRatio.toPlainString()); weChatShopSetSharerCommissionRequest.handle(sharerAppid, commissionRatio.toPlainString());
isSuccess = true; isSuccess = true;
} catch (Exception e) { } catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e); log.error("设置推客的的分佣类型和比例信息失败", e);
...@@ -365,7 +365,7 @@ public class DrmSharerConfig { ...@@ -365,7 +365,7 @@ public class DrmSharerConfig {
boolean isSuccess = false; boolean isSuccess = false;
try { try {
// 设置推客分佣比例 // 设置推客分佣比例
weChatSetSharerProductCommissionRequest.handle(sharerAppid, newBo.getProductId(), commissionRatio.toPlainString()); weChatShopSetSharerProductCommissionRequest.handle(sharerAppid, newBo.getProductId(), commissionRatio.toPlainString());
isSuccess = true; isSuccess = true;
} catch (Exception e) { } catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e); log.error("设置推客的的分佣类型和比例信息失败", e);
...@@ -390,7 +390,7 @@ public class DrmSharerConfig { ...@@ -390,7 +390,7 @@ public class DrmSharerConfig {
boolean isSuccess = false; boolean isSuccess = false;
try { try {
// 设置推客分佣比例 // 设置推客分佣比例
weChatSetSharerProductCommissionRequest.handle(sharerAppid, oldBo.getProductId(), null); weChatShopSetSharerProductCommissionRequest.handle(sharerAppid, oldBo.getProductId(), null);
isSuccess = true; isSuccess = true;
} catch (Exception e) { } catch (Exception e) {
log.error("设置推客的的分佣类型和比例信息失败", e); log.error("设置推客的的分佣类型和比例信息失败", e);
......
...@@ -7,10 +7,10 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO; ...@@ -7,10 +7,10 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductListVO;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageQuery;
import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO; import com.netease.yanxuan.wx.store.sharer.biz.meta.page.PageVO;
import com.netease.yanxuan.wx.store.sharer.biz.service.IProductService; import com.netease.yanxuan.wx.store.sharer.biz.service.IProductService;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatPromoteProductDetailRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductDetailRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatPromoteProductLinkRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductLinkRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatPromoteProductListRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopPromoteProductListRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSharerListRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSharerListRequest;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.*; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -35,16 +35,16 @@ import java.util.stream.Collectors; ...@@ -35,16 +35,16 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
public class ProductServiceImpl implements IProductService { public class ProductServiceImpl implements IProductService {
private final WeChatPromoteProductListRequest weChatPromoteProductListRequest; private final WeChatShopPromoteProductListRequest weChatShopPromoteProductListRequest;
private final WeChatPromoteProductDetailRequest weChatPromoteProductDetailRequest; private final WeChatShopPromoteProductDetailRequest weChatShopPromoteProductDetailRequest;
private final WeChatPromoteProductLinkRequest weChatPromoteProductLinkRequest; private final WeChatShopPromoteProductLinkRequest weChatShopPromoteProductLinkRequest;
private final WeChatSharerListRequest weChatSharerListRequest; private final WeChatShopSharerListRequest weChatShopSharerListRequest;
private final DrmSharerConfig drmSharerConfig; private final DrmSharerConfig drmSharerConfig;
@Override @Override
public PageVO<ProductListVO> getProductPageList(PageQuery pageQuery, String keyword) { public PageVO<ProductListVO> getProductPageList(PageQuery pageQuery, String keyword) {
PageVO<ProductListVO> pageVO = new PageVO<>(); PageVO<ProductListVO> pageVO = new PageVO<>();
WeChatPromoteProductListVO productListVO = weChatPromoteProductListRequest.handle(keyword, WeChatPromoteProductListVO productListVO = weChatShopPromoteProductListRequest.handle(keyword,
pageQuery.getNextKey(), pageQuery.getPageSize()); pageQuery.getNextKey(), pageQuery.getPageSize());
pageVO.setHasMore(!CollectionUtils.isEmpty(productListVO.getProduct_list()) pageVO.setHasMore(!CollectionUtils.isEmpty(productListVO.getProduct_list())
&& productListVO.getProduct_list().size() >= pageQuery.getPageSize()); && productListVO.getProduct_list().size() >= pageQuery.getPageSize());
...@@ -53,7 +53,7 @@ public class ProductServiceImpl implements IProductService { ...@@ -53,7 +53,7 @@ public class ProductServiceImpl implements IProductService {
List<ProductListVO> resultList = Optional.ofNullable(productListVO.getProduct_list()).orElseGet(ArrayList::new) List<ProductListVO> resultList = Optional.ofNullable(productListVO.getProduct_list()).orElseGet(ArrayList::new)
.stream() .stream()
.map(item -> { .map(item -> {
WeChatPromoteProductDetailVO detailVO = weChatPromoteProductDetailRequest.handle(item.getShop_appid(), WeChatPromoteProductDetailVO detailVO = weChatShopPromoteProductDetailRequest.handle(item.getShop_appid(),
item.getProduct_id()); item.getProduct_id());
if(null == detailVO){ if(null == detailVO){
return null; return null;
...@@ -81,7 +81,7 @@ public class ProductServiceImpl implements IProductService { ...@@ -81,7 +81,7 @@ public class ProductServiceImpl implements IProductService {
// 获取用户信息 // 获取用户信息
LoginUserInfo loginUserInfo = LoginUserContextHolder.get(); LoginUserInfo loginUserInfo = LoginUserContextHolder.get();
if(null != loginUserInfo && StringUtils.isNotBlank(loginUserInfo.getOpenId())){ if(null != loginUserInfo && StringUtils.isNotBlank(loginUserInfo.getOpenId())){
WeChatSharerListVO sharerListVO = weChatSharerListRequest.handle(loginUserInfo.getOpenId(), "", 1); WeChatSharerListVO sharerListVO = weChatShopSharerListRequest.handle(loginUserInfo.getOpenId(), "", 1);
if (null != sharerListVO && !CollectionUtils.isEmpty(sharerListVO.getSharer_info_list())) { if (null != sharerListVO && !CollectionUtils.isEmpty(sharerListVO.getSharer_info_list())) {
WeChatSharerInfoVO sharerInfoVO = sharerListVO.getSharer_info_list().get(0); WeChatSharerInfoVO sharerInfoVO = sharerListVO.getSharer_info_list().get(0);
if (null != sharerInfoVO && null != sharerInfoVO.getCommission_ratio()) { if (null != sharerInfoVO && null != sharerInfoVO.getCommission_ratio()) {
...@@ -102,7 +102,7 @@ public class ProductServiceImpl implements IProductService { ...@@ -102,7 +102,7 @@ public class ProductServiceImpl implements IProductService {
listVO.setShopAppid(item.getShop_appid()); listVO.setShopAppid(item.getShop_appid());
listVO.setProductId(item.getProduct_id()); listVO.setProductId(item.getProduct_id());
// 获取推广链接 // 获取推广链接
WeChatPromoteProductLinkVO promoteProductLinkVO = weChatPromoteProductLinkRequest.handle(item.getShop_appid(), item.getProduct_id()); WeChatPromoteProductLinkVO promoteProductLinkVO = weChatShopPromoteProductLinkRequest.handle(item.getShop_appid(), item.getProduct_id());
listVO.setProductUrl(null != promoteProductLinkVO ? promoteProductLinkVO.getShort_link() : null); listVO.setProductUrl(null != promoteProductLinkVO ? promoteProductLinkVO.getShort_link() : null);
return listVO; return listVO;
}) })
......
...@@ -14,8 +14,8 @@ import com.netease.yanxuan.wx.store.sharer.biz.service.IUserService; ...@@ -14,8 +14,8 @@ import com.netease.yanxuan.wx.store.sharer.biz.service.IUserService;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException; import com.netease.yanxuan.wx.store.sharer.common.exception.NoAuthException;
import com.netease.yanxuan.wx.store.sharer.dal.mapper.SharerInfoMapper; import com.netease.yanxuan.wx.store.sharer.dal.mapper.SharerInfoMapper;
import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo; import com.netease.yanxuan.wx.store.sharer.dal.meta.model.po.SharerInfo;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSharerListRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSharerListRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatSharerRegisterBindRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopSharerRegisterBindRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatUserInfoRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatUserInfoRequest;
import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.CommissionTypeEnum; import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.CommissionTypeEnum;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatSharerInfoVO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatSharerInfoVO;
...@@ -45,8 +45,8 @@ public class UserServiceImpl implements IUserService { ...@@ -45,8 +45,8 @@ public class UserServiceImpl implements IUserService {
private final DrmSharerConfig drmSharerConfig; private final DrmSharerConfig drmSharerConfig;
private final LoginUserHelper jwtHelper; private final LoginUserHelper jwtHelper;
private final WeChatUserInfoRequest weChatUserRequest; private final WeChatUserInfoRequest weChatUserRequest;
private final WeChatSharerRegisterBindRequest weChatSharerRegisterBindRequest; private final WeChatShopSharerRegisterBindRequest weChatShopSharerRegisterBindRequest;
private final WeChatSharerListRequest weChatSharerListRequest; private final WeChatShopSharerListRequest weChatShopSharerListRequest;
@Override @Override
...@@ -107,7 +107,7 @@ public class UserServiceImpl implements IUserService { ...@@ -107,7 +107,7 @@ public class UserServiceImpl implements IUserService {
if (StringUtils.isNotBlank(sharerInfo.getSharerAppid())) { if (StringUtils.isNotBlank(sharerInfo.getSharerAppid())) {
result.setSharerAppId(sharerInfo.getSharerAppid()); result.setSharerAppId(sharerInfo.getSharerAppid());
} }
WeChatSharerListVO sharerListVO = weChatSharerListRequest.handle(loginUserInfo.getOpenId(), "", 1); WeChatSharerListVO sharerListVO = weChatShopSharerListRequest.handle(loginUserInfo.getOpenId(), "", 1);
if (null != sharerListVO && !CollectionUtils.isEmpty(sharerListVO.getSharer_info_list())) { if (null != sharerListVO && !CollectionUtils.isEmpty(sharerListVO.getSharer_info_list())) {
WeChatSharerInfoVO sharerInfoVO = sharerListVO.getSharer_info_list().get(0); WeChatSharerInfoVO sharerInfoVO = sharerListVO.getSharer_info_list().get(0);
if (null != sharerInfoVO && StringUtils.isNotBlank(sharerInfoVO.getSharer_appid())) { if (null != sharerInfoVO && StringUtils.isNotBlank(sharerInfoVO.getSharer_appid())) {
...@@ -150,7 +150,7 @@ public class UserServiceImpl implements IUserService { ...@@ -150,7 +150,7 @@ public class UserServiceImpl implements IUserService {
private SharerInfoVO getSharerRegisterBindInfo(String openId) { private SharerInfoVO getSharerRegisterBindInfo(String openId) {
// 获取推客注册与绑定信息 // 获取推客注册与绑定信息
WeChatSharerRegisterBindVO sharerRegisterBindVO = weChatSharerRegisterBindRequest.handle(openId); WeChatSharerRegisterBindVO sharerRegisterBindVO = weChatShopSharerRegisterBindRequest.handle(openId);
SharerInfoVO result = new SharerInfoVO(); SharerInfoVO result = new SharerInfoVO();
result.setOpenId(openId); result.setOpenId(openId);
result.setBindStatus(sharerRegisterBindVO.getBind_status()); result.setBindStatus(sharerRegisterBindVO.getBind_status());
......
...@@ -29,4 +29,13 @@ public interface CoreConstant { ...@@ -29,4 +29,13 @@ public interface CoreConstant {
* Redis微信认证Token锁 * Redis微信认证Token锁
*/ */
String REDIS_TOKEN_WECHAT_LOCK_KEY = "TOKEN:WECHAT:LOCK"; String REDIS_TOKEN_WECHAT_LOCK_KEY = "TOKEN:WECHAT:LOCK";
/**
* Redis微信小店认证Token
*/
String REDIS_TOKEN_WECHAT_SHOP_KEY = "TOKEN:WECHAT:SHOP";
/**
* Redis微信小店认证Token锁
*/
String REDIS_TOKEN_WECHAT_SHOP_LOCK_KEY = "TOKEN:WECHAT:SHOP:LOCK";
} }
...@@ -31,4 +31,16 @@ public class WeChatConfig { ...@@ -31,4 +31,16 @@ public class WeChatConfig {
*/ */
@Value("${wechat.appsecret:0bf536fe0b0a20542dd97a490f8e89b7}") @Value("${wechat.appsecret:0bf536fe0b0a20542dd97a490f8e89b7}")
private String appsecret; private String appsecret;
/**
* 微信开放接口小店appId
*/
@Value("${wechat.shop.appid:wxc956822fcdb4a43c}")
private String shopAppid;
/**
* 微信开放接口小店appSecret
*/
@Value("${wechat.shop.appsecret:67176561fb2bd4ebf0bb535e6ca10051}")
private String shopAppsecret;
} }
\ No newline at end of file
...@@ -13,6 +13,12 @@ public class WeChatApi { ...@@ -13,6 +13,12 @@ public class WeChatApi {
public static final int WECHAT_COMMISSION_RATIO_MULTIPLIER = 1000000; public static final int WECHAT_COMMISSION_RATIO_MULTIPLIER = 1000000;
/** /**
* 微信请求Token字段名
*/
public static final String WECHAT_REQUEST_TOKEN_FIELD_NAME = "access_token";
/**
* 获取用户认证信息 * 获取用户认证信息
*/ */
public static final String GET_TOKEN = "/cgi-bin/token"; public static final String GET_TOKEN = "/cgi-bin/token";
......
...@@ -4,6 +4,7 @@ import com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant; ...@@ -4,6 +4,7 @@ import com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant;
import com.netease.yanxuan.wx.store.sharer.common.exception.BizException; import com.netease.yanxuan.wx.store.sharer.common.exception.BizException;
import com.netease.yanxuan.wx.store.sharer.common.handler.RedisClient; import com.netease.yanxuan.wx.store.sharer.common.handler.RedisClient;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatAccessTokenRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatAccessTokenRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopAccessTokenRequest;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatAccessTokenVO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatAccessTokenVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -21,8 +22,9 @@ import java.util.concurrent.TimeUnit; ...@@ -21,8 +22,9 @@ import java.util.concurrent.TimeUnit;
public class WeChatContextHolder { public class WeChatContextHolder {
private final RedisClient redisClient; private final RedisClient redisClient;
private final WeChatAccessTokenRequest weChatAccessTokenRequest; private final WeChatAccessTokenRequest weChatAccessTokenRequest;
private final WeChatShopAccessTokenRequest weChatShopAccessTokenRequest;
private static final long RETRY_DELAY_MS = 200; // 每次重试之间的延迟时间(毫秒) private static final long RETRY_DELAY_MS = 200;
private static final int EXPIRE_SECONDS = 5 * 60; private static final int EXPIRE_SECONDS = 5 * 60;
/** /**
...@@ -62,4 +64,42 @@ public class WeChatContextHolder { ...@@ -62,4 +64,42 @@ public class WeChatContextHolder {
handle.getExpires_in() - EXPIRE_SECONDS); handle.getExpires_in() - EXPIRE_SECONDS);
return handle.getAccess_token(); return handle.getAccess_token();
} }
/**
* 获取微信小店认证信息
*/
public String getShopAccessToken() {
// 双重检查锁定
String accessToken = redisClient.getStr(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_KEY);
if (StringUtils.isNotBlank(accessToken)) {
return accessToken;
}
try {
return createAccessToken();
} catch (InterruptedException e) {
throw new BizException("微信认证获取AccessToken异常", e);
}
}
/**
* 创建微信小店认证信息
*/
public String createShopAccessToken() throws InterruptedException {
// 设置10秒的锁
boolean locked = redisClient.setIfAbsent(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_KEY, "locked", 10);
if (!locked) {
// 未获取到锁,等待一段时间后重试
TimeUnit.MILLISECONDS.sleep(RETRY_DELAY_MS);
return createAccessToken();
}
// 双重检查锁定
String accessToken = redisClient.getStr(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_KEY);
if (StringUtils.isNotBlank(accessToken)) {
return accessToken;
}
WeChatAccessTokenVO handle = weChatShopAccessTokenRequest.handle();
redisClient.setStr(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_KEY, handle.getAccess_token(),
handle.getExpires_in() - EXPIRE_SECONDS);
return handle.getAccess_token();
}
} }
package com.netease.yanxuan.wx.store.sharer.integration.handler; package com.netease.yanxuan.wx.store.sharer.integration.handler;
import com.netease.yanxuan.wx.store.sharer.common.util.SpringContextUtils;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
/** /**
...@@ -19,9 +17,4 @@ public interface IWeChatRequest { ...@@ -19,9 +17,4 @@ public interface IWeChatRequest {
* 请求地址 * 请求地址
*/ */
String getRequestUrl(); String getRequestUrl();
default String getAccessToken() {
WeChatContextHolder weChatContextHolder = SpringContextUtils.getBean(WeChatContextHolder.class);
return weChatContextHolder.getAccessToken();
}
} }
package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatAccessTokenBO;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatAccessTokenVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
/**
* @Description 微信小店凭证请求
* @Author fanjiaxin
* @Date 2025/3/11 17:33
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class WeChatShopAccessTokenRequest implements IWeChatRequest {
private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig;
private static final String GRANT_TYPE = "client_credential";
@Override
public HttpMethod getRequestMethod() {
return HttpMethod.GET;
}
@Override
public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_TOKEN;
}
/**
* 处理
*/
public WeChatAccessTokenVO handle() {
WeChatAccessTokenBO params = WeChatAccessTokenBO.builder()
.grant_type(GRANT_TYPE)
.appid(weChatConfig.getShopAppid())
.secret(weChatConfig.getShopAppsecret())
.build();
return weChatRestTemplateHandler.execute(getRequestUrl(), getRequestMethod(), params, WeChatAccessTokenVO.class);
}
}
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatGetSharerProductCommissionBO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatGetSharerProductCommissionBO;
...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service; ...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatGetSharerProductCommissionRequest implements IWeChatRequest { public class WeChatShopGetSharerProductCommissionRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -31,7 +33,9 @@ public class WeChatGetSharerProductCommissionRequest implements IWeChatRequest { ...@@ -31,7 +33,9 @@ public class WeChatGetSharerProductCommissionRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_SHARER_PRODUCT_COMMISSION_INFO + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.GET_SHARER_PRODUCT_COMMISSION_INFO
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME +"="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.ProductPlanTypeEnum; import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.ProductPlanTypeEnum;
...@@ -20,7 +21,8 @@ import org.springframework.stereotype.Service; ...@@ -20,7 +21,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatPromoteProductDetailRequest implements IWeChatRequest { public class WeChatShopPromoteProductDetailRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -32,7 +34,9 @@ public class WeChatPromoteProductDetailRequest implements IWeChatRequest { ...@@ -32,7 +34,9 @@ public class WeChatPromoteProductDetailRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_PROMOTE_PRODUCT_DETAIL + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.GET_PROMOTE_PRODUCT_DETAIL
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatPromoteProductLinkBO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatPromoteProductLinkBO;
...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service; ...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatPromoteProductLinkRequest implements IWeChatRequest { public class WeChatShopPromoteProductLinkRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -31,7 +33,9 @@ public class WeChatPromoteProductLinkRequest implements IWeChatRequest { ...@@ -31,7 +33,9 @@ public class WeChatPromoteProductLinkRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_PRODUCT_PROMOTION_LINK_INFO + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.GET_PRODUCT_PROMOTION_LINK_INFO
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.ProductPlanTypeEnum; import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.ProductPlanTypeEnum;
...@@ -20,7 +21,8 @@ import org.springframework.stereotype.Service; ...@@ -20,7 +21,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatPromoteProductListRequest implements IWeChatRequest { public class WeChatShopPromoteProductListRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -32,7 +34,9 @@ public class WeChatPromoteProductListRequest implements IWeChatRequest { ...@@ -32,7 +34,9 @@ public class WeChatPromoteProductListRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_PROMOTE_PRODUCT_LIST + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.GET_PROMOTE_PRODUCT_LIST
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.CommissionTypeEnum; import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.CommissionTypeEnum;
...@@ -20,7 +21,8 @@ import org.springframework.stereotype.Service; ...@@ -20,7 +21,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatSetSharerCommissionRequest implements IWeChatRequest { public class WeChatShopSetSharerCommissionRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -32,7 +34,9 @@ public class WeChatSetSharerCommissionRequest implements IWeChatRequest { ...@@ -32,7 +34,9 @@ public class WeChatSetSharerCommissionRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.SET_SHARER_COMMISSION_INFO + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.SET_SHARER_COMMISSION_INFO
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatSetSharerProductCommissionBO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatSetSharerProductCommissionBO;
...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service; ...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatSetSharerProductCommissionRequest implements IWeChatRequest { public class WeChatShopSetSharerProductCommissionRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -31,7 +33,9 @@ public class WeChatSetSharerProductCommissionRequest implements IWeChatRequest { ...@@ -31,7 +33,9 @@ public class WeChatSetSharerProductCommissionRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.SET_SHARER_PRODUCT_COMMISSION_INFO + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.SET_SHARER_PRODUCT_COMMISSION_INFO
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatSharerListBO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatSharerListBO;
...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service; ...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatSharerListRequest implements IWeChatRequest { public class WeChatShopSharerListRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -31,7 +33,9 @@ public class WeChatSharerListRequest implements IWeChatRequest { ...@@ -31,7 +33,9 @@ public class WeChatSharerListRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_BIND_SHARER_LIST + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.GET_BIND_SHARER_LIST
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl; ...@@ -2,6 +2,7 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler.impl;
import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig; import com.netease.yanxuan.wx.store.sharer.integration.config.WeChatConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi; import com.netease.yanxuan.wx.store.sharer.integration.constant.WeChatApi;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest; import com.netease.yanxuan.wx.store.sharer.integration.handler.IWeChatRequest;
import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler; import com.netease.yanxuan.wx.store.sharer.integration.handler.WeChatRestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatSharerRegisterBindBO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.WeChatSharerRegisterBindBO;
...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service; ...@@ -19,7 +20,8 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class WeChatSharerRegisterBindRequest implements IWeChatRequest { public class WeChatShopSharerRegisterBindRequest implements IWeChatRequest {
private final WeChatContextHolder weChatContextHolder;
private final WeChatRestTemplateHandler weChatRestTemplateHandler; private final WeChatRestTemplateHandler weChatRestTemplateHandler;
private final WeChatConfig weChatConfig; private final WeChatConfig weChatConfig;
...@@ -31,7 +33,9 @@ public class WeChatSharerRegisterBindRequest implements IWeChatRequest { ...@@ -31,7 +33,9 @@ public class WeChatSharerRegisterBindRequest implements IWeChatRequest {
@Override @Override
public String getRequestUrl() { public String getRequestUrl() {
return weChatConfig.getUrl() + WeChatApi.GET_PROMOTER_REGISTER_AND_BIND_STATUS + "?access_token=" + getAccessToken(); return weChatConfig.getUrl() + WeChatApi.GET_PROMOTER_REGISTER_AND_BIND_STATUS
+ "?" + WeChatApi.WECHAT_REQUEST_TOKEN_FIELD_NAME + "="
+ weChatContextHolder.getShopAccessToken();
} }
/** /**
......
package com.netease.yanxuan.wx.store.sharer.integration.task; package com.netease.yanxuan.wx.store.sharer.integration.task;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder; import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatAccessTokenRequest;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* @Description 华能e购认证信息初始化 * @Description 微信小店认证信息初始化
* @Date 2025/2/24 11:57 * @Date 2025/3/11 11:57
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@Component @Component
public class WeChatAuthTask implements CommandLineRunner { public class WeChatAuthTask implements CommandLineRunner {
private final WeChatAccessTokenRequest weChatAccessTokenRequest;
private final WeChatContextHolder weChatContextHolder; private final WeChatContextHolder weChatContextHolder;
...@@ -23,7 +21,7 @@ public class WeChatAuthTask implements CommandLineRunner { ...@@ -23,7 +21,7 @@ public class WeChatAuthTask implements CommandLineRunner {
public void run(String... args) { public void run(String... args) {
log.info("微信认证信息初始化开始..."); log.info("微信认证信息初始化开始...");
try { try {
weChatContextHolder.getAccessToken(); weChatContextHolder.createAccessToken();
log.info("微信认证信息初始化完成"); log.info("微信认证信息初始化完成");
} catch (Exception e) { } catch (Exception e) {
log.error("微信认证信息初始化失败", e); log.error("微信认证信息初始化失败", e);
......
package com.netease.yanxuan.wx.store.sharer.integration.task;
import com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/**
* @Description 微信小店认证信息初始化
* @Date 2025/3/13 11:57
*/
@Slf4j
@RequiredArgsConstructor
@Component
public class WeChatShopAuthTask implements CommandLineRunner {
private final WeChatContextHolder weChatContextHolder;
@Override
public void run(String... args) {
log.info("微信小店认证信息初始化开始...");
try {
weChatContextHolder.createShopAccessToken();
log.info("微信小店认证信息初始化完成");
} catch (Exception e) {
log.error("微信小店认证信息初始化失败", e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment