admin
2024-01-23 81da61b828e29b7745e1382dfbbaeb685dc083ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
package com.yeshi.fanli.service.manger;
 
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import javax.annotation.Resource;
 
import com.yeshi.fanli.entity.taobao.SearchFilter;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.goods.douyin.CSJCPSApiUtil;
import com.yeshi.fanli.util.goods.douyin.DYUtil;
import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.goods.facade.utils.taobao.DaTaoKeApiUtil;
import org.jsoup.Jsoup;
import org.springframework.stereotype.Component;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.NumberUtil;
 
import com.yeshi.fanli.dto.douyin.DouYinGoods;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.jd.JDGoods;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.taobao.TaoBaoTokenParseException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.exception.user.TokenRecordException;
import com.yeshi.fanli.service.inter.user.TokenRecordService;
import com.yeshi.fanli.service.manger.goods.jd.JDGoodsLinkParseManager;
import com.yeshi.fanli.service.manger.goods.tb.TaoBaoTokenAuctionIdMapManager;
import com.yeshi.fanli.util.factory.CommonGoodsFactory;
import com.yeshi.fanli.util.jd.JDApiUtil;
import com.yeshi.fanli.util.jd.JDUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
import com.yeshi.fanli.util.suning.SuningApiUtil;
import com.yeshi.fanli.util.suning.SuningUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.vipshop.VipShopApiUtil;
import com.yeshi.fanli.util.vipshop.VipShopUtil;
import com.yeshi.fanli.vo.msg.TokenVO;
import com.yeshi.fanli.vo.search.GoodsDocParseResultVO;
 
import net.sf.json.JSONObject;
 
/**
 * 粘贴板解析
 *
 * @author Administrator
 */
@Component
public class ClipboardAnalysisManager {
 
    @Resource
    private JDGoodsLinkParseManager jdGoodsLinkParseManager;
 
    @Resource
    private TokenRecordService tokenRecordService;
 
    @Resource
    private TaoBaoTokenAuctionIdMapManager taoBaoTokenAuctionIdMapManager;
 
    @Resource
    private RedisManager redisManager;
 
    /**
     * @Title: parseContentType @Description: 解析文本的类型 @param text @return Set
     * <ClipboardContentType> 返回类型 @throws
     */
    public static Set<ClipboardContentType> parseContentType(String originText, String platform, String version) {
        Set<ClipboardContentType> typeSet = new HashSet<>();
        StringBuffer textBuffer = new StringBuffer(originText);
        String text = textBuffer.toString();
        // 自有口令
        String parseToken = TokenUtil.parseToken(text);
        if (!StringUtil.isNullOrEmpty(parseToken)) {
            typeSet.add(ClipboardContentType.systemToken);
            text = text.replace(parseToken, "");
        }
 
        // 链接
        String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
        Pattern p = Pattern.compile(URL_REGEX);
        Matcher matcher = p.matcher(text);
        while (matcher.find()) {
            String url = matcher.group();
            if (!StringUtil.isNullOrEmpty(url)) {
                typeSet.add(ClipboardContentType.link);
                text = text.replace(url, "");
            }
        }
 
        // 淘口令
        List<String> taoBaoTokenList = null;
        if (VersionUtil.greaterThan_2_0_7(platform, version))
            taoBaoTokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(text);
        else
            taoBaoTokenList = TaoBaoUtil.getTokenListFromText(text);
        if (taoBaoTokenList != null && taoBaoTokenList.size() > 0) {
            typeSet.add(ClipboardContentType.taoBaoToken);
            for (String token : taoBaoTokenList) {
                text = text.replace(token, "");
            }
        }
        // 文本
        if (text != null && text.trim().length() > 0) {
            typeSet.add(ClipboardContentType.text);
        }
 
 
        return typeSet;
    }
 
 
    /**
     * 特价解析粘贴板
     * 无平台,根据格式判断平台
     *
     * @param text
     */
    public Integer tejiaParseSourceType(String text) {
        if (text == null)
            return null;
        text = text.trim();
        //判断是否有链接
        List<String> linkList = HttpUtil.getUrlListFromText(text);
        if (linkList != null && linkList.size() > 0) {
            String link = linkList.get(0);
            if (TaoBaoUtil.isTaoBaoLink(link)) {
                return Constant.SOURCE_TYPE_TAOBAO;
            } else if (JDUtil.isJDLink(link)) {
                return Constant.SOURCE_TYPE_JD;
            } else if (PinDuoDuoUtil.isPDDLink(link)) {
                return Constant.SOURCE_TYPE_PDD;
            } else if (VipShopUtil.isVIPShopLink(link)) {
                return Constant.SOURCE_TYPE_VIP;
            } else if (SuningUtil.isSuningLink(link)) {
                return Constant.SOURCE_TYPE_SUNING;
            }
            //链接非电商平台链接
            return null;
        }
 
        //判断是否疑似口令
        if (TaoBaoUtil.isHaveNewVersionTaoBaoToken(text)) {
            return Constant.SOURCE_TYPE_TAOBAO;
        }
        return null;
    }
 
    /**
     * @Title: parse @Description: 解析 @param text @param typeSet void
     * 返回类型 @throws
     */
    public void parse(String platform, String version, String text, Long uid, IClipboardAnalysisResult resultListener) {
        if (text == null)
            return;
        text = text.trim();
 
        Set<ClipboardContentType> typeSet = parseContentType(text, platform, version);
        //新版口令
        String goodsId = null;
        if (text.contains("https://m.tb.cn/")) {
            String tempGoodsId = DaTaoKeApiUtil.parseGoodsIdFromToken(text);
            if (tempGoodsId != null) {
                goodsId = tempGoodsId;
                typeSet.add(ClipboardContentType.taoBaoToken);
            } else {
                try {
                    TaoKeApiUtil.TokenConvertResult result = TaoKeApiUtil.tokenConvert(text);
                    if (result != null) {
                        goodsId = result.getNum_iid();
                        typeSet.add(ClipboardContentType.taoBaoToken);
                    }
                } catch (TaoBaoTokenParseException e) {
                    e.printStackTrace();
                }
            }
        }
 
        // 系统口令
        if (typeSet.contains(ClipboardContentType.systemToken)) {
            try {
                TokenVO tokenVO = tokenRecordService.discernToken(text, uid, platform, version);
                resultListener.onResult(tokenVO);
            } catch (TokenRecordException e) {
                if (e.getCode() == 1001) { // 需要用户登录
                    resultListener.needLogin(e.getMsg());
                } else {
                    resultListener.none();
                }
            }
            return;
        }
        //优先解析淘口令
        if (goodsId != null) {
            TaoBaoGoodsBrief taobaoGoods =null;
            try {
                taobaoGoods =  TaoKeApiUtil.getSimpleGoodsInfo(goodsId);
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
            if (taobaoGoods==null) {
                int startIndex = text.indexOf("「");
                int endIndex = text.indexOf("」");
                if (startIndex > 0 && endIndex > 0) {
                    resultListener.onResult(text.substring(startIndex+1,endIndex));
                    return;
                }
            } else {
                CommonGoods commonGoods = CommonGoodsFactory.create(taobaoGoods);
                if (commonGoods != null)
                    resultListener.onResult(commonGoods);
                else
                    resultListener.onResult(text);
            }
            return;
        }
 
 
        // 只有链接 淘宝链接/京东链接/拼多多链接
        if (typeSet.size() == 1) {
            if (typeSet.contains(ClipboardContentType.link)) {// 纯链接
                // 解析商品
                CommonGoods goods = parseLink(text);
                if (goods == null) {
                    // 判断链接之中是否包含口令
                    try {
                        String newText = URLDecoder.decode(text, "UTF-8");
                        List<String> tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(newText);
                        if (tokenList != null && tokenList.size() > 0) {
                            try {
                                goods = parseTaoBaoToken(tokenList.get(0));
                            } catch (TaoBaoTokenParseException e) {
                            }
                            if (goods != null && goods.getGoodsId() != null) {
                                resultListener.onResult(goods);
                                return;
                            }
                        }
 
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
 
                    //TODO 解析链接中的title
//                    Jsoup.connect(text).get();
 
 
                    resultListener.none();
                } else {
                    resultListener.onResult(goods);
                }
 
            } else if (typeSet.contains(ClipboardContentType.taoBaoToken)) {// 纯淘口令
 
                try {
                    CommonGoods commonGoods = parseTaoBaoToken(text);
                    if (commonGoods != null)
                        resultListener.onResult(commonGoods);
                    else
                        resultListener.onResult(text);
 
                } catch (TaoBaoTokenParseException e1) {
                    resultListener.onResult(text);
                }
 
            } else {// 纯文本
                // 文本推荐
                if (text.length() > 256)
                    resultListener.none();
                else
                    resultListener.onResult(text);
            }
        } else if (typeSet.size() == 2) {
            List<String> urlList = HttpUtil.getUrlListFromText(text);
            List<String> tokenList = null;
            if (VersionUtil.greaterThan_2_0_7(platform, version))
                tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(text);
            else
                tokenList = TaoBaoUtil.getTokenListFromText(text);
 
            String link = null;
            String token = null;
 
            if (typeSet.contains(ClipboardContentType.link) && typeSet.contains(ClipboardContentType.taoBaoToken)) {// 链接+口令
                if (text.indexOf(urlList.get(0)) < text.indexOf(tokenList.get(0)))// 第一个链接在第一个口令前面
                    link = urlList.get(0);
                else// 第一个口令在第一个链接前面
                    token = tokenList.get(0);
            } else if (typeSet.contains(ClipboardContentType.link) && typeSet.contains(ClipboardContentType.text)) {// 链接+文本
                link = urlList.get(0);
 
            } else {// 口令+文本
                token = tokenList.get(0);
            }
 
            if (!StringUtil.isNullOrEmpty(link)) {
                CommonGoods goods = parseLink(urlList.get(0));
                if (goods == null || goods.getGoodsId() == null) {
                    if (tokenList.size() == 0 && urlList.size() == 2
                            && urlList.get(0).indexOf("://uland.taobao.com") > -1
                            && urlList.get(1).indexOf("?id=") > -1) {// 有2个链接的文案,第一个是店铺券链接,其中二个是淘宝商品详情
                        CommonGoods goods1 = parseLink(urlList.get(1));
                        if (goods1 != null && goods1.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
                            resultListener.onResult(goods1);
                        } else {
                            resultListener.onResult(new GoodsDocParseResultVO(text, urlList.get(0)));
                        }
 
                    } else if (urlList.size() > 1)
                        resultListener.onResult(new GoodsDocParseResultVO(text, urlList.get(0)));
                    else {// 单链接
                        // 判断是否包含可转链的链接
                        if (!isContainsLinkConvert(link))
                            resultListener.none();
                        else
                            resultListener.onResult(new GoodsDocParseResultVO(text, link));
                    }
                } else {
                    if (VersionUtil.greaterThan_2_0_7(platform, version)) {
                        if (urlList.size() == 1)// 单链接+文本
                            resultListener.onResult(goods);
                        else
                            resultListener.onResult(new GoodsDocParseResultVO(text, goods));
                    } else {
                        resultListener.onResult(goods);
                    }
                }
            } else {
                CommonGoods goods = null;
                try {
                    goods = parseTaoBaoToken(token);
                } catch (TaoBaoTokenParseException e) {
                    resultListener.onResult(new GoodsDocParseResultVO(text));
                    return;
                }
                if (goods != null && goods.getGoodsId() != null) {
                    if (tokenList.size() == 1) {// 单个口令
                        resultListener.onResult(goods);
                    } else
                        resultListener.onResult(new GoodsDocParseResultVO(text, goods));
                } else {
                    resultListener.onResult(new GoodsDocParseResultVO(text));
                }
            }
 
        } else if (typeSet.size() == 3) {// 口令+链接+文本
            // 淘口令
            List<String> tokenList = null;
            if (VersionUtil.greaterThan_2_0_7(platform, version))
                tokenList = TaoBaoUtil.getTokenListFromTextWithKuoHao(text);
            else
                tokenList = TaoBaoUtil.getTokenListFromText(text);
 
            List<String> urlList = HttpUtil.getUrlListFromText(text);
            if (text.contains("【") && tokenList != null && tokenList.size() == 1 && urlList != null
                    && urlList.size() == 1) {// Android淘宝链接复制
                CommonGoods goods = null;
                try {
                    goods = parseTaoBaoToken(tokenList.get(0));
                } catch (TaoBaoTokenParseException e1) {
                    e1.printStackTrace();
                }
                if (goods == null) {
                    if (text.trim().indexOf("【") > -1 && text.trim().indexOf("】") > 0) {
                        // 截取标题
                        String title = text.trim().substring(text.trim().indexOf("【") + 1,
                                text.trim().lastIndexOf("】"));
                        goods = new CommonGoods();
                        goods.setTitle(title);
                        goods.setPicture("http://");
                    }
                }
 
                if (goods != null) {
                    resultListener.onResult(goods);
                }
 
            } else {// 文案
 
                String token = null;
                token = tokenList.get(0);
 
                if (!StringUtil.isNullOrEmpty(token)) {
                    CommonGoods goods = null;
                    try {
                        goods = parseTaoBaoToken(token);
                        if (goods != null && goods.getGoodsId() != null) {
                            // 如:http://rd.wechat.com/qrcode/confirm?block_type=101&content=%E3%80%90%E5%8E%9F%E4%BB%B7%E3%80%9120%E5%85%83%0A%E3%80%90%E5%88%B8%E5%90%8E%E4%BB%B7%E3%80%9120%E5%85%83%0A-----------------%0A%E5%BE%A9%E8%A3%BD%E8%BF%99%E6%9D%A1%EF%BC%8C(psNX1UPRJNe)%EF%BC%8C%E8%BF%9B%E5%85%A5%E3%80%90Tao%E5%AE%9D%E3%80%91%E5%8D%B3%E5%8F%AF%E6%8A%A2%E8%B4%AD&lang=zh_CN&scene=37
                            if (text.contains("//rd.wechat.com/qrcode/")) {// 微信复制过来的
                                resultListener.onResult(goods);
                            } else
                                resultListener.onResult(new GoodsDocParseResultVO(text, goods));
                        } else {
                            resultListener.onResult(new GoodsDocParseResultVO(text));
                        }
                    } catch (TaoBaoTokenParseException e) {
                        resultListener.onResult(new GoodsDocParseResultVO(text));
                    }
                } else {
                    CommonGoods goods = parseLink(urlList.get(0));
                    if (goods == null || goods.getGoodsId() == null) {
                        resultListener.onResult(new GoodsDocParseResultVO(text, urlList.get(0)));
                    } else {
                        resultListener.onResult(new GoodsDocParseResultVO(text, goods));
                    }
                }
            }
            return;
        }
    }
 
    /**
     * @Title: parseLink @Description: 解析单链接 @param link @return CommonGoods
     * 返回类型 @throws
     */
    public CommonGoods parseLink(String link) {
 
        SimpleCommonGoods simpleGoods = parseGoodsIdFromLink(link);
        if (simpleGoods == null) {
            return null;
        }
 
        CommonGoods commonGoods = null;
        if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
            TaoBaoGoodsBrief goods = null;
            try {
                goods = redisManager.getTaoBaoGoodsBrief(simpleGoods.getGoodsId());
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
 
            if (goods != null) {
                commonGoods = CommonGoodsFactory.create(goods);
            } else {
                SearchFilter sf=new SearchFilter();
                sf.setKey("https://item.taobao.com/item.htm?id="+simpleGoods.getGoodsId());
                TaoBaoSearchResult searchResult = TaoKeApiUtil.searchWuLiaoNew(sf,null,null);
                if(searchResult!=null&&searchResult.getTaoBaoGoodsBriefs()!=null&&searchResult.getTaoBaoGoodsBriefs().size()>0){
                    TaoBaoGoodsBrief tempGoods =   searchResult.getTaoBaoGoodsBriefs().get(0);
                    commonGoods = new CommonGoods();
                    commonGoods.setTitle(tempGoods.getTitle());
                    commonGoods.setPicture(tempGoods.getPictUrl());
                }else {
                    goods = TaoBaoUtil.getTmallGoodsInfo(simpleGoods.getGoodsId());
                    if (goods != null) {
                        commonGoods = new CommonGoods();
                        commonGoods.setTitle(goods.getTitle());
                        commonGoods.setPicture(goods.getPictUrl());
                    } else {
                        // TODO 根据淘宝商品ID解析标题与图片
                    }
                }
            }
 
        } else if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_JD) {
            // 优先采用高级接口请求数据
            JDGoods jdGoods = null;
            try {
                // 防止高级接口被收回
                jdGoods = JDApiUtil.queryGoodsDetail(Long.parseLong(simpleGoods.getGoodsId()));
            } catch (Exception e) {
            }
            if (jdGoods == null) {
                jdGoods = JDApiUtil.getGoodsDetail(Long.parseLong(simpleGoods.getGoodsId()));
            }
            if (jdGoods != null) {
                commonGoods = CommonGoodsFactory.create(jdGoods);
            } else {// 商品并未参与推广
                jdGoods = JDUtil.getSimpleGoodsInfo(simpleGoods.getGoodsId());
                if (jdGoods != null) {
                    commonGoods = new CommonGoods();
                    commonGoods.setTitle(jdGoods.getSkuName());
                    commonGoods.setPicture(jdGoods.getPicUrl());
                }
            }
        } else if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_PDD) {
            PDDGoodsDetail goods = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(simpleGoods.getGoodsId()));
            if (goods != null) {
                commonGoods = CommonGoodsFactory.create(goods);
            } else {
                goods = PinDuoDuoUtil.getPDDGoodsInfo(simpleGoods.getGoodsId());
                if (goods != null) {
                    commonGoods = new CommonGoods();
                    commonGoods.setTitle(goods.getGoodsName());
                    commonGoods.setPicture(goods.getGoodsThumbnailUrl());
                }
            }
        } else if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_VIP) {
            VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(simpleGoods.getGoodsId());
            if (goods != null) {
                commonGoods = CommonGoodsFactory.create(goods);
            }
        } else if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_SUNING) {
            SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(simpleGoods.getGoodsId().split("-")[1],
                    simpleGoods.getGoodsId().split("-")[0]);
            if (goods != null) {
                commonGoods = CommonGoodsFactory.create(goods);
            }
        } else if (simpleGoods.getGoodsType() == Constant.SOURCE_TYPE_DY) {
            DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(simpleGoods.getGoodsId()));
            if (goods != null) {
                commonGoods = CommonGoodsFactory.create(goods);
            }
        }
 
        return commonGoods;
    }
 
    /**
     * 从链接中解析商品ID
     *
     * @return
     */
    public SimpleCommonGoods parseGoodsIdFromLink(String link) {
 
        String jdId = parseJDSkuIdFromLink(link);
 
        if (!StringUtil.isNullOrEmpty(jdId)) {
            return new SimpleCommonGoods(jdId, Constant.SOURCE_TYPE_JD);
        }
 
        // 解析拼多多
        String pddId = PinDuoDuoUtil.getPDDGoodsId(link);
        if (!StringUtil.isNullOrEmpty(pddId)) {
            return new SimpleCommonGoods(pddId, Constant.SOURCE_TYPE_PDD);
        }
 
        // 解析苏宁
        String suningId = SuningUtil.parseGoodsIdByUrl(link);
        if (!StringUtil.isNullOrEmpty(suningId)) {
            return new SimpleCommonGoods(suningId, Constant.SOURCE_TYPE_SUNING);
        }
 
        // 解析唯品会
        String vipId = VipShopUtil.parseGoodsIdByUrl(link);
        if (!StringUtil.isNullOrEmpty(vipId)) {
            return new SimpleCommonGoods(vipId, Constant.SOURCE_TYPE_VIP);
        }
        String dyProductId = DYUtil.parseProdectIdFromLink(link);
        if (!StringUtil.isNullOrEmpty(dyProductId)) {
            return new SimpleCommonGoods(dyProductId, Constant.SOURCE_TYPE_DY);
        }
 
        // 解析淘宝
        String auctionId = parseTBAuctionIdFromLink(link);
        if (!StringUtil.isNullOrEmpty(auctionId)) {
            return new SimpleCommonGoods(auctionId, Constant.SOURCE_TYPE_TAOBAO);
        }
 
        return null;
    }
 
    /**
     * 从链接中解析京东商品的SKUID
     *
     * @param link
     * @return
     */
    public String parseJDSkuIdFromLink(String link) {
        // 解析其他商品
        String jdId = JDUtil.getJDGoodsId(link);
 
        // 微信链接
        if (StringUtil.isNullOrEmpty(jdId)) {
            jdId = JDUtil.getJDGoodsIdByWeiXin(link);
        }
 
        // 领券短连接
        if (StringUtil.isNullOrEmpty(jdId) && (link.contains("u.jd.com")||link.contains("//3.cn/"))) {
            jdId = jdGoodsLinkParseManager.parseGoodsIdByJDShortUrl(link);
        }
 
        return jdId;
    }
 
 
    public String parseTBAuctionIdFromLink(String link) {
        TaoBaoGoodsBrief tb = null;
        String auctionId = null;
        if (link.startsWith("https://a.m.taobao.com/i"))// 淘宝账号未登录状态
        {
            link = link.substring("https://a.m.taobao.com/i".length(), link.indexOf(".htm"));
            if (NumberUtil.isNumeric(link)) {
                auctionId = link + "";
            }
        } else if (link.contains("ju.taobao.com") || link.contains(".juhuasuan.com")) {// 聚划算
            int index = link.indexOf("item_id");
            if (index >= 0) {
                link = link.substring(index);
                int last = link.indexOf("&");
                String id = "";
                if (last > 0)
                    id = link.substring(link.indexOf("=") + 1, link.indexOf("&"));
                else {
                    id = link.substring(link.indexOf("=" + 1));
                }
                auctionId = id;
            }
        } else if (link.contains("http://zmnxbc.com")) { // 手机端天猫APP分享
            tb = TaoBaoUtil.parsePhoneShareUrlByTM(link);
            if (tb != null)
                auctionId = tb.getAuctionId() + "";
        } else if (link.contains("h5.m.taobao") || link.contains("detail.m.tmall") || link.contains("item.taobao")
                || link.contains("detail.tmall")) { // 手机页面和电脑页面
            Map<String, String> map = Utils.parseURL(link);
            String id = "";
            id = map.get("id").replace("}", "");
            auctionId = id;
        } else if (link.contains("v.douyin.com")) { // 抖音
            tb = analysisDouYin(link);
            if (tb != null) {
                if (!StringUtil.isNullOrEmpty(tb.getAuctionUrl())) {// 抖音解析到淘宝商品链接
                    CommonGoods goods = parseLink(tb.getAuctionUrl());
                    if (goods != null) {
                        auctionId = goods.getGoodsId() + "";
                    }
                }
            }
        } else {
            tb = TaoBaoUtil.parsePhoneShareUrlByTB(link);
            if (tb != null)
                auctionId = tb.getAuctionId() + "";
        }
 
        return auctionId;
 
    }
 
    private CommonGoods parseTaoBaoToken(String token) throws TaoBaoTokenParseException {
        String auctionId = taoBaoTokenAuctionIdMapManager.getAuctionIdByToken(token);
        if (auctionId != null) {//
            return getTaoBaoGoods(auctionId);
        } else {
            return null;
        }
    }
 
    private CommonGoods getTaoBaoGoods(String auctionId) {
        TaoBaoGoodsBrief goods = TaoBaoUtil.isAlimama(auctionId + "");
        if (goods == null) {
            goods = TaoBaoUtil.getTaoBaoGoodsBriefNotInPub(auctionId);
        }
        if (goods != null) {
            CommonGoods commonGoods = CommonGoodsFactory.create(goods);
            return commonGoods;
        } else
            return null;
    }
 
    /**
     * @Title: analysisDouYin @Description: 抖音解析 @param link @return CommonGoods
     * 返回类型 @throws
     */
    private TaoBaoGoodsBrief analysisDouYin(String link) {
        String location = HttpUtil.getLocation(link);
        if (!StringUtil.isNullOrEmpty(location)) {
            if (location.contains("taobao.com")) { // 淘宝商品
                String realUrl = TaoBaoUtil.getRealUrl(location);
                if (!StringUtil.isNullOrEmpty(realUrl)) {
                    TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
                    goods.setAuctionUrl(realUrl);
                    return goods;
                }
            } else if (location.contains("haohuo.jinritemai.com")) { // 抖音商品
                DouYinGoods goods = DouYinUtil.getGoodsInfo(location);
                JSONObject goodsJSON = new JSONObject();
                goodsJSON.put("title", goods.getName());
                goodsJSON.put("pictUrl", goods.getImg());
 
                TaoBaoGoodsBrief commonGoods = new TaoBaoGoodsBrief();
                commonGoods.setPictUrl(goods.getImg());
                commonGoods.setTitle(goods.getName());
                return commonGoods;
            }
        }
        return null;
    }
 
    private boolean isContainsLinkConvert(String link) {
        if (link.contains(".jd.com"))
            return true;
        else if (link.contains(".taobao.com") || link.contains(".tmall"))
            return true;
        else if (link.contains(".pinduoduo.com") || link.contains(".yangkeduo.com"))
            return true;
        return false;
    }
 
    class SimpleCommonGoods {
        private String goodsId;
        private int goodsType;
 
        public SimpleCommonGoods(String goodsId, int goodsType) {
            this.goodsId = goodsId;
            this.goodsType = goodsType;
        }
 
        public String getGoodsId() {
            return goodsId;
        }
 
        public void setGoodsId(String goodsId) {
            this.goodsId = goodsId;
        }
 
        public int getGoodsType() {
            return goodsType;
        }
 
        public void setGoodsType(int goodsType) {
            this.goodsType = goodsType;
        }
    }
 
 
    public static void main(String[] args) {
//String originText, String platform, String version
 
        new ClipboardAnalysisManager(). parseJDSkuIdFromLink("https://3.cn/1-U6tjhC");
 
    }
}
 
/**
 * 粘贴板解析结果
 *
 * @author Administrator
 */