fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
utils/src/main/java/org/yeshi/utils/HttpUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/RecommendController.java
@@ -80,8 +80,9 @@ import com.yeshi.fanli.service.inter.goods.SuperRecommendBannerV2Service; import com.yeshi.fanli.service.inter.goods.SuperRecommendSpecialService; import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.homemodule.DeviceSexService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.homemodule.DeviceSexService; import com.yeshi.fanli.service.inter.goods.recommend.RecommendGoodsDeleteHistoryService; import com.yeshi.fanli.service.inter.homemodule.SpecialService; import com.yeshi.fanli.service.inter.homemodule.SuperSpecialService; import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; @@ -257,6 +258,9 @@ private DeviceSexService deviceSexService; @Resource private RecommendGoodsDeleteHistoryService recommendGoodsDeleteHistoryService; @RequestMapping(value = "getHonestList") public void getHonestList(AcceptData acceptData, PrintWriter out) { @@ -1339,18 +1343,22 @@ // 筛选 List<TaoBaoGoodsBriefExtra> goodsList = new ArrayList<>(); List<TaoBaoGoodsBrief> gList = recommendGoodsDeleteHistoryService .filterGoods(acceptData.getDevice(), result.getTaoBaoGoodsBriefs()); // 设备推荐 for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) { if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && goods.getCouponAmount() != null && goods.getCouponAmount().compareTo(new BigDecimal("5")) >= 0 && goods.getBiz30day() > 1000 && !StringUtil.isNullOrEmpty(goods.getPictUrlWhite())) { if (gList != null) for (TaoBaoGoodsBrief goods : gList) { if (!StringUtil.isNullOrEmpty(goods.getCouponInfo()) && goods.getCouponAmount() != null && goods.getCouponAmount().compareTo(new BigDecimal("5")) >= 0 && goods.getBiz30day() > 1000 && !StringUtil.isNullOrEmpty(goods.getPictUrlWhite())) { TaoBaoGoodsBriefExtra extra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goods, proportion.toString(), ""); extra.setRecommend(true); goodsList.add(extra); TaoBaoGoodsBriefExtra extra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goods, proportion.toString(), ""); extra.setRecommend(true); goodsList.add(extra); } } } try { monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0, (int) (java.lang.System.currentTimeMillis() - startTime), "推荐数量:" + goodsList.size())); @@ -2051,7 +2059,9 @@ redisManager.saveCommonTaoToken(tb.getAuctionId(), token); } } tb.setCouponLinkTaoToken(token); // 测试 if (!Constant.IS_TEST) tb.setCouponLinkTaoToken(token); // 服务端转链 // if (convertInServer && @@ -2067,7 +2077,10 @@ couponInfo.put("couponTime", "使用期限:" + tb.getCouponEffectiveStartTime().replace("-", ".") + "-" + tb.getCouponEffectiveEndTime().replace("-", ".")); // 券的口令 couponInfo.put("couponToken", token); // 测试 if (!Constant.IS_TEST) couponInfo.put("couponToken", token); goodsJson.put("couponInfo", couponInfo); if (tb.getBiz30day() >= 1000) { @@ -2354,7 +2367,7 @@ e1.printStackTrace(); } if (goodsList != null) if (goodsList != null && goodsList.size() > 0) goodsList.parallelStream().forEach(goods -> { // 获取详情 utils/src/main/java/org/yeshi/utils/HttpUtil.java
@@ -37,6 +37,9 @@ import org.apache.http.util.EntityUtils; import org.yeshi.utils.entity.ProxyIP; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class HttpUtil { public static String getHost(String host) { @@ -49,19 +52,59 @@ return ""; } public static String getShortLink(String url) { public static String getShortLink(String url) { String shortLink = getShortLink2(url); if (StringUtil.isNullOrEmpty(shortLink)) shortLink = getShortLink3(url); if (StringUtil.isNullOrEmpty(shortLink)) shortLink = getShortLink1(url); return shortLink; } private static String getShortLink1(String url) { try { String totalUrl = String.format("http://api.suolink.cn/api.php?url=%s", URLEncoder.encode(url)); String result = get(totalUrl, null); if (!StringUtil.isNullOrEmpty(result) && result.startsWith("http")) return result.trim(); // JSONArray rtesultArray = JSONArray.fromObject(result); // if (rtesultArray.size() > 0) { // return rtesultArray.optJSONObject(0).optString("url_short"); // } } catch (Exception e) { return url; } return null; } private static String getShortLink2(String url) { try { String totalUrl = String.format( "https://api.weibo.com/2/short_url/shorten.json?source=3403499693&url_long=%s", URLEncoder.encode(url)); String result = get(totalUrl, null); JSONObject data = JSONObject.fromObject(result); JSONArray array = data.optJSONArray("urls"); data = array.optJSONObject(0); String shortUrl = data.optString("url_short"); if (!StringUtil.isNullOrEmpty(shortUrl)) return shortUrl; } catch (Exception e) { e.printStackTrace(); } return null; } private static String getShortLink3(String url) { try { String totalUrl = String.format( "https://api.weibo.com/2/short_url/shorten.json?source=2963429064&url_long=%s", URLEncoder.encode(url)); String result = get(totalUrl, null); JSONObject data = JSONObject.fromObject(result); JSONArray array = data.optJSONArray("urls"); data = array.optJSONObject(0); String shortUrl = data.optString("url_short"); if (!StringUtil.isNullOrEmpty(shortUrl)) return shortUrl; } catch (Exception e) { e.printStackTrace(); } return null; } @@ -354,7 +397,7 @@ public static String post(String url, Map<String, String> map, Map<String, String> headers) { HttpClient client = new HttpClient(); // client.getHostConfiguration().setProxy("192.168.1.122", 8888); // client.getHostConfiguration().setProxy("192.168.1.122", 8888); PostMethod pm = new PostMethod(url);// 创建HttpPost对象 NameValuePair[] ns = new NameValuePair[map.keySet().size()]; Iterator<String> its = map.keySet().iterator();