提交 9c8bff4d 作者: 沈振路

客服消息适配文本的小程序文字链【未测试】

上级 1a062c39
......@@ -14,7 +14,10 @@ import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.RabbitCommonNameConstant;
import com.yaoyaozw.customer.entity.*;
import com.yaoyaozw.customer.enums.CustomerStoreTemplateEnum;
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.mapper.CustomerGraphicsDelayMapper;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
......@@ -28,6 +31,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
......@@ -81,6 +85,8 @@ public class CustomerServiceCommonAsyncComponent {
private CompanyAcquisitionLinkService companyAcquisitionLinkService;
@Autowired
private TencentCustomerUtil tencentCustomerUtil;
@Resource
private MpReferralFactory mpReferralFactory;
@Async("myExecutor")
......@@ -701,48 +707,38 @@ public class CustomerServiceCommonAsyncComponent {
}
referralEntity.setInfoId(authInfoVo.getId());
// 判断如果是番茄小程序的话,处理参数
if (CustomerCommonConstant.STORE_NAME_TOMATO.equals(authInfoVo.getStoreType()) && CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType())) {
// 番茄小程序
if (ACTIVITY_NEWS_TYPE.equals(referralEntity.getNewsType())) {
// 活动使用公众号本身的分销商Id
referralEntity.setAccountId(authInfoVo.getAccountId());
} else {
referralEntity.setAccountId(authInfoVo.getExpandDistributorId());
if (BOOK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
referralEntity.setMediaSource("2");
}
boolean isMpQuery = CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType()) || StringUtils.isNotBlank(referralEntity.getMpAppId());
referralEntity.setMiniProgramQuery(isMpQuery);
if (isMpQuery) {
MpReferralHandler handler = mpReferralFactory.getHandler(authInfoVo.getStoreType());
if (handler == null) {
throw new BaseException("不支持小程序发文的书城:" + (StringUtils.isNotBlank(authInfoVo.getStoreTypeName()) ? authInfoVo.getStoreTypeName() : authInfoVo.getStoreType()));
}
referralEntity.setMiniProgramQuery(Boolean.TRUE);
}
if (STORE_NAME_YUE_WEN_1.equals(authInfoVo.getStoreType()) && CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType())) {
referralEntity.setMiniProgramQuery(Boolean.TRUE);
}
// LOCAL_LOG.info("获取链接, 参数: {}", referralEntity);
R r = referralFeignClient.productReferral(referralEntity);
if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) {
if (OVER_FREQUENCY_MSG.equals(r.getMessage())) {
referralEntity.setReferral(OVER_FREQUENCY_STR);
} else {
referralEntity.setReferral(null);
ReferralEntity referralResult = handler.queryMpReferral(referralEntity);
if (referralResult != null) {
// 全量赋值
BeanUtils.copyProperties(referralResult, referralEntity);
}
LOCAL_LOG.info("公众号:{} 获取链接失败:{}, 参数: {}", authInfoVo.getAccountName(), r.getMessage(), referralEntity);
throw new RuntimeException(r.getMessage());
} else {
LOCAL_LOG.info("公众号: {} 获取链接成功", authInfoVo.getAccountName());
}
String res = r.getData("storeReferral", new TypeReference<String>() {});
JSONObject jsonObject1 = JSON.parseObject(res);
String referral = jsonObject1.getString("referral");
referralEntity.setPromoteId(jsonObject1.getString("promoteId"));
referralEntity.setReferral(referral);
if (CustomerCommonConstant.STORE_NAME_TOMATO.equals(authInfoVo.getStoreType()) && CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType())) {
// 取链接成功之后,后置处理番茄小程序
suffixHandleTomatoMiniProgram(authInfoVo, referralEntity);
}
if (STORE_NAME_YUE_WEN_1.equals(authInfoVo.getStoreType()) && CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType())) {
// 取链接成功之后,后置处理阅文1小程序
suffixHandleYwMiniProgram(authInfoVo, referralEntity, jsonObject1);
// LOCAL_LOG.info("获取链接, 参数: {}", referralEntity);
R r = referralFeignClient.productReferral(referralEntity);
if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) {
if (OVER_FREQUENCY_MSG.equals(r.getMessage())) {
referralEntity.setReferral(OVER_FREQUENCY_STR);
} else {
referralEntity.setReferral(null);
}
LOCAL_LOG.info("公众号:{} 获取链接失败:{}, 参数: {}", authInfoVo.getAccountName(), r.getMessage(), referralEntity);
throw new RuntimeException(r.getMessage());
} else {
LOCAL_LOG.info("公众号: {} 获取链接成功", authInfoVo.getAccountName());
}
String res = r.getData("storeReferral", new TypeReference<String>() {});
JSONObject jsonObject1 = JSON.parseObject(res);
String referral = jsonObject1.getString("referral");
referralEntity.setPromoteId(jsonObject1.getString("promoteId"));
referralEntity.setReferral(referral);
}
}
......
......@@ -59,9 +59,12 @@ public class CustomerCommonConstant {
public final static String ACTIVITY_NEWS_TYPE_NAME_CONFIG_NAME_MODEL = "系统-客服-{newsType}-{accountNickName}-{storeType}-{currentDate}-{configName}";
public final static String CUSTOMER_TEXT_LINK_TEMPLATE = "<a href=\"{url}-\" style='color: blue'>{content}</a>";
public final static String CUSTOMER_TEXT_MINI_PROGRAM_TEMPLATE = "<a href=\"#\" data-miniprogram-appid=\"{mpAppId}\" data-miniprogram-path=\"{mpPath}\">点击跳小程序</a>";
public final static String CUSTOMER_TEXT_URL_PLACEHOLDER = "{url}-";
public final static String CUSTOMER_TEXT_CONTENT_PLACEHOLDER = "{content}";
public final static String CUSTOMER_TEXT_MP_APPID_PLACEHOLDER = "{mpAppId}";
public final static String CUSTOMER_TEXT_MP_PATH_PLACEHOLDER = "{mpPath}";
public final static String H5_STYLE_CODE = " style='color: blue'";
public final static Integer USUAL_LINK_NEWS_TYPE = 3;
......
......@@ -103,6 +103,15 @@ public class CommonReferralBody implements Serializable {
private String h5Content;
private String mpTitle;
private String mpAppId;
private String mpPath;
private String mediaId;
public Date getStartTime() {
if (CollectionUtil.isNotEmpty(this.dateList)) {
return dateList.get(0);
......
......@@ -29,6 +29,8 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.ArrayList;
import java.util.List;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST;
/**
* @author darker
* @date 2022/10/12 11:49
......@@ -74,6 +76,11 @@ public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphic
@Override
@Transactional(rollbackFor = Exception.class)
public GenericsResult<CustomerMessageTextDetailVO> insertCustomerContent(CommonReferralBody referralDto) {
// 预处理小程序信息
if (StringUtils.isNotBlank(referralDto.getMpAppId()) && !REMOTE_LINK_NEWS_TYPE_LIST.contains(referralDto.getNewsType())) {
// 判断是不是确实符合小程序类型:(newsType 只有书籍、活动、常用链接 支持小程序)
return new GenericsResult<>(false, "当前链接类型不支持发送小程序");
}
// 处理活动数据
ReferralEntity referralEntity = new ReferralEntity();
......@@ -119,10 +126,14 @@ public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphic
// 设置主键id和h5代码段
customerContentVO.setId(item.getId());
String context = null;
if (CustomerCommonConstant.REPLACE_LINK_NEWS_TYPE_LIST.contains(item.getNewsType()) || CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(item.getNewsType())) {
if (StringUtils.isNotBlank(item.getMpAppId())) {
// 小程序链接:这里的mpAppId会在保存的时候通过占位符填入,待生成的时候,匹配具体appId
context = CustomerCommonConstant.CUSTOMER_TEXT_MINI_PROGRAM_TEMPLATE
.replace(CustomerCommonConstant.CUSTOMER_TEXT_CONTENT_PLACEHOLDER, item.getTextContent());
} else if (CustomerCommonConstant.REPLACE_LINK_NEWS_TYPE_LIST.contains(item.getNewsType()) || CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(item.getNewsType())) {
// 非小程序链接
context = CustomerCommonConstant.CUSTOMER_TEXT_LINK_TEMPLATE
.replace(CustomerCommonConstant.CUSTOMER_TEXT_CONTENT_PLACEHOLDER, item.getTextContent())
.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER, CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER + idx);
.replace(CustomerCommonConstant.CUSTOMER_TEXT_CONTENT_PLACEHOLDER, item.getTextContent());
} else if (CustomerCommonConstant.COMMON_NEWS_TYPE_LIST.contains(item.getNewsType())){
// 纯文本或者获客链接
context = item.getTextContent();
......@@ -144,7 +155,7 @@ public class CustomerGraphicsTextServiceImpl extends ServiceImpl<CustomerGraphic
contentList.add(customerContentVO);
// 统计referralSize
if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(item.getNewsType()) || CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(item.getNewsType())) {
if (REMOTE_LINK_NEWS_TYPE_LIST.contains(item.getNewsType()) || CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(item.getNewsType())) {
replaceLinkTypeNum += 1;
}
idx += 1;
......
......@@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
......@@ -215,12 +216,14 @@ public class WeChatServiceImpl implements WeChatService{
private WeChatCustomerRequestEntity buildCustomerRequest(CustomerGraphics customerGraphics,List<ReferralEntityVo> urlList){
//类型判断
if (CUSTOMER_TEXT.equals(customerGraphics.getType())){
if (StringUtils.isNotBlank(customerGraphics.getContent()) && customerGraphics.getContent().contains(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER) && CollectionUtil.isEmpty(urlList)) {
if (StringUtils.isNotBlank(customerGraphics.getContent())
&& (customerGraphics.getContent().contains(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER) || customerGraphics.getContent().contains(CustomerCommonConstant.CUSTOMER_TEXT_MP_PATH_PLACEHOLDER))
&& CollectionUtil.isEmpty(urlList)) {
// 文本中存在需要替换的链接,但链接列表为空
return null;
}
//文本类客服,需要判断替换链接的个数
Map<Integer, String> sortReferral = urlList!=null&&!urlList.isEmpty()?urlList.stream().collect(Collectors.toMap(ReferralEntityVo::getSort, ReferralEntityVo::getReferral, (v1, v2) -> v2)):new HashMap<>(1);
Map<Integer, ReferralEntityVo> sortReferral = urlList!=null&&!urlList.isEmpty()?urlList.stream().collect(Collectors.toMap(ReferralEntityVo::getSort, Function.identity(), (v1, v2) -> v2)):new HashMap<>(1);
// 统计生成完成的非自定义链接的链接数量
int actualReferralCount = urlList == null ? 0 : (int) urlList.stream().filter(v -> !StringUtils.isAnyBlank(v.getAppid(), v.getReferral()) && v.getNewsType() != null && v.getNewsType() != -1).map(ReferralEntityVo::getSort).distinct().count();
......@@ -228,13 +231,17 @@ public class WeChatServiceImpl implements WeChatService{
String content = customerGraphics.getContent();
for (Map.Entry<Integer, String> replaceReferral : sortReferral.entrySet()) {
for (Map.Entry<Integer, ReferralEntityVo> replaceReferral : sortReferral.entrySet()) {
Integer sort = replaceReferral.getKey();
String url = replaceReferral.getValue();
ReferralEntityVo referralEntityVo = replaceReferral.getValue();
String url = referralEntityVo.getReferral();
//替换占位符
content=content.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER + sort, url);
content = content.replace(CustomerCommonConstant.CUSTOMER_TEXT_URL_PLACEHOLDER + sort, url)
.replace(CustomerCommonConstant.CUSTOMER_TEXT_MP_APPID_PLACEHOLDER, referralEntityVo.getMpAppId())
.replace(CustomerCommonConstant.CUSTOMER_TEXT_MP_PATH_PLACEHOLDER + sort, referralEntityVo.getMpPath())
;
}
return new WeChatCustomerRequestEntity(CUSTOMER_TEXT,content);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论