| | |
| | | import com.yeshi.goods.facade.utils.taobao.HaoDanKuApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import org.yeshi.utils.UrlUtils;
|
| | |
|
| | | /**
|
| | | * 转链组件
|
| | | *
|
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class ConvertLinkManager {
|
| | |
| | | private TaoBaoTokenAuctionIdMapManager taoBaoTokenAuctionIdMapManager;
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: convertJDLinkFromText @Description:转链文本中的京东短链 @param text @param
|
| | | * uid @param share @return @throws Exception String 返回类型 @throws
|
| | | */
|
| | |
|
| | | public String convertJDLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | | public String convertJDLinkFromText(String text, Long uid, boolean share, boolean simpleTKToken) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | |
| | | * @Title: convertTBLinkFromText @Description: 转链文本中的淘口令 @param text @param
|
| | | * uid @param share @return @throws Exception String 返回类型 @throws
|
| | | */
|
| | | private String convertTBLinkFromText(String text, Long uid, boolean share) throws Exception {
|
| | | /**
|
| | | * @param text
|
| | | * @param uid
|
| | | * @param share
|
| | | * @param simpleToken -是否采用简版淘口令
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | private String convertTBLinkFromText(String text, Long uid, boolean share, boolean simpleToken) throws Exception {
|
| | |
|
| | | StringBuilder builder = new StringBuilder(text);
|
| | | String newText = builder.toString();
|
| | |
| | | throw new Exception("商品转链失败");
|
| | | }
|
| | |
|
| | | String newToken = TaoKeApiUtil.getTKToken(simpleGoods.getPictUrl(), simpleGoods.getTitle(), link);
|
| | | String newToken = TaoKeApiUtil.getTKToken(simpleGoods.getPictUrl(), simpleGoods.getTitle(), link, simpleToken);
|
| | | if (StringUtil.isNullOrEmpty(newToken)) {
|
| | | throw new Exception("口令转链失败");
|
| | | }
|
| | |
| | | link = dto.getClick_url();
|
| | | }
|
| | |
|
| | | String token = TaoKeApiUtil.getTKToken("http://", "淘宝官方活动", link);
|
| | | String token = TaoKeApiUtil.getTKToken("http://", "淘宝官方活动", link, simpleToken);
|
| | | newText = newText.replace(st, TaoBaoUtil.filterTaoToken(token));
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: convertLinkFromText @Description: 从文本转链 @param text @return
|
| | | * String 返回类型 @throws
|
| | | */
|
| | | public String convertLinkFromText(String text, Long uid, boolean share)
|
| | | public String convertLinkFromText(String text, Long uid, boolean share, boolean simpleToken)
|
| | | throws ConvertLinkExceptionException, Exception {
|
| | | String newText = convertJDLinkFromText(text, uid, share);
|
| | | String newText = convertJDLinkFromText(text, uid, share, simpleToken);
|
| | | newText = convertPDDLinkFromText(newText, uid, share);
|
| | | newText = convertTBLinkFromText(newText, uid, share);
|
| | | newText = convertTBLinkFromText(newText, uid, share, simpleToken);
|
| | |
|
| | | List<String> urls = UrlUtils.parseUrlsFromText(text);
|
| | | if (urls != null)
|
| | | for (String url : urls) {
|
| | | if (url.contains("{relationId}")) {
|
| | | String relationId = userExtraTaoBaoInfoService.getRelationIdByUid(uid);
|
| | | if (StringUtil.isNullOrEmpty(relationId)) {
|
| | | throw new Exception("淘宝未授权");
|
| | | }
|
| | | newText = newText.replace(url, url.replace("{relationId}", relationId));
|
| | | }
|
| | | }
|
| | | if (text.equalsIgnoreCase(newText))
|
| | | throw new ConvertLinkExceptionException(ConvertLinkExceptionException.CODE_NONE, "不包含可转链的口令与链接");
|
| | | return newText;
|
| | |
| | | * 创建口令 @Title: createTaoBaoToken @Description: @param uid 用户ID @param
|
| | | * picturl @param title @param link @return String 返回类型 @throws
|
| | | */
|
| | | public String createTaoBaoToken(Long uid, String picturl, String title, String link) {
|
| | |
|
| | | String token = TaoKeApiUtil.getTKToken(picturl, title, link);
|
| | | public String createTaoBaoToken(Long uid, String picturl, String title, String link, boolean simpleToken) {
|
| | | String token = TaoKeApiUtil.getTKToken(picturl, title, link, simpleToken);
|
| | | if (!StringUtil.isNullOrEmpty(token)) {
|
| | | // 缓存30分钟
|
| | | redisManager.cacheCommonString(
|