admin
2021-06-11 bc9d4bf3fddcb3107f8509159a250f7a5a5f8ae5
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
package com.yeshi.fanli.service.manger.goods.pdd;
 
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.exception.pdd.PDDAuthException;
import com.yeshi.fanli.exception.pdd.PDDGoodsException;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
import com.yeshi.fanli.vo.pdd.PDDConvertLinkResultVO;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
@Component
public class PDDConvertLinkManager {
 
    @Resource
    private PIDManager pidManager;
 
    @Resource
    private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
 
 
    /**
     * 商品转链
     *
     * @param goodsId
     * @param system
     * @param customParams
     * @param pidType
     * @return
     * @throws PDDGoodsException
     * @throws PDDAuthException
     */
    public PDDConvertLinkResultVO convertGoods(Long goodsId, SystemEnum system, String customParams, SystemPIDInfo.PidType pidType) throws PDDGoodsException, PDDAuthException {
 
        String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, pidType);
        PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
        if (goods == null) {
            throw new PDDGoodsException(1, "商品已下架");
        }
 
        boolean auth = PinDuoDuoApiUtil.isAuth(pid, customParams);
        PDDConvertLinkResultVO convertUrl = null;
        if (!auth) {
            throw new PDDAuthException(1, "用户未授权");
        } else {
            convertUrl = PinDuoDuoApiUtil.convert(goods.getGoodsSign(), pid + "", customParams, !auth);
        }
        return convertUrl;
    }
 
 
    /**
     * 获取授权链接信息
     *
     * @param system
     * @param customParams
     * @param pidType
     * @return
     */
    public PDDConvertLinkResultVO getAuthLinkInfo(SystemEnum system, String customParams, SystemPIDInfo.PidType pidType) {
        String pid = pidManager.getPidCache(system, Constant.SOURCE_TYPE_PDD, pidType);
        return PinDuoDuoApiUtil.getAuthLink(pid, customParams);
    }
 
 
}