提交 3652f3f4 作者: 沈振路

阳光小程序链接获取

上级 ac4c9879
......@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.handler;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yaoyaozw.customer.entity.AuthorizerExpandInfo;
import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.ReferralEntity;
......@@ -84,5 +85,18 @@ public abstract class MpReferralHandler {
protected Boolean isHttpPath(String path) {
return StringUtils.isNotBlank(path) && (path.startsWith("http"));
}
protected AuthorizerExpandInfo getAuthorizerExpandInfo(String appId) {
// 根据appid查询authorizer_expand_info表(1条)
LambdaQueryWrapper<AuthorizerExpandInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AuthorizerExpandInfo::getAuthorizerAppid, appId);
queryWrapper.last("LIMIT 1");
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.getOne(queryWrapper);
if (authorizerExpandInfo == null) {
throw new IllegalArgumentException("未找到对应的公众号扩展信息,appid: " + appId);
}
return authorizerExpandInfo;
}
}
......@@ -35,13 +35,7 @@ public class TomatoMpReferralHandler extends MpReferralHandler {
public ReferralEntity queryMpReferral(ReferralEntity referralEntity, AuthorizerInfo authorizerInfo) {
// 根据appid查询authorizer_expand_info表(1条)
String appid = authorizerInfo.getAppid();
LambdaQueryWrapper<AuthorizerExpandInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AuthorizerExpandInfo::getAuthorizerAppid, appid);
queryWrapper.last("LIMIT 1");
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.getOne(queryWrapper);
if (authorizerExpandInfo == null) {
throw new IllegalArgumentException("未找到对应的公众号扩展信息,appid: " + appid);
}
AuthorizerExpandInfo authorizerExpandInfo = getAuthorizerExpandInfo(appid);
referralEntity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 处理参数:设置accountId为mpDistributorId
......
package com.yaoyaozw.customer.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yaoyaozw.customer.common.R;
import com.yaoyaozw.customer.constants.ApiResultConstant;
import com.yaoyaozw.customer.entity.AuthorizerExpandInfo;
import com.yaoyaozw.customer.entity.AuthorizerInfo;
import com.yaoyaozw.customer.entity.ReferralEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
/**
......@@ -16,13 +22,35 @@ public class YgMpReferralHandler extends MpReferralHandler {
@Override
public ReferralEntity queryMpReferral(ReferralEntity referralEntity, AuthorizerInfo authorizerInfo) {
// TODO: 实现阳光书城的具体查询逻辑
referralEntity.setMiniProgramQuery(Boolean.TRUE);
// 调用接口获取原生链接
R r = referralFeignClient.productReferral(referralEntity);
if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) {
throw new RuntimeException("获取链接失败: " + r.getMessage());
}
String res = r.getData("storeReferral", new TypeReference<String>() {});
JSONObject jsonObject = JSON.parseObject(res);
// 处理链接
constructMpReferral(referralEntity, authorizerInfo, null, jsonObject);
return referralEntity;
}
@Override
public void constructMpReferral(ReferralEntity referralEntity, AuthorizerInfo authorizerInfo, AuthorizerExpandInfo authorizerExpandInfo, JSONObject responseJson) {
return;
// 原始字段
referralEntity.setPromoteId(responseJson.getString("promoteId"));
String referral = responseJson.getString("referral");
referralEntity.setReferral(referral);
// 小程序字段
String mpPath = responseJson.getString("mpPath");
referralEntity.setMpPath(StringUtils.isNotBlank(mpPath) ? mpPath : (isMiniProgramPath(referral) ? referral : null));
referralEntity.setMpAppId(responseJson.getString("mpAppId"));
referralEntity.setExtraHttpUrl(responseJson.getString("extraHttpUrl"));
if (StringUtils.isBlank(referralEntity.getMpAppId())) {
authorizerExpandInfo = getAuthorizerExpandInfo(authorizerInfo.getAppid());
referralEntity.setMpAppId(authorizerExpandInfo.getMpAppid());
}
}
}
......@@ -70,6 +70,11 @@ public class YwMpReferralHandler extends MpReferralHandler {
referralEntity.setMpPath(StringUtils.isNotBlank(mpPath) ? mpPath : (isMiniProgramPath(referral) ? referral : null));
referralEntity.setMpAppId(responseJson.getString("mpAppId"));
referralEntity.setExtraHttpUrl(responseJson.getString("extraHttpUrl"));
if (StringUtils.isBlank(referralEntity.getMpAppId())) {
authorizerExpandInfo = getAuthorizerExpandInfo(authorizerInfo.getAppid());
referralEntity.setMpAppId(authorizerExpandInfo.getMpAppid());
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论