提交 3b5d3d83 作者: 沈振路

关键词、关回 使用封装接口调用创建小程序链接【未测试】

上级 2c0a7f4a
......@@ -12,7 +12,9 @@ import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.CustomerMaterialConstant;
import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.exception.BaseException;
import com.yaoyaozw.customer.factory.MpReferralFactory;
import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.handler.MpReferralHandler;
import com.yaoyaozw.customer.service.AuthorizerExpandInfoService;
import com.yaoyaozw.customer.service.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CompanyAcquisitionLinkService;
......@@ -56,9 +58,9 @@ public class CustomerKeywordComponent {
@Resource
private CompanyAcquisitionLinkService companyAcquisitionLinkService;
@Resource
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Resource
private AuthorizerInfoService authorizerInfoService;
@Resource
private MpReferralFactory mpReferralFactory;
/**
* 获取链接实体
......@@ -90,6 +92,37 @@ public class CustomerKeywordComponent {
return referralEntity;
}
public ReferralEntity getCreateReferralEntityMp(CommonReferralBody referralBody) {
ReferralEntity referralEntity = new ReferralEntity();
// 赋值链接参数
BeanUtil.copyProperties(referralBody, referralEntity);
Integer newsType = referralEntity.getNewsType();
// 判断是否需要获取书城链接
if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(referralBody.getNewsType())) {
// 处理链接名称
if (CustomerCommonConstant.BOOK_NEWS_TYPE.equals(newsType) || CustomerCommonConstant.ACTIVITY_NEWS_TYPE.equals(newsType)) {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = format.format(new Date());
handleReferralName(dateStr, referralBody.getAccountName(), referralEntity);
}
if (StringUtils.isBlank(referralBody.getStoreType()) && referralBody.getInfoId() != null) {
AuthorizerInfo authorizerInfo = authorizerInfoService.getById(referralBody.getInfoId());
if (authorizerInfo != null) {
referralBody.setStoreType(authorizerInfo.getStoreType());
}
}
MpReferralHandler handler = mpReferralFactory.getHandler(referralBody.getStoreType());
if (handler == null) {
throw new BaseException("不支持小程序的书城:" + referralBody.getStoreType());
}
referralEntity = handler.queryMpReferral(referralEntity);
}
return referralEntity;
}
/**
* 获取复用时的链接数据
*
......@@ -251,34 +284,13 @@ public class CustomerKeywordComponent {
if (StringUtils.isBlank(neoEntity.getMpTitle())) {
throw new BaseException("无法匹配小程序发文的标题内容");
}
// 番茄
// 重新处理 小程序appId、小程序path
String storeType;
if (StringUtils.isNotBlank(targetAuth.getStoreType())) {
storeType = targetAuth.getStoreType();
} else {
AuthorizerInfo authorizerInfo = authorizerInfoService.lambdaQuery().eq(AuthorizerInfo::getAppid, targetAuth.getAppId()).last("limit 1").one();
if (authorizerInfo == null) {
throw new BaseException("无法获取公众号信息");
}
storeType = authorizerInfo.getStoreType();
}
if (!CustomerCommonConstant.STORE_NAME_TOMATO.equals(storeType)) {
return;
}
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.lambdaQuery().eq(AuthorizerExpandInfo::getAuthorizerAppid, neoEntity.getAppid()).last("limit 1").one();
if (authorizerExpandInfo == null) {
throw new BaseException("无法获取公众号" + neoEntity.getAppid() + "的绑定配置信息");
}
// 填入小程序appId
neoEntity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 重新获取链接
ReferralEntity targetReferral = new ReferralEntity();
try {
BeanUtil.copyProperties(sourceReferral, targetReferral, "id", "accountId", "name", "referral", "materialGraphicsId", "infoId");
// 为参数设置公众号相关参数
targetReferral.setAccountId(authorizerExpandInfo.getMpDistributorId());
targetReferral.setInfoId(targetAuth.getId());
targetReferral.setStoreType(targetAuth.getStoreType());
Integer newsType = targetReferral.getNewsType();
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(newsType)) {
// 常用链接延用name
......@@ -287,30 +299,18 @@ public class CustomerKeywordComponent {
// 书籍、活动 类型, 重新构造name
handleReferralName(dateStr, targetAuth.getAccountName(), targetReferral);
}
doGetReferral(targetReferral);
MpReferralHandler handler = mpReferralFactory.getHandler(targetReferral.getStoreType());
if (handler == null) {
throw new BaseException("不支持小程序的书城:" + targetReferral.getStoreType());
}
targetReferral = handler.queryMpReferral(targetReferral);
} catch (Exception e) {
throw new RuntimeException("获取链接异常: " + e.getMessage());
}
targetReferral.setMaterialGraphicsId(neoEntity.getId());
String referral = targetReferral.getReferral();
// 番茄处理小程序常用链接
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authorizerExpandInfo.getFlagId();
}
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(targetReferral.getNewsType())) {
if (referral.contains("scene=0")) {
referral = referral.replace("scene=0", "scene=1");
}
} else {
if (!referral.contains(LANDING_PAGE)) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
}
targetReferral.setReferral(referral);
neoEntity.setMpPath(referral);
neoEntity.setMpAppId(targetReferral.getMpAppId());
neoEntity.setContent("");
// 保存链接数据
if (ObjectUtil.isNull(targetReferral.getId())) {
......
......@@ -15,7 +15,9 @@ import com.yaoyaozw.customer.dto.follow.FollowReplySaveDTO;
import com.yaoyaozw.customer.dto.follow.NewsMessageReplyEntity;
import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.exception.BaseException;
import com.yaoyaozw.customer.factory.MpReferralFactory;
import com.yaoyaozw.customer.feigns.ReferralFeignClient;
import com.yaoyaozw.customer.handler.MpReferralHandler;
import com.yaoyaozw.customer.service.AuthorizerExpandInfoService;
import com.yaoyaozw.customer.service.AuthorizerInfoService;
import com.yaoyaozw.customer.service.CompanyAcquisitionLinkService;
......@@ -65,6 +67,8 @@ public class FollowReplyComponent {
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Resource
private AuthorizerInfoService authorizerInfoService;
@Resource
private MpReferralFactory mpReferralFactory;
/**
* 获取链接实体
......@@ -96,6 +100,35 @@ public class FollowReplyComponent {
return referralEntity;
}
public ReferralEntity getCreateReferralEntityMp(CommonReferralBody referralBody) {
ReferralEntity referralEntity = new ReferralEntity();
// 赋值链接参数
BeanUtil.copyProperties(referralBody, referralEntity);
Integer newsType = referralEntity.getNewsType();
// 判断是否需要获取书城链接
if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(referralBody.getNewsType())) {
// 处理链接名称
if (CustomerCommonConstant.BOOK_NEWS_TYPE.equals(newsType) || CustomerCommonConstant.ACTIVITY_NEWS_TYPE.equals(newsType)) {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
String dateStr = format.format(new Date());
handleReferralName(dateStr, referralBody.getAccountName(), referralEntity);
}
if (StringUtils.isBlank(referralBody.getStoreType()) && referralBody.getInfoId() != null) {
AuthorizerInfo authorizerInfo = authorizerInfoService.getById(referralBody.getInfoId());
if (authorizerInfo != null) {
referralBody.setStoreType(authorizerInfo.getStoreType());
}
}
MpReferralHandler handler = mpReferralFactory.getHandler(referralBody.getStoreType());
if (handler == null) {
throw new BaseException("不支持小程序的书城:" + referralBody.getStoreType());
}
referralEntity = handler.queryMpReferral(referralEntity);
}
return referralEntity;
}
/**
* 获取复用时的链接数据
*
......@@ -284,34 +317,13 @@ public class FollowReplyComponent {
if (StringUtils.isBlank(neoEntity.getMpTitle())) {
throw new BaseException("无法匹配小程序发文的标题内容");
}
// 番茄
// 重新处理 小程序appId、小程序path
String storeType;
if (StringUtils.isNotBlank(targetAuth.getStoreType())) {
storeType = targetAuth.getStoreType();
} else {
AuthorizerInfo authorizerInfo = authorizerInfoService.lambdaQuery().eq(AuthorizerInfo::getAppid, targetAuth.getAppId()).last("limit 1").one();
if (authorizerInfo == null) {
throw new BaseException("无法获取公众号信息");
}
storeType = authorizerInfo.getStoreType();
}
if (!CustomerCommonConstant.STORE_NAME_TOMATO.equals(storeType)) {
return;
}
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.lambdaQuery().eq(AuthorizerExpandInfo::getAuthorizerAppid, neoEntity.getAppid()).last("limit 1").one();
if (authorizerExpandInfo == null) {
throw new BaseException("无法获取公众号" + neoEntity.getAppid() + "的绑定配置信息");
}
// 填入小程序appId
neoEntity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 重新获取链接
ReferralEntity targetReferral = new ReferralEntity();
try {
BeanUtil.copyProperties(sourceReferral, targetReferral, "id", "accountId", "name", "referral", "materialGraphicsId", "infoId");
// 为参数设置公众号相关参数
targetReferral.setAccountId(authorizerExpandInfo.getMpDistributorId());
targetReferral.setInfoId(targetAuth.getId());
targetReferral.setStoreType(targetAuth.getStoreType());
Integer newsType = targetReferral.getNewsType();
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(newsType)) {
// 常用链接延用name
......@@ -320,30 +332,17 @@ public class FollowReplyComponent {
// 书籍、活动 类型, 重新构造name
handleReferralName(dateStr, targetAuth.getAccountName(), targetReferral);
}
doGetReferral(targetReferral);
MpReferralHandler handler = mpReferralFactory.getHandler(targetReferral.getStoreType());
if (handler == null) {
throw new BaseException("不支持小程序的书城:" + targetReferral.getStoreType());
}
targetReferral = handler.queryMpReferral(targetReferral);
} catch (Exception e) {
throw new RuntimeException("获取链接异常: " + e.getMessage());
}
targetReferral.setMaterialGraphicsId(neoEntity.getId());
String referral = targetReferral.getReferral();
// 番茄处理小程序常用链接
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authorizerExpandInfo.getFlagId();
}
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(targetReferral.getNewsType())) {
if (referral.contains("scene=0")) {
referral = referral.replace("scene=0", "scene=1");
}
} else {
if (!referral.contains(LANDING_PAGE)) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
}
targetReferral.setReferral(referral);
neoEntity.setMpPath(referral);
neoEntity.setMpPath(targetReferral.getReferral());
neoEntity.setMpAppId(targetReferral.getMpAppId());
neoEntity.setContent("");
// 保存链接数据
if (ObjectUtil.isNull(targetReferral.getId())) {
......
......@@ -251,6 +251,8 @@ public class ReferralEntity implements Serializable {
*/
@TableField(exist = false)
private Boolean miniProgramQuery;
@TableField(exist = false)
private String extraHttpUrl;
public static final String COL_ID = "id";
......
......@@ -65,8 +65,6 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private CustomerFollowReplyMultiNewsService followReplyMultiNewsService;
@Resource
private AuthorizerExpandInfoService authorizerExpandInfoService;
@Override
......@@ -171,8 +169,11 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
if (StringUtils.isBlank(entity.getMpTitle())) {
throw new BaseException("无法匹配小程序发文的标题内容");
}
// 番茄
// 重新处理 小程序appId、小程序path
// 重新获取链接
ReferralEntity referralEntity;
try {
if (StringUtils.isBlank(originReferralBody.getStoreType())) {
// 查询
String storeType;
if (saveDto.getAccountEntity() != null && StringUtils.isNotBlank(saveDto.getAccountEntity().getStoreType())) {
storeType = saveDto.getAccountEntity().getStoreType();
......@@ -183,42 +184,16 @@ public class CustomerFollowReplyServiceImpl extends ServiceImpl<CustomerFollowRe
}
storeType = authorizerInfo.getStoreType();
}
if (!CustomerCommonConstant.STORE_NAME_TOMATO.equals(storeType)) {
return;
originReferralBody.setStoreType(storeType);
}
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.lambdaQuery().eq(AuthorizerExpandInfo::getAuthorizerAppid, entity.getAppid()).last("limit 1").one();
if (authorizerExpandInfo == null) {
throw new BaseException("无法获取公众号" + entity.getAppid() + "的绑定配置信息");
}
// 填入小程序appId
entity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 重新获取链接
ReferralEntity referralEntity;
try {
originReferralBody.setAccountId(authorizerExpandInfo.getMpDistributorId());
referralEntity = followReplyComponent.getCreateReferralEntity(originReferralBody);
referralEntity = followReplyComponent.getCreateReferralEntityMp(originReferralBody);
} catch (Exception e) {
throw new RuntimeException("获取链接异常: " + e.getMessage());
}
referralEntity.setMaterialGraphicsId(entity.getId());
String referral = referralEntity.getReferral();
// 番茄处理小程序常用链接
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authorizerExpandInfo.getFlagId();
}
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
if (referral.contains("scene=0")) {
referral = referral.replace("scene=0", "scene=1");
}
} else {
if (!referral.contains(LANDING_PAGE)) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
}
entity.setMpPath(referral);
entity.setMpAppId(referralEntity.getMpAppId());
entity.setContent("");
referralEntity.setReferral(referral);
// 保存链接数据
......
......@@ -180,49 +180,25 @@ public class CustomerKeywordServiceImpl extends ServiceImpl<CustomerKeywordMappe
if (StringUtils.isBlank(entity.getMpTitle())) {
throw new BaseException("无法匹配小程序发文的标题内容");
}
// 番茄
// 重新处理 小程序appId、小程序path
// 重新获取链接
ReferralEntity referralEntity;
try {
if (StringUtils.isBlank(originReferralBody.getStoreType())) {
// 查询
AuthorizerInfo authorizerInfo = authorizerInfoService.lambdaQuery().eq(AuthorizerInfo::getAppid, entity.getAppid()).last("limit 1").one();
if (authorizerInfo == null) {
throw new BaseException("无法获取公众号信息");
}
String storeType = authorizerInfo.getStoreType();
if (!CustomerCommonConstant.STORE_NAME_TOMATO.equals(storeType)) {
return;
originReferralBody.setStoreType(authorizerInfo.getStoreType());
}
AuthorizerExpandInfo authorizerExpandInfo = authorizerExpandInfoService.lambdaQuery().eq(AuthorizerExpandInfo::getAuthorizerAppid, entity.getAppid()).last("limit 1").one();
if (authorizerExpandInfo == null) {
throw new BaseException("无法获取公众号" + entity.getAppid() + "的绑定配置信息");
}
// 填入小程序appId
entity.setMpAppId(authorizerExpandInfo.getMpAppid());
// 重新获取链接
ReferralEntity referralEntity;
try {
originReferralBody.setAccountId(authorizerExpandInfo.getMpDistributorId());
referralEntity = customerKeywordComponent.getCreateReferralEntity(originReferralBody);
referralEntity = customerKeywordComponent.getCreateReferralEntityMp(originReferralBody);
} catch (Exception e) {
throw new RuntimeException("获取链接异常: " + e.getMessage());
}
referralEntity.setMaterialGraphicsId(entity.getId());
String referral = referralEntity.getReferral();
// 番茄处理小程序常用链接
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authorizerExpandInfo.getFlagId();
}
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
if (referral.contains("scene=0")) {
referral = referral.replace("scene=0", "scene=1");
}
} else {
if (!referral.contains(LANDING_PAGE)) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
}
entity.setMpPath(referral);
entity.setMpAppId(referralEntity.getMpAppId());
entity.setContent("");
referralEntity.setReferral(referral);
// 保存链接数据
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论