Commit f6eae4e2 by fanjiaxin

新加入实名认证相关代码

parent 39032de4
Pipeline #75478 passed with stages
in 1 minute 8 seconds
...@@ -9,11 +9,11 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLin ...@@ -9,11 +9,11 @@ import com.netease.yanxuan.wx.store.sharer.biz.meta.model.vo.ProductPromotionLin
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.common.constant.CoreConstant;
import com.netease.yanxuan.wx.store.sharer.common.exception.NoBindSharerException; import com.netease.yanxuan.wx.store.sharer.common.exception.NoBindSharerException;
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.common.util.AsyncUtils; import com.netease.yanxuan.wx.store.sharer.common.util.AsyncUtils;
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.constant.WeChatConstant;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.*; import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.*;
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;
...@@ -160,12 +160,12 @@ public class ProductServiceImpl implements IProductService { ...@@ -160,12 +160,12 @@ public class ProductServiceImpl implements IProductService {
*/ */
private WeChatPromoteProductDetailVO getProductDetailCache(String shopAppid, String productId) { private WeChatPromoteProductDetailVO getProductDetailCache(String shopAppid, String productId) {
WeChatPromoteProductDetailVO detailVO; WeChatPromoteProductDetailVO detailVO;
String productDetailKey = CoreConstant.REDIS_PRODUCT_DETAIL_KEY + shopAppid + ":" + productId; String productDetailKey = WeChatConstant.REDIS_PRODUCT_DETAIL_KEY + shopAppid + ":" + productId;
String productDetailJson = redisClient.getStr(productDetailKey); String productDetailJson = redisClient.getStr(productDetailKey);
if (StringUtils.isBlank(productDetailJson)) { if (StringUtils.isBlank(productDetailJson)) {
detailVO = weChatShopPromoteProductDetailRequest.handle(shopAppid, Long.valueOf(productId)); detailVO = weChatShopPromoteProductDetailRequest.handle(shopAppid, Long.valueOf(productId));
if (null != detailVO) { if (null != detailVO) {
redisClient.setStr(productDetailKey, JSON.toJSONString(detailVO), CoreConstant.REDIS_PRODUCT_DETAIL_EXPIRE_SECONDS); redisClient.setStr(productDetailKey, JSON.toJSONString(detailVO), WeChatConstant.REDIS_PRODUCT_DETAIL_EXPIRE_SECONDS);
} }
} else { } else {
detailVO = JSON.parseObject(productDetailJson, WeChatPromoteProductDetailVO.class); detailVO = JSON.parseObject(productDetailJson, WeChatPromoteProductDetailVO.class);
......
...@@ -19,49 +19,4 @@ public interface CoreConstant { ...@@ -19,49 +19,4 @@ public interface CoreConstant {
* Redis认证Token失效时间,秒 * Redis认证Token失效时间,秒
*/ */
int REDIS_TOKEN_EXPIRE_SECONDS = 30 * 24 * 60 * 60; int REDIS_TOKEN_EXPIRE_SECONDS = 30 * 24 * 60 * 60;
/**
* Redis微信认证Token
*/
String REDIS_TOKEN_WECHAT_KEY = "TOKEN:WECHAT";
/**
* Redis微信认证Token锁
*/
String REDIS_TOKEN_WECHAT_LOCK_KEY = "TOKEN:WECHAT:LOCK";
/**
* Redis微信认证Token锁时间,秒
*/
String REDIS_TOKEN_WECHAT_LOCK_VALUE = "wechat:lock";
/**
* Redis微信认证Token锁时间,秒
*/
int REDIS_TOKEN_WECHAT_LOCK_TIME = 5;
/**
* Redis微信小店认证Token
*/
String REDIS_TOKEN_WECHAT_SHOP_KEY = "TOKEN:WECHAT:SHOP";
/**
* Redis微信小店认证Token锁
*/
String REDIS_TOKEN_WECHAT_SHOP_LOCK_KEY = "TOKEN:WECHAT:SHOP:LOCK";
/**
* Redis微信小店认证Token锁时间,秒
*/
String REDIS_TOKEN_WECHAT_SHOP_LOCK_VALUE = "wechat:shop:lock";
/**
* Redis微信小店认证Token锁时间,秒
*/
int REDIS_TOKEN_WECHAT_SHOP_LOCK_TIME = 5;
/**
* Redis商品详情缓存KEY
*/
String REDIS_PRODUCT_DETAIL_KEY = "PRODUCT:DETAIL:";
/**
* Redis商品详情过期时间,秒
*/
int REDIS_PRODUCT_DETAIL_EXPIRE_SECONDS = 6 * 60 * 60;
} }
package com.netease.yanxuan.wx.store.sharer.integration.constant;
/**
* @Description 微信常量信息
* @Author fanjiaxin
* @Date 2025/3/9 13:15
*/
public interface WeChatConstant {
/**
* Redis微信认证Token
*/
String REDIS_TOKEN_WECHAT_KEY = "TOKEN:WECHAT";
/**
* Redis微信认证Token锁
*/
String REDIS_TOKEN_WECHAT_LOCK_KEY = "TOKEN:WECHAT:LOCK";
/**
* Redis微信认证Token锁时间,秒
*/
String REDIS_TOKEN_WECHAT_LOCK_VALUE = "wechat:lock";
/**
* Redis微信认证Token锁时间,秒
*/
int REDIS_TOKEN_WECHAT_LOCK_TIME = 5;
/**
* Redis微信小店认证Token
*/
String REDIS_TOKEN_WECHAT_SHOP_KEY = "TOKEN:WECHAT:SHOP";
/**
* Redis微信小店认证Token锁
*/
String REDIS_TOKEN_WECHAT_SHOP_LOCK_KEY = "TOKEN:WECHAT:SHOP:LOCK";
/**
* Redis微信小店认证Token锁时间,秒
*/
String REDIS_TOKEN_WECHAT_SHOP_LOCK_VALUE = "wechat:shop:lock";
/**
* Redis微信小店认证Token锁时间,秒
*/
int REDIS_TOKEN_WECHAT_SHOP_LOCK_TIME = 5;
/**
* Redis商品详情缓存KEY
*/
String REDIS_PRODUCT_DETAIL_KEY = "PRODUCT:DETAIL:";
/**
* Redis商品详情过期时间,秒
*/
int REDIS_PRODUCT_DETAIL_EXPIRE_SECONDS = 6 * 60 * 60;
}
package com.netease.yanxuan.wx.store.sharer.integration.core; package com.netease.yanxuan.wx.store.sharer.integration.core;
import com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant;
import com.netease.yanxuan.wx.store.sharer.common.exception.WeChatException; import com.netease.yanxuan.wx.store.sharer.common.exception.WeChatException;
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.constant.WeChatConstant;
import com.netease.yanxuan.wx.store.sharer.integration.handler.impl.WeChatShopAccessTokenRequest; 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;
...@@ -33,7 +33,7 @@ public class WeChatContextHolder { ...@@ -33,7 +33,7 @@ public class WeChatContextHolder {
*/ */
public String getShopAccessToken() { public String getShopAccessToken() {
// 检查锁定 // 检查锁定
String accessToken = redisClient.getStr(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_KEY); String accessToken = redisClient.getStr(WeChatConstant.REDIS_TOKEN_WECHAT_SHOP_KEY);
if (StringUtils.isNotBlank(accessToken)) { if (StringUtils.isNotBlank(accessToken)) {
return accessToken; return accessToken;
} }
...@@ -46,15 +46,15 @@ public class WeChatContextHolder { ...@@ -46,15 +46,15 @@ public class WeChatContextHolder {
public String createShopAccessToken() { public String createShopAccessToken() {
try { try {
// 设置10秒的锁 // 设置10秒的锁
boolean locked = redisClient.setIfAbsent(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_KEY, boolean locked = redisClient.setIfAbsent(WeChatConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_KEY,
CoreConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_VALUE, CoreConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_TIME); WeChatConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_VALUE, WeChatConstant.REDIS_TOKEN_WECHAT_SHOP_LOCK_TIME);
if (!locked) { if (!locked) {
// 未获取到锁,等待一段时间后重试 // 未获取到锁,等待一段时间后重试
TimeUnit.MILLISECONDS.sleep(RETRY_DELAY_MS); TimeUnit.MILLISECONDS.sleep(RETRY_DELAY_MS);
return getShopAccessToken(); return getShopAccessToken();
} }
WeChatAccessTokenVO handle = weChatShopAccessTokenRequest.handle(); WeChatAccessTokenVO handle = weChatShopAccessTokenRequest.handle();
redisClient.setStr(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_KEY, handle.getAccess_token(), redisClient.setStr(WeChatConstant.REDIS_TOKEN_WECHAT_SHOP_KEY, handle.getAccess_token(),
handle.getExpires_in() - EXPIRE_SECONDS); handle.getExpires_in() - EXPIRE_SECONDS);
return handle.getAccess_token(); return handle.getAccess_token();
} catch (InterruptedException e) { } catch (InterruptedException e) {
......
package com.netease.yanxuan.wx.store.sharer.integration.handler; package com.netease.yanxuan.wx.store.sharer.integration.handler;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.netease.yanxuan.wx.store.sharer.common.constant.CoreConstant;
import com.netease.yanxuan.wx.store.sharer.common.exception.WeChatException; import com.netease.yanxuan.wx.store.sharer.common.exception.WeChatException;
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.common.handler.RestTemplateClient; import com.netease.yanxuan.wx.store.sharer.common.handler.RestTemplateClient;
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.constant.WeChatConstant;
import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.WeChatErrorCodeEnum; import com.netease.yanxuan.wx.store.sharer.integration.meta.enums.WeChatErrorCodeEnum;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatCoreVO; import com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatCoreVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -39,7 +39,7 @@ public class WeChatRestTemplateHandler { ...@@ -39,7 +39,7 @@ public class WeChatRestTemplateHandler {
&& !WeChatApi.WECHAT_REQUEST_SUCCESS_CODE.equals(result.getErrcode())) { && !WeChatApi.WECHAT_REQUEST_SUCCESS_CODE.equals(result.getErrcode())) {
if(WeChatErrorCodeEnum.INVALID_CREDENTIAL.getCode().equals(result.getErrcode())){ if(WeChatErrorCodeEnum.INVALID_CREDENTIAL.getCode().equals(result.getErrcode())){
// token过期,清除微信小店认证信息 // token过期,清除微信小店认证信息
redisClient.delete(CoreConstant.REDIS_TOKEN_WECHAT_SHOP_KEY); redisClient.delete(WeChatConstant.REDIS_TOKEN_WECHAT_SHOP_KEY);
} }
throw new WeChatException(String.join(",","调用微信接口失败" + result.getErrmsg())); throw new WeChatException(String.join(",","调用微信接口失败" + result.getErrmsg()));
} }
......
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