数云接口对接,会员操作,积分变更操作

master
382696293@qq.com 2 years ago
parent 678bbc11fe
commit 635f8fb43a

@ -30,7 +30,7 @@ public class AccessToken {
/** /**
* 0: 1:accessToken * 0: 1:accessToken
*/ */
private String isOverDue; private Integer isOverDue;
public String getAccessToken() { public String getAccessToken() {
return accessToken; return accessToken;
@ -64,11 +64,11 @@ public class AccessToken {
this.authValue = authValue; this.authValue = authValue;
} }
public String getIsOverDue() { public Integer getIsOverDue() {
return isOverDue; return isOverDue;
} }
public void setIsOverDue(String isOverDue) { public void setIsOverDue(Integer isOverDue) {
this.isOverDue = isOverDue; this.isOverDue = isOverDue;
} }

@ -0,0 +1,174 @@
package com.flossom.common.core.domain.shuyun;
/**
*
*/
public class ShuYunMember {
/**
* ()
*/
private String id;
/**
* ()
*/
private String platCode;
/**
* 使IDID()
*/
private String shopId;
/**
* ()
*/
private String name;
/**
* ()
*/
private String mobile;
/**
* yyyy-MM-dd
*/
private String birthday;
/**
* F(); M()
*/
private String gender;
/**
* yyyy-MM-dd HH:mm:ss
*/
private String created;
/**
* ID
*/
private String guideId;
public ShuYunMember() {
}
/**
*
* @param id
* @param platCode
* @param shopId
* @param name
* @param mobile
*/
public ShuYunMember(String id, String platCode, String shopId, String name, String mobile) {
this.id = id;
this.platCode = platCode;
this.shopId = shopId;
this.name = name;
this.mobile = mobile;
}
/**
*
* @param id
* @param platCode
* @param shopId
*/
public ShuYunMember(String id, String platCode, String shopId) {
this.id = id;
this.platCode = platCode;
this.shopId = shopId;
}
public ShuYunMember(String id, String platCode, String shopId, String mobile) {
this.id = id;
this.platCode = platCode;
this.shopId = shopId;
this.mobile = mobile;
}
public ShuYunMember(String id, String platCode, String shopId, String name, String mobile, String birthday, String gender, String created, String guideId) {
this.id = id;
this.platCode = platCode;
this.shopId = shopId;
this.name = name;
this.mobile = mobile;
this.birthday = birthday;
this.gender = gender;
this.created = created;
this.guideId = guideId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPlatCode() {
return platCode;
}
public void setPlatCode(String platCode) {
this.platCode = platCode;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getGuideId() {
return guideId;
}
public void setGuideId(String guideId) {
this.guideId = guideId;
}
}

@ -0,0 +1,183 @@
package com.flossom.common.core.domain.shuyun;
public class ShuYunPointChange {
/**
*
*/
private String id;
/**
*
*/
private String platCode;
/**
* 使IDID
*/
private String shopId;
/**
*
*/
private String sequence;
/**
*
* TRADE:
* REFUND:退
* SERVICE:
* CONSUME:
* EXPIRE:
* IMPORT:
* MALL:
* BRAND:
* OTHER
*/
private String source;
/**
*
*/
private Integer changePoint;
/**
* yyyy-MM-dd HH:mm:ss
*/
private String created;
/**
* yyyy-MM-dd HH:mm:ss
*/
private String expired;
/**
*
*/
private String operator;
/**
*
*/
private String desc;
public ShuYunPointChange() {
}
/**
*
*
* @param id
* @param platCode
* @param shopId
* @param sequence
* @param source
* @param changePoint
* @param created
* @param desc
*/
public ShuYunPointChange(String id, String platCode, String shopId, String sequence, String source, Integer changePoint, String created, String desc) {
this.id = id;
this.platCode = platCode;
this.shopId = shopId;
this.sequence = sequence;
this.source = source;
this.changePoint = changePoint;
this.created = created;
this.desc = desc;
}
public ShuYunPointChange(String id, String platCode, String shopId, String sequence, String source, Integer changePoint, String created, String expired, String operator, String desc) {
this.id = id;
this.platCode = platCode;
this.shopId = shopId;
this.sequence = sequence;
this.source = source;
this.changePoint = changePoint;
this.created = created;
this.expired = expired;
this.operator = operator;
this.desc = desc;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPlatCode() {
return platCode;
}
public void setPlatCode(String platCode) {
this.platCode = platCode;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getSequence() {
return sequence;
}
public void setSequence(String sequence) {
this.sequence = sequence;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public Integer getChangePoint() {
return changePoint;
}
public void setChangePoint(Integer changePoint) {
this.changePoint = changePoint;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getExpired() {
return expired;
}
public void setExpired(String expired) {
this.expired = expired;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

@ -46,7 +46,7 @@ public class ShuYunCallbackController {
*/ */
if (accessTokenList != null && accessTokenList.size() > 0) { if (accessTokenList != null && accessTokenList.size() > 0) {
for (AccessToken accessToken : accessTokenList) { for (AccessToken accessToken : accessTokenList) {
if (StringUtils.equals(accessToken.getAppId(), shuYunConfig.getAppid())) { if (accessToken.getIsOverDue() == 0 && StringUtils.equals(accessToken.getAuthValue(), shuYunConfig.getAuthValue())) {
logger.info("缓存数云accessToken{}", accessToken); logger.info("缓存数云accessToken{}", accessToken);
if (StringUtils.isNotBlank(accessToken.getAccessToken())) { if (StringUtils.isNotBlank(accessToken.getAccessToken())) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();

@ -1,9 +1,45 @@
package com.flossom.system.utils.shuyun; package com.flossom.system.utils.shuyun;
/**
*
*/
public class ActionMethod { public class ActionMethod {
/**
* token
*/
private String accessToken; private String accessToken;
/**
*
*/
private String queryMember;
/**
*
*/
private String registerMember;
/**
*
*/
private String modifyMember;
/**
*
*/
private String modifyMemberMobile;
/**
*
*/
private String unbindMember;
/**
*
*/
private String pointChange;
public String getAccessToken() { public String getAccessToken() {
return accessToken; return accessToken;
} }
@ -11,4 +47,52 @@ public class ActionMethod {
public void setAccessToken(String accessToken) { public void setAccessToken(String accessToken) {
this.accessToken = accessToken; this.accessToken = accessToken;
} }
public String getQueryMember() {
return queryMember;
}
public void setQueryMember(String queryMember) {
this.queryMember = queryMember;
}
public String getRegisterMember() {
return registerMember;
}
public void setRegisterMember(String registerMember) {
this.registerMember = registerMember;
}
public String getModifyMember() {
return modifyMember;
}
public void setModifyMember(String modifyMember) {
this.modifyMember = modifyMember;
}
public String getModifyMemberMobile() {
return modifyMemberMobile;
}
public void setModifyMemberMobile(String modifyMemberMobile) {
this.modifyMemberMobile = modifyMemberMobile;
}
public String getUnbindMember() {
return unbindMember;
}
public void setUnbindMember(String unbindMember) {
this.unbindMember = unbindMember;
}
public String getPointChange() {
return pointChange;
}
public void setPointChange(String pointChange) {
this.pointChange = pointChange;
}
} }

@ -1,8 +1,16 @@
package com.flossom.system.utils.shuyun; package com.flossom.system.utils.shuyun;
import com.alibaba.fastjson.JSON;
import com.flossom.common.core.constant.CacheConstants; import com.flossom.common.core.constant.CacheConstants;
import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.shuyun.AccessToken;
import com.flossom.common.core.domain.shuyun.ShuYunMember;
import com.flossom.common.core.domain.shuyun.ShuYunPointChange;
import com.flossom.common.core.exception.ServiceException;
import com.flossom.common.redis.service.RedisService; import com.flossom.common.redis.service.RedisService;
import com.flossom.system.utils.HttpClientUtils; import com.flossom.system.utils.HttpClientUtils;
import com.shuyun.open.sdk.bean.HttpMethod;
import com.shuyun.open.sdk.core.GateWayClient;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -11,6 +19,7 @@ import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Map;
/** /**
@ -21,6 +30,9 @@ public class ShuYunApiUtils {
protected final static Logger logger = LoggerFactory.getLogger(ShuYunApiUtils.class); protected final static Logger logger = LoggerFactory.getLogger(ShuYunApiUtils.class);
/**
*
*/
private static ShuYunConfig shuYunConfig; private static ShuYunConfig shuYunConfig;
private static RedisService redisService; private static RedisService redisService;
@ -36,20 +48,147 @@ public class ShuYunApiUtils {
} }
/** /**
* accessTokenaccessToken * accessToken accessToken
*
* @return
* @throws Exception
*/ */
public static String getAccessToken() throws Exception { public static String getAccessToken() {
Integer expiryTime = redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_VALUE); Long expiryTime = redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_EXPIRY);
if (expiryTime == null || LocalDateTime.now().atZone(ZoneId.systemDefault()).toEpochSecond() > expiryTime) { if (expiryTime == null || expiryTime == 0 || LocalDateTime.now().atZone(ZoneId.systemDefault()).toEpochSecond() > expiryTime) {
String accessTokenUrl = StringUtils.replace(shuYunConfig.getActionMethod().getAccessToken(), "{appid}", shuYunConfig.getAppid()); String accessTokenUrl = StringUtils.replace(shuYunConfig.getActionMethod().getAccessToken(), "{appid}", shuYunConfig.getAppid());
logger.info("刷新accessToken地址{}", accessTokenUrl); logger.info("刷新accessToken地址{}", accessTokenUrl);
String result = HttpClientUtils.get(accessTokenUrl); try {
logger.info("请求刷新accessToken结果{}", result); String result = HttpClientUtils.get(accessTokenUrl);
logger.info("请求数云接口获取accessToken结果{}", result);
R r = JSON.parseObject(result, R.class);
if (r.getCode() != R.SUCCESS) {
logger.error("请求数云接口获取accessToken失败将直接使用旧的accessToken失败原因{}", result);
}
} catch (Exception e) {
logger.error("请求数云接口获取accessToken失败将直接使用旧的accessToken失败原因{}", e);
}
}
String accessTokenStr = redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_VALUE);
if (StringUtils.isNotBlank(accessTokenStr)) {
AccessToken accessToken = JSON.parseObject(accessTokenStr, AccessToken.class);
return accessToken.getAccessToken();
}
/**
* redis
*/
logger.error("从redis获取数云accessToken失败缓存中没有accessToken有可能是第一次调用");
throw new ServiceException("从redis获取数云accessToken失败缓存中没有accessToken有可能是第一次调用");
}
/**
*
*
* @param httpMethod
* @param requestParams geturl
* @param requestBody postput
* @param actionMethod
*/
public static R shuYunHttpRequest(HttpMethod httpMethod, Map requestParams, String requestBody, String actionMethod) throws ServiceException {
logger.info("数云接口请求地址:{}参数requestParams = {}、requestBody = {}", actionMethod, requestParams, requestBody);
String result = GateWayClient.askGateWay(
httpMethod,
shuYunConfig.getUrl(),
requestParams,
requestBody,
shuYunConfig.getAppid(),
shuYunConfig.getSecurity(),
getAccessToken(),
actionMethod);
logger.info("返回响应:{}", result);
R r = JSON.parseObject(result, R.class);
if (r.getCode() == 10000 || r.getCode() == 14000) {
return r;
} else {
logger.error("调用数云接口发生未知错误:{}", result);
throw new ServiceException("调用数云接口发生未知错误");
}
}
/**
*
*/
public static void registerMember(ShuYunMember member) {
try {
shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(member),
shuYunConfig.getActionMethod().getRegisterMember());
} catch (Exception e) {
logger.error("请求数云接口注册会员失败:{}", e);
throw new ServiceException("请求数云接口注册会员失败");
}
}
/**
*
*/
public static ShuYunMember queryMember(ShuYunMember member) {
try {
R r = shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(member),
shuYunConfig.getActionMethod().getQueryMember());
if (r.getCode() == 10000) {
return JSON.parseObject(r.getData().toString(), ShuYunMember.class);
}
return null;
} catch (Exception e) {
logger.error("请求数云接口-查询会员信息失败:{}", e);
throw new ServiceException("请求数云接口-查询会员信息失败");
}
}
/**
*
*
*/
public static void modifyMember(ShuYunMember member) {
try {
shuYunHttpRequest(HttpMethod.PUT, null, JSON.toJSONString(member),
shuYunConfig.getActionMethod().getModifyMember());
} catch (Exception e) {
logger.error("请求数云接口-修改会员信息(除手机号)失败:{}", e);
throw new ServiceException("请求数云接口-修改会员信息(除手机号)失败");
}
}
/**
*
*/
public static void modifyMemberMobile(ShuYunMember member) {
try {
shuYunHttpRequest(HttpMethod.PUT, null, JSON.toJSONString(member),
shuYunConfig.getActionMethod().getModifyMemberMobile());
} catch (Exception e) {
logger.error("请求数云接口-修改会员手机号失败:{}", e);
throw new ServiceException("请求数云接口-修改会员手机号失败");
}
}
/**
*
*/
public static void unbindMember(ShuYunMember member) {
try {
shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(member),
shuYunConfig.getActionMethod().getUnbindMember());
} catch (Exception e) {
logger.error("请求数云接口-解绑会员失败:{}", e);
throw new ServiceException("请求数云接口-解绑会员失败");
}
}
/**
*
*/
public static void pointChange(ShuYunPointChange shuYunPointChange) {
try {
shuYunHttpRequest(HttpMethod.POST, null, JSON.toJSONString(shuYunPointChange),
shuYunConfig.getActionMethod().getPointChange());
} catch (Exception e) {
logger.error("请求数云接口-会员积分变更失败:{}", e);
throw new ServiceException("请求数云接口-会员积分变更失败");
} }
return redisService.getCacheMapValue(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_VALUE);
} }
} }

@ -29,6 +29,15 @@ public class ShuYunConfig {
*/ */
private String security; private String security;
/**
*
*/
private String authValue;
private String platCode;
private String shopId;
private ActionMethod actionMethod; private ActionMethod actionMethod;
@ -63,4 +72,28 @@ public class ShuYunConfig {
public void setActionMethod(ActionMethod actionMethod) { public void setActionMethod(ActionMethod actionMethod) {
this.actionMethod = actionMethod; this.actionMethod = actionMethod;
} }
public String getPlatCode() {
return platCode;
}
public void setPlatCode(String platCode) {
this.platCode = platCode;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getAuthValue() {
return authValue;
}
public void setAuthValue(String authValue) {
this.authValue = authValue;
}
} }

Loading…
Cancel
Save