From d1bcc87e41d8d176ce58ee9e27a17ec93d0d7cb2 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 23 八月 2019 11:59:18 +0800
Subject: [PATCH] Merge branch 'mater-1.6.0' into div
---
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java | 149 +++++++++++++++----------------------------------
1 files changed, 46 insertions(+), 103 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
index 6c70940..9f6bbe8 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
@@ -22,6 +22,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.entity.taobao.TaoBaoShopInfo;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
+import com.yeshi.fanli.exception.taobao.TaoBaoAuthException;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
@@ -37,46 +38,6 @@
//娣樺疂瀹PI鎺ュ彛
public class TaoKeApiUtil {
-
- /**
- * 鎸夊叧閿瓧鍜屽垎绫绘悳绱㈠埜
- *
- * @param key
- * @param catList
- * @return
- */
- public static TaoBaoSearchResult searchCouple(String key, List<Long> catList, int page, int pageSize) {
- Map<String, String> map = new HashMap<>();
- map.put("method", "taobao.tbk.dg.item.coupon.get");
- map.put("page_size", pageSize + "");
- map.put("page_no", page + "");
- String cate = "";
- if (catList != null && catList.size() > 10)
- catList = catList.subList(0, 10);
- if (catList != null && catList.size() > 0) {
- for (Long c : catList)
- cate += c + ",";
- if (cate.endsWith(","))
- cate = cate.substring(0, cate.length() - 1);
- map.put("cat", cate);
- }
-
- if (!StringUtil.isNullOrEmpty(key)) {
- map.put("q", key);
- }
- String result = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
- System.out.println(result);
- TaoBaoSearchResult finalResult = parseCoupleContent(result);
- if (finalResult == null)
- return null;
- PageEntity pageEntity = finalResult.getPageEntity();
- pageEntity.setPageIndex(page);
- pageEntity.setPageSize(pageSize);
- pageEntity.setTotalPage(pageEntity.getTotalCount() % pageSize == 0
- ? ((int) (pageEntity.getTotalCount() / pageSize)) : (int) (pageEntity.getTotalCount() / pageSize + 1));
- finalResult.setPageEntity(pageEntity);
- return finalResult;
- }
// 瑙f瀽鍒哥殑鍐呭
private static TaoBaoSearchResult parseCoupleContent(String content) {
@@ -376,22 +337,6 @@
System.out.println(goods.getAuctionId() + ":" + g.getAuctionId());
if (goods.getAuctionId().longValue() == g.getAuctionId()) {
g.setId(goods.getAuctionId());
- // 鍒ゆ柇鏄惁鏈変紭鎯犲埜
- if (!StringUtil.isNullOrEmpty(g.getCouponActivityId())) {
- // 鑾峰彇浼樻儬鍒歌鎯�
- QuanInfo quanInfo = getQuanInfo(g.getAuctionId(), g.getCouponActivityId());
- if (quanInfo != null) {
- g.setCouponAmount(quanInfo.coupon_amount);
- g.setCouponEffectiveEndTime(quanInfo.coupon_end_time);
- g.setCouponEffectiveStartTime(quanInfo.coupon_start_time);
- g.setCouponLeftCount(quanInfo.coupon_remain_count);
- g.setCouponStartFee(quanInfo.coupon_start_fee);
- g.setCouponTotalCount(quanInfo.coupon_total_count);
- }
- } else {
- g.setCouponAmount(new BigDecimal(0));
- g.setCouponStartFee(new BigDecimal(0));
- }
g.setCreatetime(new Date());
g.setMaterialLibType(goods.getMaterialLibType());
return g;
@@ -929,10 +874,9 @@
if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
List<BigDecimal> quanInfo = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo());
goods.setCouponAmount(quanInfo.get(1));
- goods.setCouponEffectiveEndTime(
- TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24, "yyyy-MM-dd"));
- goods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
- goods.setCouponStartFee(quanInfo.get(0));
+ goods.setCouponEffectiveEndTime(item.optString("coupon_end_time"));
+ goods.setCouponEffectiveStartTime(item.optString("coupon_start_time"));
+ goods.setCouponStartFee(new BigDecimal(item.optString("coupon_start_fee")));
goods.setCouponLeftCount(item.optInt("coupon_remain_count"));
goods.setCouponLink("https:" + item.optString("coupon_share_url"));
goods.setCouponTotalCount(item.optInt("coupon_total_count"));
@@ -1297,41 +1241,6 @@
}
/**
- * TODO 鎸夎澶囩寽浣犲枩娆�
- *
- * @param userNickName
- * @param os
- * @param imei
- * @param idfa
- * @param ip
- * @param ua
- * @param net
- * @param pageNo
- * @param pageSize
- */
- public static void guessLikeByDevice(String userNickName, String os, String imei, String idfa, String ip, String ua,
- String net, int pageNo, int pageSize) {
- Map<String, String> map = new HashMap<>();
- map.put("method", "taobao.tbk.item.guess.like");
- if (!StringUtil.isNullOrEmpty(userNickName))
- map.put("user_nick", userNickName);
- map.put("os", os + "");
- if (!StringUtil.isNullOrEmpty(idfa))
- map.put("idfa", idfa);
- if (!StringUtil.isNullOrEmpty(imei)) {
- map.put("imei", imei + "");
- map.put("imei_md5", StringUtil.Md5(imei));
- }
- map.put("ip", ip + "");
- map.put("ua", ua + "");
- map.put("net", net + "");
- map.put("page_no", pageNo + "");
- map.put("page_size", pageSize + "");
- String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
- System.out.println(resultStr);
- }
-
- /**
* 鍝佺墝鍒歌幏鍙�
*
* @param pageNo
@@ -1646,7 +1555,7 @@
return null;
}
- public static String getRelationId(String accessToken, String appKey, String appSecret) {
+ public static String getRelationId(String accessToken, String appKey, String appSecret) throws TaoBaoAuthException {
Map<String, String> map = new HashMap<>();
map.put("method", "taobao.tbk.sc.publisher.info.save");
map.put("session", accessToken);
@@ -1662,14 +1571,22 @@
return resultJSON.optJSONObject("tbk_sc_publisher_info_save_response").optJSONObject("data")
.optString("relation_id");
} catch (TaoKeApiException e) {
- e.printStackTrace();
- LogHelper.error("娓犻亾ID鐢宠鍑洪敊:" + e.getMsg());
+ JSONObject errorJSON = JSONObject.fromObject(e.getMsg()).optJSONObject("error_response");
+ if (errorJSON.optInt("code") == 15 && errorJSON.optInt("sub_code") == 1)// 鏈疄鍚�
+ {
+ throw new TaoBaoAuthException(TaoBaoAuthException.CODE_NOT_REAL_NAME, errorJSON.optString("sub_msg"));
+ } else {
+ e.printStackTrace();
+ LogHelper.error("娓犻亾ID鐢宠鍑洪敊:" + e.getMsg());
+ throw new TaoBaoAuthException(TaoBaoAuthException.CODE_OTHER, errorJSON.optString("sub_msg"));
+ }
+ } catch (Exception e) {
+ LogHelper.error("娓犻亾ID鐢宠鍑洪敊:" + (resultJSON != null ? resultJSON.toString() : "鏈煡閿欒"));
}
-
return null;
}
- public static String getSpecialId(String accessToken, String appKey, String appSecret) {
+ public static String getSpecialId(String accessToken, String appKey, String appSecret) throws TaoBaoAuthException {
Map<String, String> map = new HashMap<>();
map.put("method", "taobao.tbk.sc.publisher.info.save");
map.put("session", accessToken);
@@ -1685,8 +1602,17 @@
return resultJSON.optJSONObject("tbk_sc_publisher_info_save_response").optJSONObject("data")
.optString("special_id");
} catch (TaoKeApiException e) {
- e.printStackTrace();
- LogHelper.error("浼氬憳杩愯惀ID鐢宠鍑洪敊:" + resultJSON);
+ JSONObject errorJSON = JSONObject.fromObject(e.getMsg()).optJSONObject("error_response");
+ if (errorJSON.optInt("code") == 15 && errorJSON.optInt("sub_code") == 1)// 鏈疄鍚�
+ {
+ throw new TaoBaoAuthException(TaoBaoAuthException.CODE_NOT_REAL_NAME, errorJSON.optString("sub_msg"));
+ } else {
+ e.printStackTrace();
+ LogHelper.error("浼氬憳杩愯惀ID鐢宠鍑洪敊:" + e.getMsg());
+ throw new TaoBaoAuthException(TaoBaoAuthException.CODE_OTHER, errorJSON.optString("sub_msg"));
+ }
+ } catch (Exception e) {
+ LogHelper.error("浼氬憳杩愯惀ID鐢宠鍑洪敊:" + (resultJSON != null ? resultJSON.toString() : "鏈煡閿欒"));
}
return null;
@@ -1763,7 +1689,7 @@
public static void taoKeContent() {
Map<String, String> map = new HashMap<>();
map.put("method", "taobao.tbk.content.get");
- map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]);
+ map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]);
map.put("type", "1");
map.put("count", "100");
@@ -2082,6 +2008,23 @@
}
return null;
}
+
+ public static void getCouponByAuctionId(Long auctionId) {
+ Map<String, String> map = new HashMap<>();
+ map.put("method", "taobao.tbk.itemid.coupon.get");
+ map.put("platform", 2 + "");
+ map.put("pid", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
+ map.put("num_iids", auctionId + "");
+ TaoKeAppInfo app = new TaoKeAppInfo();
+ app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY);
+ app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
+ try {
+ JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
+ System.out.print(json);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
class QuanInfo {
--
Gitblit v1.8.0