package com.caimei.www.utils; import lombok.extern.slf4j.Slf4j; import org.thymeleaf.util.StringUtils; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; /** * 小程序链接工具类 * * @author : Charles * @date : 2021/4/9 */ @Slf4j public class AppletsLinkUtil { /** * 1二级页面 */ public static final Pattern pattern1 = Pattern.compile("/cmpage/info-1"); public static final Pattern pattern34 = Pattern.compile("/topic.html"); /** * 2项目仪器详情 */ public static final Pattern pattern2 = Pattern.compile("/cmpage/info-2"); public static final Pattern pattern6 = Pattern.compile("equipment/detail"); /** * 3直播页面 */ public static final Pattern pattern3 = Pattern.compile("/cmpage/info-3"); public static final Pattern pattern36 = Pattern.compile("wx.vzan.com"); /** * 4自由页面 */ public static final Pattern pattern4 = Pattern.compile("/cmpage/info-4"); public static final Pattern pattern33 = Pattern.compile("page.html"); /** * 5商品详情 */ public static final Pattern pattern5 = Pattern.compile("/product-"); /** * 7供应商主页 */ public static final Pattern pattern7 = Pattern.compile("supplier/prolist"); public static final Pattern pattern8 = Pattern.compile("supplier/index.html"); public static final Pattern pattern9 = Pattern.compile("view/supplierHomePage.jsp"); public static final Pattern pattern10 = Pattern.compile("supplier/productlist-"); /** * 8专题活动页 */ public static final Pattern pattern11 = Pattern.compile("promotions.html"); public static final Pattern pattern12 = Pattern.compile("cmpage/area.html"); /** * 9二手市场介绍 */ public static final Pattern pattern13 = Pattern.compile("html/secondHand/introduction.jsp"); public static final Pattern pattern14 = Pattern.compile("flea-market/intro.html"); /** * 10二手商品列表 */ public static final Pattern pattern15 = Pattern.compile("html/secondHand/secondList.jsp"); public static final Pattern pattern16 = Pattern.compile("flea-market/list.html"); /** * 11二手商品发布 */ public static final Pattern pattern17 = Pattern.compile("html/maintenance/view/secondtransactions.jsp"); public static final Pattern pattern18 = Pattern.compile("flea-market/form.html"); /** * 12商品搜索 */ public static final Pattern pattern19 = Pattern.compile("product/search.shtml"); public static final Pattern pattern20 = Pattern.compile("product/search/list"); public static final Pattern pattern21 = Pattern.compile("product/list.html"); /** * 13信息详情 */ public static final Pattern pattern22 = Pattern.compile("info/detail"); /** * 14品牌招商介绍页 */ public static final Pattern pattern23 = Pattern.compile("html/InvestmentCaiMei/investmentpage.jsp"); public static final Pattern pattern24 = Pattern.compile("investment.html"); /** * 15维修保养介绍页 */ public static final Pattern pattern25 = Pattern.compile("html/maintenance/view/mt-entry-index.jsp"); public static final Pattern pattern26 = Pattern.compile("repair.html"); /** * 16首页 */ public static final Pattern pattern27 = Pattern.compile("index.action"); public static final Pattern pattern28 = Pattern.compile("index.html"); /** * 17注册页 */ public static final Pattern pattern29 = Pattern.compile("web/login/view/register_new_vip.jsp"); public static final Pattern pattern30 = Pattern.compile("register.html"); /** * 18信息中心 */ public static final Pattern pattern31 = Pattern.compile("info/center"); /** * 19供应商列表 */ public static final Pattern pattern32 = Pattern.compile("supplier/list.html"); /** * 20分类详情 */ public static final Pattern pattern35 = Pattern.compile("/cmpage/info-5"); /** * 21美博会专题页 */ public static final Pattern pattern37 = Pattern.compile("/beautytopic"); /** * 22美体会专题页 */ public static final Pattern pattern38 = Pattern.compile("/cmpage/info-5-301"); /** * 根据链接判断链接类型 * * @param link * @return */ public static Integer getLinkType(String link) { if (!StringUtils.isEmpty(link)) { if (pattern1.matcher(link).find() || pattern34.matcher(link).find()) { return 1; } else if (pattern2.matcher(link).find() || pattern6.matcher(link).find()) { return 2; } else if (pattern3.matcher(link).find() || pattern36.matcher(link).find()) { return 3; } else if (pattern4.matcher(link).find() || pattern33.matcher(link).find()) { return 4; } else if (pattern5.matcher(link).find()) { return 5; } else if (pattern7.matcher(link).find() || pattern8.matcher(link).find() || pattern9.matcher(link).find() || pattern10.matcher(link).find()) { return 7; } else if (pattern11.matcher(link).find() || pattern12.matcher(link).find()) { return 8; } else if (pattern13.matcher(link).find() || pattern14.matcher(link).find()) { return 9; } else if (pattern15.matcher(link).find() || pattern16.matcher(link).find()) { return 10; } else if (pattern17.matcher(link).find() || pattern18.matcher(link).find()) { return 11; } else if (pattern19.matcher(link).find() || pattern20.matcher(link).find() || pattern21.matcher(link).find()) { return 12; } else if (pattern22.matcher(link).find()) { return 13; } else if (pattern23.matcher(link).find() || pattern24.matcher(link).find()) { return 14; } else if (pattern25.matcher(link).find() || pattern26.matcher(link).find()) { return 15; } else if (pattern27.matcher(link).find() || pattern28.matcher(link).find()) { return 16; } else if (pattern29.matcher(link).find() || pattern30.matcher(link).find()) { return 17; } else if (pattern31.matcher(link).find()) { return 18; } else if (pattern32.matcher(link).find()) { return 19; } else if (pattern35.matcher(link).find()) { if (pattern38.matcher(link).find()) { return 22; } return 20; } else if (pattern37.matcher(link).find()) { return 21; } else { return -1; } } else { return -1; } } /** * 根据链接获取链接中携带的参数 * * @param linkType * @param link * @return */ public static Map getLinkParam(Integer linkType, String link) { HashMap map = new HashMap<>(); String[] idArr = link.split("/"); String[] split1 = null; String[] split2 = null; String[] split3 = null; if (idArr.length > 0) { split1 = idArr[idArr.length - 1].split("-"); split2 = idArr[idArr.length - 1].split("="); if (split1.length > 0) { split3 = split1[split1.length - 1].split("\\."); } } if (linkType == 3 || linkType == 5 || linkType == 20 || linkType == 22) { //-{id}.html if (split3 != null && split3.length == 2) { map.put("id", split3[0]); } } else if (linkType == 1 || linkType == 2 || linkType == 4 || linkType == 7) { if (pattern1.matcher(link).find() || pattern2.matcher(link).find() || pattern4.matcher(link).find() || pattern7.matcher(link).find() || pattern10.matcher(link).find()) { //-{id}.html if (split3 != null && split3.length == 2) { map.put("id", split3[0]); } } else if (pattern6.matcher(link).find() || pattern33.matcher(link).find() || pattern8.matcher(link).find() || pattern9.matcher(link).find() || pattern34.matcher(link).find()) { //id={id} if (split2 != null && split2.length == 2) { map.put("id", split2[1]); } } } else if (linkType == 13 || linkType == 18) { //a-{id}-b if (split1 != null && split1.length == 3) { map.put("id", split1[1]); } } else if (linkType == 12 || linkType == 19) { //keyword= if (split2 != null && split2.length == 2) { String keyword = split2[1]; try { keyword = URLDecoder.decode(keyword, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error("try-catch:",e); } map.put("keyword", keyword); } } return map; } }