提交 3bc6faa8 作者: 沈振路

客服消息适配“番茄小程序”

上级 9fd9adbc
...@@ -19,7 +19,9 @@ import com.yaoyaozw.customer.mapper.CustomerGraphicsDelayMapper; ...@@ -19,7 +19,9 @@ import com.yaoyaozw.customer.mapper.CustomerGraphicsDelayMapper;
import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper; import com.yaoyaozw.customer.mapper.CustomerGraphicsMapper;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper; import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.service.*; import com.yaoyaozw.customer.service.*;
import com.yaoyaozw.customer.utils.TencentCustomerUtil;
import com.yaoyaozw.customer.vo.AuthInfoVO; import com.yaoyaozw.customer.vo.AuthInfoVO;
import com.yaoyaozw.customer.vo.TencentMediaResponseVO;
import com.yaoyaozw.customer.vo.kanban.CommonOptionResponseVO; import com.yaoyaozw.customer.vo.kanban.CommonOptionResponseVO;
import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO; import com.yaoyaozw.customer.vo.customer.CrowdPackageUserVO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -36,6 +38,9 @@ import java.text.SimpleDateFormat; ...@@ -36,6 +38,9 @@ import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.CUSTOMER_TYPE_VALUE_MINI_PROGRAM;
import static com.yaoyaozw.customer.constants.CustomerCommonConstant.*;
/** /**
* @author darker * @author darker
* @date 2022/9/28 15:16 * @date 2022/9/28 15:16
...@@ -74,6 +79,8 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -74,6 +79,8 @@ public class CustomerServiceCommonAsyncComponent {
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@Resource @Resource
private CompanyAcquisitionLinkService companyAcquisitionLinkService; private CompanyAcquisitionLinkService companyAcquisitionLinkService;
@Autowired
private TencentCustomerUtil tencentCustomerUtil;
@Async("myExecutor") @Async("myExecutor")
...@@ -151,7 +158,9 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -151,7 +158,9 @@ public class CustomerServiceCommonAsyncComponent {
referralEntityService.ultimateDeleteReferrals(materialId, "and account_id is not null"); referralEntityService.ultimateDeleteReferrals(materialId, "and account_id is not null");
for (ReferralEntity referralEntity : referralEntityList) { for (ReferralEntity referralEntity : referralEntityList) {
// 不管有没有,先赋值图片地址
referralEntity.setMediaOriginUrl(customerGraphics.getCoverUrl());
referralEntity.setCustomerMsgType(customerGraphics.getType());
// 获取链接 // 获取链接
if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(referralEntity.getNewsType()) || if (CustomerCommonConstant.REMOTE_LINK_NEWS_TYPE_LIST.contains(referralEntity.getNewsType()) ||
CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) { CustomerCommonConstant.ACQUISITION_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
...@@ -687,6 +696,17 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -687,6 +696,17 @@ public class CustomerServiceCommonAsyncComponent {
referralEntity.setName(name); referralEntity.setName(name);
} }
referralEntity.setInfoId(authInfoVo.getId()); referralEntity.setInfoId(authInfoVo.getId());
// 判断如果是番茄小程序的话,处理参数
if (CustomerCommonConstant.STORE_NAME_TOMATO.equals(authInfoVo.getStoreType()) && CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType())) {
// 番茄小程序
if (CustomerCommonConstant.ACTIVITY_NEWS_TYPE.equals(referralEntity.getNewsType())) {
// 活动使用公众号本身的分销商Id
referralEntity.setAccountId(authInfoVo.getAccountId());
} else {
referralEntity.setAccountId(authInfoVo.getExpandDistributorId());
}
}
// LOCAL_LOG.info("获取链接, 参数: {}", referralEntity); // LOCAL_LOG.info("获取链接, 参数: {}", referralEntity);
R r = referralFeignClient.productReferral(referralEntity); R r = referralFeignClient.productReferral(referralEntity);
if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) { if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) {
...@@ -705,6 +725,62 @@ public class CustomerServiceCommonAsyncComponent { ...@@ -705,6 +725,62 @@ public class CustomerServiceCommonAsyncComponent {
String referral = jsonObject1.getString("referral"); String referral = jsonObject1.getString("referral");
referralEntity.setPromoteId(jsonObject1.getString("promoteId")); referralEntity.setPromoteId(jsonObject1.getString("promoteId"));
referralEntity.setReferral(referral); referralEntity.setReferral(referral);
// 取链接成功之后,后置处理番茄小程序
suffixHandleTomatoMiniProgram(authInfoVo, referralEntity);
}
private void suffixHandleTomatoMiniProgram(AuthInfoVO authInfoVo, ReferralEntity referralEntity) {
if (CustomerCommonConstant.STORE_NAME_TOMATO.equals(authInfoVo.getStoreType()) && CUSTOMER_TYPE_VALUE_MINI_PROGRAM.equals(referralEntity.getCustomerMsgType())) {
String referral = referralEntity.getReferral();
// 番茄小程序
if (CustomerCommonConstant.ACTIVITY_NEWS_TYPE.equals(referralEntity.getNewsType())) {
// 活动需要后置查询番茄小程序链接
// 根据 promoteId 查询番茄链接详情,番茄活动接口创建链接返回的是http链接,需要查询接口获取其小程序 /page 链接
R r = referralFeignClient.queryActivityInfo(referralEntity.getAccountId(), referralEntity.getPromoteId());
if (!r.getCode().equals(ApiResultConstant.SUCCESS_CODE)) {
throw new RuntimeException("获取活动链接详情失败: " + r.getMessage());
}
String res = r.getData("activityData", new TypeReference<String>() {});
JSONObject jsonObject = JSON.parseObject(res);
referral = jsonObject.getString("url");
}
if (StringUtils.isNotBlank(referral) && isMiniProgramPath(referral)) {
// 添加 get_book_item_id=true 参数
if (!referral.contains(GET_BOOK_ITEM)) {
referral = referral + "&" + GET_BOOK_ITEM_VAL;
}
// 添加 from_oa_app_id={flagId} 参数
if (!referral.contains(FROM_APPID)) {
referral = referral + "&" + FROM_APPID + "=" + authInfoVo.getExpandFlagId();
}
// 添加 landing_page=reader 参数
if (!referral.contains(LANDING_PAGE) && !CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
referral = referral + "&" + LANDING_PAGE_VAL;
}
// 常用链接换掉scene
if (CustomerCommonConstant.USUAL_LINK_NEWS_TYPE.equals(referralEntity.getNewsType())) {
referral = referral.replace("scene=0", "scene=1");
}
}
referralEntity.setMpAppId(authInfoVo.getExpandMpAppId());
referralEntity.setMpPath(referral);
// 暂时将小程序地址也赋值到跳转链接地址上
referralEntity.setReferral(referral);
// 上传腾讯图片素材
TencentMediaResponseVO uploadResult = tencentCustomerUtil.uploadTencentMedia(authInfoVo.getAppId(), referralEntity.getMediaOriginUrl(), referralEntity.getCustomerMsgType());
if (StringUtils.isNotEmpty(uploadResult.getErrmsg())) {
LOCAL_LOG.warn("公众号: {} 上传素材失败 {}", authInfoVo.getAppId(), uploadResult.getErrmsg());
}
referralEntity.setMediaId(uploadResult.getMedia_id());
}
}
private Boolean isMiniProgramPath(String path) {
return StringUtils.isNotBlank(path) && (path.startsWith("page") || path.startsWith("/page"));
} }
private Map<String, String> getStoreEntityMap(Set<String> storeKeySet) { private Map<String, String> getStoreEntityMap(Set<String> storeKeySet) {
......
...@@ -103,6 +103,10 @@ public class CustomerCommonConstant { ...@@ -103,6 +103,10 @@ public class CustomerCommonConstant {
if (type.equals(CUSTOMER_TYPE_VALUE_TEXT)) { if (type.equals(CUSTOMER_TYPE_VALUE_TEXT)) {
return CUSTOMER_TYPE_NAME_TEXT; return CUSTOMER_TYPE_NAME_TEXT;
} }
if (type.equals(CUSTOMER_TYPE_VALUE_MINI_PROGRAM)) {
return CUSTOMER_TYPE_NAME_MINI_PROGRAM;
}
return type; return type;
} }
......
...@@ -209,6 +209,30 @@ public class ReferralEntity implements Serializable { ...@@ -209,6 +209,30 @@ public class ReferralEntity implements Serializable {
@TableField(value = "config_name") @TableField(value = "config_name")
private String configName; private String configName;
/**
* 小程序标题
*/
@TableField("mp_title")
private String mpTitle;
/**
* 小程序appId
*/
@TableField("mp_app_id")
private String mpAppId;
/**
* 小程序跳转路径
*/
@TableField("mp_path")
private String mpPath;
@TableField("media_id")
private String mediaId;
@TableField(exist = false)
private String mediaOriginUrl;
@TableField(exist = false)
private String customerMsgType;
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "infoId") @ApiModelProperty(value = "infoId")
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
......
...@@ -28,6 +28,10 @@ public interface ReferralFeignClient { ...@@ -28,6 +28,10 @@ public interface ReferralFeignClient {
R productReferral(@RequestBody ReferralEntity referralEntity); R productReferral(@RequestBody ReferralEntity referralEntity);
@GetMapping("/queryActivityInfo")
R queryActivityInfo(@RequestParam String distributorId, @RequestParam String activityId);
/** /**
* 获取活动config * 获取活动config
* *
......
package com.yaoyaozw.customer.service.wechat.entity.customerRequest;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @author wgh
* @date 2022/10/8 19:15
*/
@Data
@NoArgsConstructor
public class CustomerMiniProgramItem implements Serializable {
private String title;
private String appid;
private String pagepath;
private String thumb_media_id;
public CustomerMiniProgramItem(String title, String appid, String pagepath, String thumb_media_id) {
this.title = title;
this.appid = appid;
this.pagepath = pagepath;
this.thumb_media_id = thumb_media_id;
}
}
package com.yaoyaozw.customer.service.wechat.entity.customerRequest; package com.yaoyaozw.customer.service.wechat.entity.customerRequest;
import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
...@@ -22,6 +23,8 @@ public class WeChatCustomerRequestEntity implements Serializable { ...@@ -22,6 +23,8 @@ public class WeChatCustomerRequestEntity implements Serializable {
private CustomerTextItem text; private CustomerTextItem text;
private CustomerMiniProgramItem miniprogrampage;
public WeChatCustomerRequestEntity( String msgtype, String title, String description, String url, String picurl) { public WeChatCustomerRequestEntity( String msgtype, String title, String description, String url, String picurl) {
this.msgtype = msgtype; this.msgtype = msgtype;
...@@ -34,6 +37,16 @@ public class WeChatCustomerRequestEntity implements Serializable { ...@@ -34,6 +37,16 @@ public class WeChatCustomerRequestEntity implements Serializable {
this.text = new CustomerTextItem(content); this.text = new CustomerTextItem(content);
} }
public static WeChatCustomerRequestEntity miniProgram(String title, String appId, String path, String mediaId) {
WeChatCustomerRequestEntity weChatCustomerRequestEntity = new WeChatCustomerRequestEntity();
weChatCustomerRequestEntity.setMsgtype(CustomerCommonConstant.CUSTOMER_TYPE_VALUE_MINI_PROGRAM);
weChatCustomerRequestEntity.setMiniprogrampage(
new CustomerMiniProgramItem(title, appId, path, mediaId)
);
return weChatCustomerRequestEntity;
}
public WeChatCustomerRequestEntity() { public WeChatCustomerRequestEntity() {
} }
......
...@@ -40,6 +40,8 @@ public class WeChatServiceImpl implements WeChatService{ ...@@ -40,6 +40,8 @@ public class WeChatServiceImpl implements WeChatService{
private static final String CUSTOMER_NEWS="news"; private static final String CUSTOMER_NEWS="news";
private static final String CUSTOMER_MP="miniprogrampage";
private static final int THREAD_SIZE=1000; private static final int THREAD_SIZE=1000;
private static final Integer SUCCESS_CODE=0; private static final Integer SUCCESS_CODE=0;
...@@ -245,6 +247,17 @@ public class WeChatServiceImpl implements WeChatService{ ...@@ -245,6 +247,17 @@ public class WeChatServiceImpl implements WeChatService{
if (urlList!=null&&!urlList.isEmpty()){ if (urlList!=null&&!urlList.isEmpty()){
return new WeChatCustomerRequestEntity(CUSTOMER_NEWS,customerGraphics.getExtendTitle(),customerGraphics.getContent(),urlList.get(0).getReferral(),customerGraphics.getCoverUrl()); return new WeChatCustomerRequestEntity(CUSTOMER_NEWS,customerGraphics.getExtendTitle(),customerGraphics.getContent(),urlList.get(0).getReferral(),customerGraphics.getCoverUrl());
} }
} else if (CUSTOMER_MP.equals(customerGraphics.getType())) {
if (CollectionUtil.isNotEmpty(urlList)) {
ReferralEntityVo mpReferralEntity = urlList.get(0);
String title = StringUtils.isNotBlank(mpReferralEntity.getMpTitle()) ? mpReferralEntity.getMpTitle() : customerGraphics.getExtendTitle();
if (StringUtils.isAnyBlank(
title, mpReferralEntity.getMpAppId(), mpReferralEntity.getMpPath(), mpReferralEntity.getMediaId()
)) {
return null;
}
return WeChatCustomerRequestEntity.miniProgram(title, mpReferralEntity.getMpAppId(), mpReferralEntity.getMpPath(), mpReferralEntity.getMediaId());
}
} }
return null; return null;
} }
......
...@@ -34,6 +34,10 @@ public class AuthInfoVO implements Serializable { ...@@ -34,6 +34,10 @@ public class AuthInfoVO implements Serializable {
@ApiModelProperty("书城名") @ApiModelProperty("书城名")
private String storeTypeName; private String storeTypeName;
private String expandDistributorId;
private String expandMpAppId;
private String expandFlagId;
public void putPropertyValue(AuthorizerInfo authorizerInfo) { public void putPropertyValue(AuthorizerInfo authorizerInfo) {
this.id = authorizerInfo.getId(); this.id = authorizerInfo.getId();
this.accountId = authorizerInfo.getAccountId(); this.accountId = authorizerInfo.getAccountId();
......
...@@ -22,6 +22,15 @@ public class ReferralEntityVo implements Serializable { ...@@ -22,6 +22,15 @@ public class ReferralEntityVo implements Serializable {
private String referral; private String referral;
private Integer sort; private Integer sort;
private String mpTitle;
private String mpAppId;
private String mpPath;
private String mediaId;
} }
...@@ -12,11 +12,15 @@ ...@@ -12,11 +12,15 @@
<select id="getAuthInfoList" resultType="com.yaoyaozw.customer.vo.AuthInfoVO"> <select id="getAuthInfoList" resultType="com.yaoyaozw.customer.vo.AuthInfoVO">
select select
id, account_id as accountId, appid appId, ai.id, ai.account_id as accountId, ai.appid appId,
nick_name as accountName, ai.nick_name as accountName,
store_type as storeType ai.store_type as storeType,
from authorizer_info aei.mp_distributor_id expandDistributorId,
aei.mp_appid expandMpAppId,
aei.flag_id expandFlagId
from authorizer_info ai
LEFT JOIN authorizer_expand_info aei ON aei.authorizer_appid = ai.appid
where account_id in where account_id in
<foreach collection="accountSet" item="accountId" separator="," open="(" close=")"> <foreach collection="accountSet" item="accountId" separator="," open="(" close=")">
#{accountId} #{accountId}
......
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
<select id="findByMaterialGraphicsId" resultType="com.yaoyaozw.customer.vo.referral.ReferralEntityVo"> <select id="findByMaterialGraphicsId" resultType="com.yaoyaozw.customer.vo.referral.ReferralEntityVo">
select material_graphics_id ,referral.account_id,authInfo.appid,referral.referral,referral.sort, referral.news_type select material_graphics_id ,referral.account_id,authInfo.appid,referral.referral,referral.sort, referral.news_type,
mp_title mpTitle, mp_app_id mpAppId, mp_path mpPath, media_id mediaId
from referral_entity referral left join authorizer_info authInfo from referral_entity referral left join authorizer_info authInfo
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论