diff --git a/src/main/java/cn/van/business/util/JDUtil.java b/src/main/java/cn/van/business/util/JDUtil.java index f1c821d..2b67579 100644 --- a/src/main/java/cn/van/business/util/JDUtil.java +++ b/src/main/java/cn/van/business/util/JDUtil.java @@ -96,7 +96,7 @@ public class JDUtil { *

* 订单号: */ - private static final String WENAN_D = "单:\n" + "{单号} \n" + "分销标记(标记用,勿改):\n" + "型号:\n" + "\n" + "链接:\n" + "\n" + "下单付款:\n" + "\n" + "后返金额:\n" + "\n" + "地址:\n" +"{地址}"+ "\n" + "物流链接:\n" + "\n" + "订单号:\n" + "\n" + "下单人:\n" + "\n"; + private static final String WENAN_D = "单:\n" + "{单号} \n" + "分销标记(标记用,勿改):\n" + "型号:\n" + "\n" + "链接:\n" + "\n" + "下单付款:\n" + "\n" + "后返金额:\n" + "\n" + "地址:\n" + "{地址}" + "\n" + "物流链接:\n" + "\n" + "订单号:\n" + "\n" + "下单人:\n" + "\n"; final WXUtil wxUtil; private final StringRedisTemplate redisTemplate; @@ -698,15 +698,23 @@ public class JDUtil { private void handleInitState(String wxid, String message, UserInteractionState state) { if ("转".equals(message)) { state.setCurrentState(UserInteractionState.ProcessState.PRODUCT_PROMOTION); - state.setCurrentField("content"); - wxUtil.sendTextMessage(wxid, "请输入推广方案(包含商品链接):", 1, wxid, false); + state.setCurrentField("content—withOutPic"); + wxUtil.sendTextMessage(wxid, "请输入推广方案 \n " + "(指令: 转 不返回图文 \n 文案 带图文 ):", 1, wxid, false); + logger.info("进入转链流程 - 用户: {}", wxid); + } else if ("文案".equals(message)) { + state.setCurrentState(UserInteractionState.ProcessState.PRODUCT_PROMOTION); + state.setCurrentField("content—withPic"); + wxUtil.sendTextMessage(wxid, "请输入推广方案 \n " + "(指令: 转 不返回图文 \n 文案 带图文 ):", 1, wxid, false); logger.info("进入转链流程 - 用户: {}", wxid); } } private void handlePromotionState(String wxid, String message, UserInteractionState state) { - if ("content".equals(state.getCurrentField())) { - processContentInput(wxid, message, state); + if ("content—withOutPic".equals(state.getCurrentField())) { + processContentInput(wxid, message, state,false); + } else if ("content—withPic".equals(state.getCurrentField())) { + processContentInput(wxid, message, state,true); + } else if ("confirm".equals(state.getCurrentField())) { handleGiftMoneyConfirmation(wxid, message, state); } @@ -821,8 +829,9 @@ public class JDUtil { * @param wxid 用户微信ID * @param message 用户输入的方案内容 * @param state 当前交互状态 + * @param b */ - private void processContentInput(String wxid, String message, UserInteractionState state) { + private void processContentInput(String wxid, String message, UserInteractionState state, boolean withPic) { try { // 1. 清除旧缓存 cacheMap.remove("productData" + wxid); @@ -831,17 +840,26 @@ public class JDUtil { // 2. 生成推广内容 HashMap> contentResult = generatePromotionContent(message, false); - // 3. 发送文本内容 - for (String text : contentResult.get("text")) { - wxUtil.sendTextMessage(wxid, text, 1, wxid, true); - } + if (withPic){ + // 3. 发送文本内容 + for (String text : contentResult.get("text")) { + wxUtil.sendTextMessage(wxid, text, 1, wxid, true); + } + // 4. 发送图片(如果有) + List images = contentResult.get("images"); + if (images != null) { + for (String imageUrl : images) { + if (imageUrl != null) { + wxUtil.sendImageMessage(wxid, imageUrl); + } + } + } + }else { - // 4. 发送图片(如果有) - List images = contentResult.get("images"); - if (images != null) { - for (String imageUrl : images) { - if (imageUrl != null) { - wxUtil.sendImageMessage(wxid, imageUrl); + // 3. 发送文本内容 + for (String text : contentResult.get("text")) { + if (text.contains("链接类型")){ + wxUtil.sendTextMessage(wxid, text, 1, wxid, true); } } } @@ -932,7 +950,7 @@ public class JDUtil { * @param message 方案内容,包含商品链接 * @return 处理后的方案,附带商品信息 */ - public synchronized HashMap> generatePromotionContent(String message, Boolean isCj) { + public synchronized HashMap> generatePromotionContent(String message, Boolean isCj) { HashMap> finallMessage = new HashMap<>(); List textList = new ArrayList<>(); List imagesList = new ArrayList<>(); @@ -1250,7 +1268,7 @@ public class JDUtil { String title = ""; if (!isCj) { - try{ + try { String[] lines = message.split("\\r?\\n"); if (lines.length > 0) { title = lines[0]; @@ -1261,7 +1279,7 @@ public class JDUtil { logger.info("文案首行 {}", title); title = title.replaceAll("@|所有人", ""); } - }catch (Exception e){ + } catch (Exception e) { logger.error("文案首行异常", e); }