package com.ruoyi.order.util.kuaishou;
|
|
import com.kuaishou.locallife.open.api.KsLocalLifeApiException;
|
import com.kuaishou.locallife.open.api.client.KsLocalLifeAccessTokenClient;
|
import com.kuaishou.locallife.open.api.common.utils.GsonUtils;
|
import com.kuaishou.locallife.open.api.domain.locallife_trade.VerifyPrepareDataNew;
|
import com.kuaishou.locallife.open.api.domain.locallife_trade.VerifyResult;
|
import com.kuaishou.locallife.open.api.request.locallife_trade.GoodlifeV1FulfilmentCertificatePrepareRequest;
|
import com.kuaishou.locallife.open.api.request.locallife_trade.GoodlifeV1FulfilmentCertificateVerifyRequest;
|
import com.kuaishou.locallife.open.api.response.locallife_trade.GoodlifeV1FulfilmentCertificatePrepareResponse;
|
import com.kuaishou.locallife.open.api.response.locallife_trade.GoodlifeV1FulfilmentCertificateVerifyResponse;
|
import com.ruoyi.common.redis.service.RedisService;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.util.List;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2025/6/16 10:28
|
*/
|
@Slf4j
|
public class VerifyUtil {
|
|
|
/**
|
* 验券准备
|
* @param code 短链地址
|
* @return
|
*/
|
public static VerifyPrepareDataNew certificatePrepare(RedisService redisService, String code){
|
//判断token是否过期
|
Object ks_access_token = redisService.getCacheObject("ks_access_token");
|
if(null == ks_access_token){
|
//刷新token
|
ClientTokenUtil.refreshToken(redisService);
|
ks_access_token = redisService.getCacheObject("ks_access_token");
|
}
|
String access_token = ks_access_token.toString();
|
KsLocalLifeAccessTokenClient client = KsLocalLifeAccessTokenClient.Builder.newBuilder()
|
.setAccessToken(access_token)
|
.build();
|
//截取链接中的检验码
|
code = code.substring(code.lastIndexOf("/") + 1);
|
GoodlifeV1FulfilmentCertificatePrepareRequest request = new GoodlifeV1FulfilmentCertificatePrepareRequest();
|
request.setEncrypted_short_code(code);
|
|
try {
|
GoodlifeV1FulfilmentCertificatePrepareResponse response = client.execute(request);
|
log.info("【快手】验券准备返回结果:{}", GsonUtils.toJSON(response));
|
VerifyPrepareDataNew data = response.getData();
|
if(0 != data.getError_code()){
|
log.error("【快手】验券准备失败");
|
return null;
|
}
|
return data;
|
} catch (KsLocalLifeApiException e) {
|
log.error("【快手】验券准备失败");
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
|
/**
|
* 验券
|
* @param poiId 快手门店id
|
* @param encryptedCodes 加密券码
|
* @param encryptedCodes 验券准备接口返回的加密快手券码
|
* @param order_id 快手订单号
|
* @return
|
*/
|
public static List<VerifyResult> certificateVerify(RedisService redisService, String verify_token, String poiId, List<String> encryptedCodes, String order_id){
|
//判断token是否过期
|
Object ks_access_token = redisService.getCacheObject("ks_access_token");
|
if(null == ks_access_token){
|
//刷新token
|
ClientTokenUtil.refreshToken(redisService);
|
ks_access_token = redisService.getCacheObject("ks_access_token");
|
}
|
String access_token = ks_access_token.toString();
|
KsLocalLifeAccessTokenClient client = KsLocalLifeAccessTokenClient.Builder.newBuilder()
|
.setAccessToken(access_token)
|
.build();
|
|
GoodlifeV1FulfilmentCertificateVerifyRequest request = new GoodlifeV1FulfilmentCertificateVerifyRequest();
|
|
request.setVerify_token(verify_token);
|
request.setPoi_id(poiId);
|
request.setEncrypted_codes(encryptedCodes);
|
request.setOrder_id(order_id);
|
try {
|
GoodlifeV1FulfilmentCertificateVerifyResponse response = client.execute(request);
|
log.info("【快手】验券返回结果:{}", GsonUtils.toJSON(response));
|
if(0 != response.getData().getError_code()){
|
log.error("【快手】验券失败");
|
return null;
|
}
|
/**
|
* result 验券结果码,0表示成功,非0表示失败
|
* msg 验券结果说明
|
* code 代表验券传入的code或encrypted_code
|
* verify_id 代表券码一次核销的标识(撤销时需要)
|
* certificate_id 代表一张券码的标识(撤销时需要)
|
* origin_code 原始券码
|
* account_id 代表商家总店id(查询验券历史时需要)
|
* is_abnormal 验券结果通知 true 异常 false 非异常
|
*/
|
return response.getData().getVerify_results();
|
} catch (KsLocalLifeApiException e) {
|
log.error("【快手】验券失败");
|
e.printStackTrace();
|
}
|
return null;
|
}
|
}
|