From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java | 1323 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 665 insertions(+), 658 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
index 4b2de4b..1945d8c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/RedisManager.java
@@ -1,658 +1,665 @@
-package com.yeshi.fanli.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import com.yeshi.fanli.entity.SystemEnum;
-import org.springframework.cache.annotation.CacheEvict;
-import org.springframework.stereotype.Component;
-import org.yeshi.utils.JsonUtil;
-
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
-import com.yeshi.fanli.entity.common.ImageInfo;
-import com.yeshi.fanli.entity.jd.JDGoods;
-import com.yeshi.fanli.entity.taobao.PidUser;
-import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.common.entity.taobao.TaoBaoShopInfo;
-import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
-import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
-import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
-import com.yeshi.fanli.util.jd.JDApiUtil;
-import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
-import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
-import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
-
-import net.sf.json.JSONArray;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.params.SetParams;
-
-//鎶㈢孩鍖呴噰鐢ㄧ殑redis
-@Component
-public class RedisManager {
-
-    @Resource
-    private JedisPool jedisPool;
-
-    @Resource
-    private TaoBaoShopService taoBaoShopService;
-
-    @Resource
-    private TaoBaoUnionConfigService taoBaoUnionConfigService;
-
-    @Resource
-    private ConfigService configService;
-
-    public Jedis getJedis() {
-        Jedis jedis = jedisPool.getResource();
-        return jedis;
-    }
-
-    /**
-     * 缂撳瓨瀛楃涓�
-     *
-     * @param key
-     * @param value
-     */
-    private void setString(String key, String value) {
-        Jedis jedis = getJedis();
-        SetParams params = new SetParams().nx().ex(60);
-        jedis.set(key, value, params);
-        try {
-            jedis.set(key, value);
-        } finally {
-            jedis.close();
-        }
-
-    }
-
-    /**
-     * 鍒犻櫎鏌愪釜閿��
-     *
-     * @param key
-     * @param value
-     */
-    private void removeKey(String key) {
-        Jedis jedis = getJedis();
-        try {
-            jedis.del(key);
-        } finally {
-            jedis.close();
-        }
-
-    }
-
-    /**
-     * 缂撳瓨瀛楃涓�
-     *
-     * @param key
-     * @param value
-     * @param seconds -缂撳瓨鏃堕棿锛坰锛�
-     */
-    private void setString(String key, String value, int seconds) {
-        Jedis jedis = getJedis();
-        try {
-            jedis.setex(key, seconds, value);
-        } finally {
-            jedis.close();
-        }
-    }
-
-    private String getString(String key) {
-        Jedis jedis = getJedis();
-        try {
-            return jedis.get(key);
-        } finally {
-            jedis.close();
-        }
-    }
-
-    public void increase(String key) {
-        Jedis jedis = getJedis();
-        try {
-            jedis.incr(key);
-        } finally {
-            jedis.close();
-        }
-    }
-
-    public void expire(String key, int seconds) {
-        Jedis jedis = getJedis();
-        try {
-            jedis.expire(key, seconds);
-        } finally {
-            jedis.close();
-        }
-    }
-
-    public void cacheCommonString(String key, String value, int seconds) {
-        setString(key, value, seconds);
-    }
-
-    public void cacheCommonString(String key, String value) {
-        setString(key, value);
-    }
-
-    public String getCommonString(String key) {
-        return getString(key);
-    }
-
-    public void removeCommonString(String key) {
-        removeKey(key);
-    }
-
-    /**
-     * 涓存椂瀛樺偍娣樺疂鐨勫晢鍝佽鎯�
-     *
-     * @param goods
-     */
-    public void saveTaoBaoGoodsBriefTemp(TaoBaoGoodsBrief goods) {
-        if (goods == null)
-            return;
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, goods.getAuctionId() + "");
-        if (Constant.IS_OUTNET) {
-            // 鏆傚瓨4涓皬鏃剁殑鍒嗕韩
-            cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 60 * 4);
-        }
-    }
-
-    public TaoBaoGoodsBrief getTaoBaoGoodsTemp(Long auctionId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, auctionId + "");
-        String value = getCommonString(key);
-        if (!StringUtil.isNullOrEmpty(value)) {
-            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
-        }
-        return null;
-    }
-
-    /**
-     * 鍒犻櫎缂撳瓨
-     *
-     * @param auctionId
-     */
-    public void deleteTaoBaoGoodsBrief(Long auctionId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
-        if (Constant.IS_OUTNET)
-            removeKey(key);
-    }
-
-    public TaoBaoGoodsBrief getTaoBaoGoodsBrief(long auctionId) throws TaobaoGoodsDownException {
-        long startTime = System.currentTimeMillis();
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
-        String value = "";
-        if (Constant.IS_OUTNET)
-            value = getCommonString(key);
-
-        if (StringUtil.isNullOrEmpty(value)) {
-            TaoBaoGoodsBrief goods = null;
-
-            goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
-
-            if (goods != null)
-                // 缂撳瓨20鍒嗛挓
-                if (Constant.IS_OUTNET)
-                    cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 20);
-            LogHelper.test(auctionId + "-鑾峰彇鍟嗗搧璇︽儏鑰楁椂:" + (System.currentTimeMillis() - startTime));
-            return goods;
-        } else {// 鐩存帴鍙栫紦瀛�
-            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
-        }
-    }
-
-    public List<ImageInfo> getTaoBaoGoodsDetailImgs(long auctionId, SystemEnum system) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsDetailimgs, auctionId + "");
-        String value = "";
-        if (Constant.IS_OUTNET)
-            value = getCommonString(key);
-
-        if (StringUtil.isNullOrEmpty(value)) {
-            List<ImageInfo> list = null;
-            try {
-                list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId, configService.getTaoBaoProxyIP(system));
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            if (list == null || list.size() == 0) {
-                list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
-            }
-            if (list != null && list.size() > 0)
-                // 缂撳瓨1澶�
-                if (Constant.IS_OUTNET)
-                    cacheCommonString(key, JsonUtil.getSimpleGson().toJson(list), 60 * 60 * 24);
-            return list;
-        } else {// 鐩存帴鍙栫紦瀛�
-            List<ImageInfo> imgList = new Gson().fromJson(value, new TypeToken<List<ImageInfo>>() {
-            }.getType());
-            return imgList;
-        }
-    }
-
-    public String getXCXCouponToken(TaoBaoGoodsBrief tb) {
-        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCoupleXCX, tb.getAuctionId() + "");
-        String value = "";
-        if (Constant.IS_OUTNET)
-            value = getCommonString(key);
-        if (StringUtil.isNullOrEmpty(value)) {
-            value = TaoKeApiUtil.getTKToken(tb.getPictUrl(), tb.getTitle(), TaoBaoCouponUtil
-                    .getCoupleUrl(tb.getCouponActivityId(), configList.get(0).getDefaultPid(), tb.getAuctionId() + ""));
-            if (value != null)
-                // 缂撳瓨20鍒嗛挓
-                if (Constant.IS_OUTNET)
-                    cacheCommonString(key, value, 60 * 20);
-            return value;
-        } else {// 鐩存帴鍙栫紦瀛�
-            return value;
-        }
-    }
-
-    /**
-     * IP璁块棶棰戠巼闄愬埗 閫傜敤浜� 灏忕▼搴忥紝H5锛學EB 鍚屼竴IP锛�5s鍐呴檺鍒惰姹�100娆�
-     *
-     * @param ip
-     */
-    public boolean ipFrequencyLimit(String ip, String apiName) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, ip + "-" + StringUtil.Md5(apiName));
-        Jedis jedis = getJedis();
-        try {
-            long count = jedis.incr(key);
-            if (count == 1)
-                jedis.expire(key, 5);
-            if (count >= 10)
-                return true;
-            else
-                return false;
-        } finally {
-            jedis.close();
-        }
-    }
-
-    public boolean frequencyLimit(String key, int timeS, int num) {
-        key = RedisKeyEnum.getRedisKey(RedisKeyEnum.frequencyLimit, key);
-        Jedis jedis = getJedis();
-        try {
-            long count = jedis.incr(key);
-            if (count == 1)
-                jedis.expire(key, timeS);
-            if (count >= num)
-                return true;
-            else
-                return false;
-        } finally {
-            jedis.close();
-        }
-    }
-
-    /**
-     * 鑾峰彇娣樺疂鍥剧墖
-     *
-     * @param auctionId
-     * @return
-     */
-    public List<String> getTBImg(Long auctionId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoImgs, auctionId + "");
-        String value = "";
-        if (Constant.IS_OUTNET)
-            value = getCommonString(key);
-        if (StringUtil.isNullOrEmpty(value)) {
-            List<String> list = TaoBaoUtil.getTbImg(auctionId + "");
-            if (Constant.IS_OUTNET && list != null && list.size() > 0) {
-                value = new Gson().toJson(list);
-                cacheCommonString(key, value, 60 * 60 * 2);
-            }
-            return list;
-        } else {
-            JSONArray array = JSONArray.fromObject(value);
-            List<String> list = new ArrayList<>();
-            for (int i = 0; i < array.size(); i++) {
-                list.add(array.getString(i));
-            }
-            return list;
-        }
-    }
-
-    /**
-     * 鑾峰彇娣樺疂搴楅摵淇℃伅
-     *
-     * @param shopTitle
-     * @param sellerId
-     * @return
-     */
-    public TaoBaoShopInfo getTBShopInfo(String shopTitle, Long sellerId, Long auctionId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoShop, sellerId + "");
-        String value = "";
-        if (Constant.IS_OUTNET)
-            value = getCommonString(key);
-
-        if (StringUtil.isNullOrEmpty(value)) {
-            TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
-            goods.setShopTitle(shopTitle);
-            goods.setSellerId(sellerId);
-            goods.setAuctionId(auctionId);
-            TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods);
-
-            if (info != null) {
-                String shopUrl = info.getShopUrl();
-                if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
-                    shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
-                    info.setShopUrl(shopUrl);
-                }
-            }
-
-            if (Constant.IS_OUTNET && info != null) {
-                value = new Gson().toJson(info);
-                cacheCommonString(key, value, 60 * 60 * 2);
-            }
-
-            return info;
-        } else {
-            TaoBaoShopInfo info = new Gson().fromJson(value, TaoBaoShopInfo.class);
-
-            String shopUrl = info.getShopUrl();
-            if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
-                shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
-                info.setShopUrl(shopUrl);
-            }
-
-            return info;
-        }
-    }
-
-    /**
-     * 鏄惁闄愬埗鍙戦�佺煭淇�
-     *
-     * @param phone
-     * @param type
-     * @return
-     */
-    public boolean isSmsFrequencyLimit(String phone, int type) {
-        if (!Constant.IS_OUTNET)
-            return false;
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
-        String value = getCommonString(key);
-        if (StringUtil.isNullOrEmpty(value))
-            return false;
-        else
-            return true;
-    }
-
-    /**
-     * 璁剧疆鐭俊60s鍊掕鏃�
-     *
-     * @param phone
-     * @param type
-     */
-    public void sendSms(String phone, int type) {
-        if (!Constant.IS_OUTNET)
-            return;
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
-        setString(key, "1", 10);
-    }
-
-    public void clearSMSFrequencyLimit(String phone, int type) {
-        if (!Constant.IS_OUTNET)
-            return;
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
-        removeKey(key);
-    }
-
-    /**
-     * 淇濆瓨楠岃瘉鐮�
-     *
-     * @param phone
-     * @param type
-     * @param code
-     */
-
-    public void saveSMSVCode(String phone, int type, String code) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
-        // 淇濆瓨2鍒嗛挓
-        setString(key, code, 120);
-    }
-
-    /**
-     * @param phone
-     * @param type
-     * @return
-     */
-    public String getSMSVCode(String phone, int type) {
-        // if (!Constant.IS_OUTNET)
-        // return "";
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
-        // 淇濆瓨2鍒嗛挓
-        return getString(key);
-    }
-
-    /**
-     * 娓呴櫎鎺夐獙璇佺爜
-     *
-     * @param phone
-     * @param type
-     * @param code
-     */
-    public void clearSMSVCode(String phone, int type) {
-        // if (!Constant.IS_OUTNET)
-        // return;
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
-        removeKey(key);
-    }
-
-    /**
-     * 淇濆瓨缁戝畾鏀粯瀹濈煭淇¢獙璇佺爜鐨勬纭��
-     */
-    public void saveBindAlipayAccountSMSState(String phone) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "");
-        // 楠岃瘉鍚庡崄鍒嗛挓鏈夋晥
-        setString(key, "1", 10 * 60);
-    }
-
-    /**
-     * 缁戝畾鏀粯瀹濆彂閫佺殑鐭俊鏄惁鍦ㄦ湁鏁堟湡鍐�
-     *
-     * @param phone
-     * @return
-     */
-    public boolean isBindAlipayAccountSMSStateValid(String phone) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "");
-        return !StringUtil.isNullOrEmpty(getString(key));
-    }
-
-    /**
-     * 缂撳瓨鐭繛鎺�1鍒嗛挓
-     *
-     * @param uid
-     * @param shortlink
-     */
-    public void setInviteShortLink(long uid, String shortlink) {
-        String value = "";
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "");
-        if (Constant.IS_OUTNET) {
-
-            value = getCommonString(key);
-
-            if (StringUtil.isNullOrEmpty(value)) {
-                cacheCommonString(key, shortlink, 60);
-            }
-        }
-
-    }
-
-    /**
-     * 鑾峰彇鐢ㄦ埛鐭繛鎺�
-     *
-     * @param uid
-     * @return
-     */
-    public String getInviteShortLink(long uid) {
-        String value = "";
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "");
-        if (Constant.IS_OUTNET)
-            value = getCommonString(key);
-
-        return value;
-    }
-
-    /**
-     * 淇濆瓨娣樺彛浠�
-     *
-     * @param auctionId
-     * @param token
-     */
-    public void saveCommonTaoToken(Long auctionId, String token) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "");
-        if (Constant.IS_OUTNET) {
-            if (!StringUtil.isNullOrEmpty(token)) {
-                // 鍙d护缂撳瓨10澶�
-                cacheCommonString(key, token, 60 * 60 * 24 * 10);
-            }
-        }
-    }
-
-    /**
-     * 鑾峰彇鐢ㄦ埛鐭繛鎺�
-     *
-     * @param uid
-     * @return
-     */
-    public String getCommonTaoToken(Long auctionId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "");
-        if (Constant.IS_OUTNET) {
-            return getCommonString(key);
-        }
-        return null;
-    }
-
-    /**
-     * 淇濆瓨娣樼ぜ閲戠殑鍙d护
-     *
-     * @param url
-     * @param token
-     */
-    public void saveTLJToken(String url, String token) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
-        if (Constant.IS_OUTNET) {
-            if (!StringUtil.isNullOrEmpty(token)) {
-                // 鍙d护缂撳瓨10澶�
-                cacheCommonString(key, token, 60 * 60 * 24 * 10);
-            }
-        }
-    }
-
-    /**
-     * 鑾峰彇娣樼ぜ閲戝彛浠�
-     *
-     * @param url
-     * @return
-     */
-    public String getTLJToken(String url) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
-        if (Constant.IS_OUTNET) {
-            return getCommonString(key);
-        }
-        return null;
-    }
-
-    /**
-     * 淇濆瓨瀵硅薄
-     *
-     * @param T
-     * @param key
-     * @param seconds
-     */
-    public void saveObj(Object clazz, String key, Integer seconds) {
-        if (clazz == null)
-            return;
-        String value = new Gson().toJson(clazz);
-        if (seconds != null)
-            cacheCommonString(key, value, seconds);
-        else
-            cacheCommonString(key, value);
-    }
-
-    /**
-     * 淇濆瓨鍒楄〃
-     *
-     * @param clazzList
-     * @param key
-     * @param seconds
-     */
-    public <T> T saveObjList(List<T> clazzList, String key, Integer seconds) {
-        if (clazzList == null)
-            return null;
-        String value = new Gson().toJson(clazzList);
-        if (seconds != null)
-            cacheCommonString(key, value, seconds);
-        else
-            cacheCommonString(key, value);
-        return null;
-    }
-
-    /**
-     * 鑾峰彇瀵硅薄
-     *
-     * @param clazz
-     * @param key
-     * @return
-     */
-    public Class<?> getObj(Class<?> clazz, String key) {
-        String value = getCommonString(key);
-        return (Class<?>) new Gson().fromJson(value, clazz);
-    }
-
-    /**
-     * 鑾峰彇鍒楄〃
-     *
-     * @param clazz
-     * @param key
-     * @return
-     */
-    public <T> List<T> getObjList(Class<T> clazz, String key) {
-        String value = getCommonString(key);
-        return JsonUtil.jsonToList(value, clazz);
-    }
-
-    public JDGoods getJDGoods(long goodsId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.jingDongGoods, goodsId + "");
-        String value = getCommonString(key);
-        if (StringUtil.isNullOrEmpty(value)) {
-            JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
-            if (jdGoods == null) {
-                jdGoods = JDApiUtil.getGoodsDetail(goodsId);
-            }
-
-            // 缂撳瓨20鍒嗛挓
-            if (jdGoods != null)
-                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(jdGoods), 60 * 20);
-
-            return jdGoods;
-        } else {// 鐩存帴鍙栫紦瀛�
-            return JsonUtil.getSimpleGson().fromJson(value, JDGoods.class);
-        }
-    }
-
-    public PDDGoodsDetail getPDDGoodsDetail(long goodsId) {
-        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.pinDuoDuoGoods, goodsId + "");
-
-        String value = getCommonString(key);
-        if (StringUtil.isNullOrEmpty(value)) {
-            PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(goodsId);
-
-            // 缂撳瓨20鍒嗛挓
-            if (pddGoods != null)
-                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(pddGoods), 60 * 20);
-
-            return pddGoods;
-        } else {// 鐩存帴鍙栫紦瀛�
-            return JsonUtil.getSimpleGson().fromJson(value, PDDGoodsDetail.class);
-        }
-    }
-
-}
+package com.yeshi.fanli.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+import org.yeshi.utils.JsonUtil;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
+import com.yeshi.fanli.entity.common.ImageInfo;
+import com.yeshi.fanli.entity.jd.JDGoods;
+import com.yeshi.fanli.entity.taobao.PidUser;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.common.entity.taobao.TaoBaoShopInfo;
+import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
+import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.config.ConfigService;
+import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
+import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
+import com.yeshi.fanli.util.jd.JDApiUtil;
+import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
+import com.yeshi.fanli.util.taobao.TaoBaoCouponUtil;
+import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
+
+import net.sf.json.JSONArray;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.params.SetParams;
+
+//鎶㈢孩鍖呴噰鐢ㄧ殑redis
+@Component
+public class RedisManager {
+
+    @Resource
+    private JedisPool jedisPool;
+
+    @Resource
+    private TaoBaoShopService taoBaoShopService;
+
+    @Resource
+    private TaoBaoUnionConfigService taoBaoUnionConfigService;
+
+    @Resource
+    private ConfigService configService;
+
+    public Jedis getJedis() {
+        Jedis jedis = jedisPool.getResource();
+        return jedis;
+    }
+
+    /**
+     * 缂撳瓨瀛楃涓�
+     *
+     * @param key
+     * @param value
+     */
+    private void setString(String key, String value) {
+        Jedis jedis = getJedis();
+        SetParams params = new SetParams().nx().ex(60);
+        jedis.set(key, value, params);
+        try {
+            jedis.set(key, value);
+        } finally {
+            jedis.close();
+        }
+
+    }
+
+    /**
+     * 鍒犻櫎鏌愪釜閿��
+     *
+     * @param key
+     */
+    public void removeKey(String key) {
+        Jedis jedis = getJedis();
+        try {
+            jedis.del(key);
+        } finally {
+            jedis.close();
+        }
+
+    }
+
+    /**
+     * 缂撳瓨瀛楃涓�
+     *
+     * @param key
+     * @param value
+     * @param seconds -缂撳瓨鏃堕棿锛坰锛�
+     */
+    private void setString(String key, String value, int seconds) {
+        Jedis jedis = getJedis();
+        try {
+            jedis.setex(key, seconds, value);
+        } finally {
+            jedis.close();
+        }
+    }
+
+    private String getString(String key) {
+        Jedis jedis = getJedis();
+        try {
+            return jedis.get(key);
+        } finally {
+            jedis.close();
+        }
+    }
+
+    public void increase(String key) {
+        Jedis jedis = getJedis();
+        try {
+            jedis.incr(key);
+        } finally {
+            jedis.close();
+        }
+    }
+
+    public void expire(String key, int seconds) {
+        Jedis jedis = getJedis();
+        try {
+            jedis.expire(key, seconds);
+        } finally {
+            jedis.close();
+        }
+    }
+
+    public boolean hasKey(String key) {
+        Jedis jedis = getJedis();
+        try {
+            return jedis.exists(key);
+        } finally {
+            jedis.close();
+        }
+    }
+
+    public void cacheCommonString(String key, String value, int seconds) {
+        setString(key, value, seconds);
+    }
+
+    public void cacheCommonString(String key, String value) {
+        setString(key, value);
+    }
+
+    public String getCommonString(String key) {
+        return getString(key);
+    }
+
+    public void removeCommonString(String key) {
+        removeKey(key);
+    }
+
+    /**
+     * 涓存椂瀛樺偍娣樺疂鐨勫晢鍝佽鎯�
+     *
+     * @param goods
+     */
+    public void saveTaoBaoGoodsBriefTemp(TaoBaoGoodsBrief goods) {
+        if (goods == null)
+            return;
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, goods.getAuctionId() + "");
+        if (Constant.IS_OUTNET) {
+            // 鏆傚瓨4涓皬鏃剁殑鍒嗕韩
+            cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 60 * 4);
+        }
+    }
+
+    public TaoBaoGoodsBrief getTaoBaoGoodsTemp(String auctionId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsTemp, auctionId + "");
+        String value = getCommonString(key);
+        if (!StringUtil.isNullOrEmpty(value)) {
+            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
+        }
+        return null;
+    }
+
+    /**
+     * 鍒犻櫎缂撳瓨
+     *
+     * @param auctionId
+     */
+    public void deleteTaoBaoGoodsBrief(String auctionId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
+        if (Constant.IS_OUTNET)
+            removeKey(key);
+    }
+
+    public TaoBaoGoodsBrief getTaoBaoGoodsBrief(String auctionId) throws TaobaoGoodsDownException {
+        long startTime = System.currentTimeMillis();
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoods, auctionId + "");
+        String value = "";
+        if (Constant.IS_OUTNET)
+            value = getCommonString(key);
+
+        if (StringUtil.isNullOrEmpty(value)) {
+            TaoBaoGoodsBrief goods = null;
+
+            goods = TaoKeApiUtil.searchGoodsDetail(auctionId);
+
+            if (goods != null)
+                // 缂撳瓨20鍒嗛挓
+                if (Constant.IS_OUTNET)
+                    cacheCommonString(key, JsonUtil.getSimpleGson().toJson(goods), 60 * 20);
+            LogHelper.test(auctionId + "-鑾峰彇鍟嗗搧璇︽儏鑰楁椂:" + (System.currentTimeMillis() - startTime));
+            return goods;
+        } else {// 鐩存帴鍙栫紦瀛�
+            return JsonUtil.getSimpleGson().fromJson(value, TaoBaoGoodsBrief.class);
+        }
+    }
+
+    public List<ImageInfo> getTaoBaoGoodsDetailImgs(String auctionId, SystemEnum system) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoGoodsDetailimgs, auctionId + "");
+        String value = "";
+        if (Constant.IS_OUTNET)
+            value = getCommonString(key);
+
+        if (StringUtil.isNullOrEmpty(value)) {
+            List<ImageInfo> list = null;
+            try {
+                list = TaoBaoUtil.getTBDetailImageWithSizev2(auctionId, configService.getTaoBaoProxyIP(system));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            if (list == null || list.size() == 0) {
+                list = TaoBaoUtil.getTBDetailImageWithSize(auctionId);
+            }
+            if (list != null && list.size() > 0)
+                // 缂撳瓨1澶�
+                if (Constant.IS_OUTNET)
+                    cacheCommonString(key, JsonUtil.getSimpleGson().toJson(list), 60 * 60 * 24);
+            return list;
+        } else {// 鐩存帴鍙栫紦瀛�
+            List<ImageInfo> imgList = new Gson().fromJson(value, new TypeToken<List<ImageInfo>>() {
+            }.getType());
+            return imgList;
+        }
+    }
+
+    public String getXCXCouponToken(TaoBaoGoodsBrief tb) {
+        List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCoupleXCX, tb.getAuctionId() + "");
+        String value = "";
+        if (Constant.IS_OUTNET)
+            value = getCommonString(key);
+        if (StringUtil.isNullOrEmpty(value)) {
+            value = TaoKeApiUtil.getTKToken(tb.getPictUrl(), tb.getTitle(), TaoBaoCouponUtil
+                    .getCoupleUrl(tb.getCouponActivityId(), configList.get(0).getDefaultPid(), tb.getAuctionId() + ""));
+            if (value != null)
+                // 缂撳瓨20鍒嗛挓
+                if (Constant.IS_OUTNET)
+                    cacheCommonString(key, value, 60 * 20);
+            return value;
+        } else {// 鐩存帴鍙栫紦瀛�
+            return value;
+        }
+    }
+
+    /**
+     * IP璁块棶棰戠巼闄愬埗 閫傜敤浜� 灏忕▼搴忥紝H5锛學EB 鍚屼竴IP锛�5s鍐呴檺鍒惰姹�100娆�
+     *
+     * @param ip
+     */
+    public boolean ipFrequencyLimit(String ip, String apiName) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, ip + "-" + StringUtil.Md5(apiName));
+        Jedis jedis = getJedis();
+        try {
+            long count = jedis.incr(key);
+            if (count == 1)
+                jedis.expire(key, 5);
+            if (count >= 10)
+                return true;
+            else
+                return false;
+        } finally {
+            jedis.close();
+        }
+    }
+
+    public boolean frequencyLimit(String key, int timeS, int num) {
+        key = RedisKeyEnum.getRedisKey(RedisKeyEnum.frequencyLimit, key);
+        Jedis jedis = getJedis();
+        try {
+            long count = jedis.incr(key);
+            if (count == 1)
+                jedis.expire(key, timeS);
+            if (count >= num)
+                return true;
+            else
+                return false;
+        } finally {
+            jedis.close();
+        }
+    }
+
+    /**
+     * 鑾峰彇娣樺疂鍥剧墖
+     *
+     * @param auctionId
+     * @return
+     */
+    public List<String> getTBImg(String auctionId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoImgs, auctionId + "");
+        String value = "";
+        if (Constant.IS_OUTNET)
+            value = getCommonString(key);
+        if (StringUtil.isNullOrEmpty(value)) {
+            List<String> list = TaoBaoUtil.getTbImg(auctionId + "");
+            if (Constant.IS_OUTNET && list != null && list.size() > 0) {
+                value = new Gson().toJson(list);
+                cacheCommonString(key, value, 60 * 60 * 2);
+            }
+            return list;
+        } else {
+            JSONArray array = JSONArray.fromObject(value);
+            List<String> list = new ArrayList<>();
+            for (int i = 0; i < array.size(); i++) {
+                list.add(array.getString(i));
+            }
+            return list;
+        }
+    }
+
+    /**
+     * 鑾峰彇娣樺疂搴楅摵淇℃伅
+     *
+     * @param shopTitle
+     * @param sellerId
+     * @return
+     */
+    public TaoBaoShopInfo getTBShopInfo(String shopTitle, Long sellerId, String auctionId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoShop, sellerId + "");
+        String value = "";
+        if (Constant.IS_OUTNET)
+            value = getCommonString(key);
+
+        if (StringUtil.isNullOrEmpty(value)) {
+            TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
+            goods.setShopTitle(shopTitle);
+            goods.setSellerId(sellerId);
+            goods.setAuctionId(auctionId);
+            TaoBaoShopInfo info = taoBaoShopService.getTaoBaoShopInfo(goods);
+
+            if (info != null) {
+                String shopUrl = info.getShopUrl();
+                if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
+                    shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
+                    info.setShopUrl(shopUrl);
+                }
+            }
+
+            if (Constant.IS_OUTNET && info != null) {
+                value = new Gson().toJson(info);
+                cacheCommonString(key, value, 60 * 60 * 2);
+            }
+
+            return info;
+        } else {
+            TaoBaoShopInfo info = new Gson().fromJson(value, TaoBaoShopInfo.class);
+
+            String shopUrl = info.getShopUrl();
+            if (shopUrl != null && shopUrl.contains("tmall://page.tm/shop")) {
+                shopUrl = "http://store.taobao.com/shop/view_shop.htm?user_number_id=" + sellerId;
+                info.setShopUrl(shopUrl);
+            }
+
+            return info;
+        }
+    }
+
+    /**
+     * 鏄惁闄愬埗鍙戦�佺煭淇�
+     *
+     * @param phone
+     * @param type
+     * @return
+     */
+    public boolean isSmsFrequencyLimit(String phone, int type) {
+        if (!Constant.IS_OUTNET)
+            return false;
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
+        String value = getCommonString(key);
+        if (StringUtil.isNullOrEmpty(value))
+            return false;
+        else
+            return true;
+    }
+
+    /**
+     * 璁剧疆鐭俊60s鍊掕鏃�
+     *
+     * @param phone
+     * @param type
+     */
+    public void sendSms(String phone, int type) {
+        if (!Constant.IS_OUTNET)
+            return;
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
+        setString(key, "1", 10);
+    }
+
+    public void clearSMSFrequencyLimit(String phone, int type) {
+        if (!Constant.IS_OUTNET)
+            return;
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMS, phone + "-" + type);
+        removeKey(key);
+    }
+
+    /**
+     * 淇濆瓨楠岃瘉鐮�
+     *
+     * @param phone
+     * @param type
+     * @param code
+     */
+
+    public void saveSMSVCode(String phone, int type, String code) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
+        // 淇濆瓨2鍒嗛挓
+        setString(key, code, 120);
+    }
+
+    /**
+     * @param phone
+     * @param type
+     * @return
+     */
+    public String getSMSVCode(String phone, int type) {
+        // if (!Constant.IS_OUTNET)
+        // return "";
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
+        // 淇濆瓨2鍒嗛挓
+        return getString(key);
+    }
+
+    /**
+     * 娓呴櫎鎺夐獙璇佺爜
+     *
+     * @param phone
+     * @param type
+     */
+    public void clearSMSVCode(String phone, int type) {
+        // if (!Constant.IS_OUTNET)
+        // return;
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSVCode, phone + "-" + type);
+        removeKey(key);
+    }
+
+    /**
+     * 淇濆瓨缁戝畾鏀粯瀹濈煭淇¢獙璇佺爜鐨勬纭��
+     */
+    public void saveBindAlipayAccountSMSState(String phone) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "");
+        // 楠岃瘉鍚庡崄鍒嗛挓鏈夋晥
+        setString(key, "1", 10 * 60);
+    }
+
+    /**
+     * 缁戝畾鏀粯瀹濆彂閫佺殑鐭俊鏄惁鍦ㄦ湁鏁堟湡鍐�
+     *
+     * @param phone
+     * @return
+     */
+    public boolean isBindAlipayAccountSMSStateValid(String phone) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSStateAlipay, phone + "");
+        return !StringUtil.isNullOrEmpty(getString(key));
+    }
+
+    /**
+     * 缂撳瓨鐭繛鎺�1鍒嗛挓
+     *
+     * @param uid
+     * @param shortlink
+     */
+    public void setInviteShortLink(long uid, String shortlink) {
+        String value = "";
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "");
+        if (Constant.IS_OUTNET) {
+
+            value = getCommonString(key);
+
+            if (StringUtil.isNullOrEmpty(value)) {
+                cacheCommonString(key, shortlink, 60);
+            }
+        }
+
+    }
+
+    /**
+     * 鑾峰彇鐢ㄦ埛鐭繛鎺�
+     *
+     * @param uid
+     * @return
+     */
+    public String getInviteShortLink(long uid) {
+        String value = "";
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.inviteShortLink, uid + "");
+        if (Constant.IS_OUTNET)
+            value = getCommonString(key);
+
+        return value;
+    }
+
+    /**
+     * 淇濆瓨娣樺彛浠�
+     *
+     * @param auctionId
+     * @param token
+     */
+    public void saveCommonTaoToken(String auctionId, String token) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "");
+        if (Constant.IS_OUTNET) {
+            if (!StringUtil.isNullOrEmpty(token)) {
+                // 鍙d护缂撳瓨10澶�
+                cacheCommonString(key, token, 60 * 60 * 24 * 10);
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇鐢ㄦ埛鐭繛鎺�
+     *
+     * @param auctionId
+     * @return
+     */
+    public String getCommonTaoToken(String auctionId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenCommon, auctionId + "");
+        if (Constant.IS_OUTNET) {
+            return getCommonString(key);
+        }
+        return null;
+    }
+
+    /**
+     * 淇濆瓨娣樼ぜ閲戠殑鍙d护
+     *
+     * @param url
+     * @param token
+     */
+    public void saveTLJToken(String url, String token) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
+        if (Constant.IS_OUTNET) {
+            if (!StringUtil.isNullOrEmpty(token)) {
+                // 鍙d护缂撳瓨10澶�
+                cacheCommonString(key, token, 60 * 60 * 24 * 10);
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇娣樼ぜ閲戝彛浠�
+     *
+     * @param url
+     * @return
+     */
+    public String getTLJToken(String url) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoTokenTLJ, StringUtil.Md5(url));
+        if (Constant.IS_OUTNET) {
+            return getCommonString(key);
+        }
+        return null;
+    }
+
+    /**
+     * 淇濆瓨瀵硅薄
+     *
+     * @param clazz
+     * @param key
+     * @param seconds
+     */
+    public void saveObj(Object clazz, String key, Integer seconds) {
+        if (clazz == null)
+            return;
+        String value = new Gson().toJson(clazz);
+        if (seconds != null)
+            cacheCommonString(key, value, seconds);
+        else
+            cacheCommonString(key, value);
+    }
+
+    /**
+     * 淇濆瓨鍒楄〃
+     *
+     * @param clazzList
+     * @param key
+     * @param seconds
+     */
+    public <T> T saveObjList(List<T> clazzList, String key, Integer seconds) {
+        if (clazzList == null)
+            return null;
+        String value = new Gson().toJson(clazzList);
+        if (seconds != null)
+            cacheCommonString(key, value, seconds);
+        else
+            cacheCommonString(key, value);
+        return null;
+    }
+
+    /**
+     * 鑾峰彇瀵硅薄
+     *
+     * @param clazz
+     * @param key
+     * @return
+     */
+    public Object getObj(Class<?> clazz, String key) {
+        String value = getCommonString(key);
+        return new Gson().fromJson(value, clazz);
+    }
+
+    /**
+     * 鑾峰彇鍒楄〃
+     *
+     * @param clazz
+     * @param key
+     * @return
+     */
+    public <T> List<T> getObjList(Class<T> clazz, String key) {
+        String value = getCommonString(key);
+        return JsonUtil.jsonToList(value, clazz);
+    }
+
+    public JDGoods getJDGoods(String goodsId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.jingDongGoods, goodsId + "");
+        String value = getCommonString(key);
+        if (StringUtil.isNullOrEmpty(value)) {
+            JDGoods jdGoods = JDApiUtil.queryGoodsDetail(goodsId);
+            if (jdGoods == null) {
+                jdGoods = JDApiUtil.getGoodsDetail(goodsId);
+            }
+
+            // 缂撳瓨20鍒嗛挓
+            if (jdGoods != null)
+                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(jdGoods), 60 * 20);
+
+            return jdGoods;
+        } else {// 鐩存帴鍙栫紦瀛�
+            return JsonUtil.getSimpleGson().fromJson(value, JDGoods.class);
+        }
+    }
+
+    public PDDGoodsDetail getPDDGoodsDetail(String goodsId) {
+        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.pinDuoDuoGoods, goodsId + "");
+
+        String value = getCommonString(key);
+        if (StringUtil.isNullOrEmpty(value)) {
+            PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(goodsId);
+
+            // 缂撳瓨20鍒嗛挓
+            if (pddGoods != null)
+                cacheCommonString(key, JsonUtil.getSimpleGson().toJson(pddGoods), 60 * 20);
+
+            return pddGoods;
+        } else {// 鐩存帴鍙栫紦瀛�
+            return JsonUtil.getSimpleGson().fromJson(value, PDDGoodsDetail.class);
+        }
+    }
+
+}

--
Gitblit v1.8.0