| | |
| | | package com.yeshi.fanli.util.taobao; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.common.entity.PageEntity; |
| | | import com.yeshi.common.entity.taobao.TaoBaoShopInfo; |
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo; |
| | |
| | | if (item.optBoolean("free_shipment")) |
| | | goods.setFreeShipment(1); |
| | | |
| | | goods.setMaterialLibTypes(item.optString("material_lib_type")); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(item.optString("material_lib_type"))) { |
| | | try { |
| | | String materialLibType = item.optString("material_lib_type"); |
| | |
| | | // 从转链搜索 |
| | | TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(), |
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), specialId, relationId); |
| | | TaoBaoConstant.TAOBAO_PID_DEFAULT), specialId, relationId); |
| | | |
| | | if (newGoods != null) { |
| | | goods.setTkRate(newGoods.getTkRate()); |
| | |
| | | // 从转链搜索 |
| | | TaoBaoGoodsBrief newGoods = specialConvertCoupon(goods.getAuctionId(), |
| | | new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), null, null); |
| | | TaoBaoConstant.TAOBAO_PID_DEFAULT), null, null); |
| | | |
| | | if (newGoods != null) { |
| | | goods.setTkRate(newGoods.getTkRate()); |
| | |
| | | map.put("relation_id", relationId); |
| | | } |
| | | |
| | | if (app != null && app.getPid() != null) { |
| | | map.put("adzone_id", app.getPid().split("_")[3]); |
| | | |
| | | } |
| | | |
| | | String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, app); |
| | | System.out.println(resultStr); |
| | | JSONObject data = JSONObject.fromObject(resultStr); |
| | | if (data.optJSONObject("tbk_dg_material_optional_response") != null |
| | | && data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list") != null) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 从淘宝链接中解析商品ID(高级接口) |
| | | * |
| | | * @param link |
| | | * @return |
| | | */ |
| | | public static String parseAuctionIdFromLink(String link) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.tbk.item.click.extract"); |
| | | map.put("click_url", link + ""); |
| | | |
| | | TaoKeAppInfo app = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, |
| | | TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID); |
| | | JSONObject resultJSON = null; |
| | | try { |
| | | resultJSON = TaoKeBaseUtil.baseRequest(map, app); |
| | | System.out.println(resultJSON); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (resultJSON == null) |
| | | return null; |
| | | |
| | | return null; |
| | | |
| | | } |
| | | |
| | | public static String getAccessToken(String code, String appKey, String appSecret) { |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | return null; |
| | | } |
| | | |
| | | public static void juHuaSuan() { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.ju.items.search"); |
| | | map.put("current_page", 1 + ""); |
| | | map.put("page_size", 100 + ""); |
| | | map.put("pid", "mm_124933865_43788020_381938426"); |
| | | |
| | | TaoKeAppInfo app = new TaoKeAppInfo(); |
| | | app.setAppKey("24838852"); |
| | | app.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8"); |
| | | |
| | | try { |
| | | JSONObject json = TaoKeBaseUtil.baseRequest(map, app); |
| | | System.out.println(json); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static void taoKeContent() { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.tbk.content.get"); |
| | | map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT.split("_")[3]); |
| | | map.put("type", "1"); |
| | | map.put("count", "100"); |
| | | |
| | | 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.println(json); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public static void taoKeContentSource(String contentId, String source) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.tbk.dg.optimus.material"); |
| | | map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]); |
| | | map.put("page_size", "10"); |
| | | map.put("page_no", "1"); |
| | | map.put("content_id", contentId); |
| | | map.put("content_source", source); |
| | | map.put("material_id", "1"); |
| | | |
| | | 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.println(json); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // AA5ISJ |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public static void getTaoKeContentEffective() { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.tbk.dg.optimus.material"); |
| | | map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID.split("_")[3]); |
| | | map.put("page_no", "1"); |
| | | map.put("page_size", "20"); |
| | | map.put("content_id", "8872035"); |
| | | |
| | | 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.println(json); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static void getTaoKeContent() { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.tbk.content.get"); |
| | | map.put("adzone_id", TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID.split("_")[3]); |
| | | map.put("type", "1"); |
| | | |
| | | 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.println(json); |
| | | } catch (TaoKeApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 淘口令转商品ID |
| | | * |
| | | * @param token |
| | | * @return |
| | | */ |
| | | public static Long tokenConvertAuctionId(String token) throws TaoBaoTokenParseException { |
| | | public static TokenConvertResult tokenConvert(String token) throws TaoBaoTokenParseException { |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.tbk.tpwd.convert"); |
| | | map.put("password_content", token); |
| | | map.put("adzone_id", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT.split("_")[3]); |
| | | map.put("adzone_id", TaoBaoConstant.TAOBAO_PID_DEFAULT.split("_")[3]); |
| | | TaoKeAppInfo app = new TaoKeAppInfo(); |
| | | app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); |
| | | app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); |
| | |
| | | System.out.println(json.toString()); |
| | | |
| | | try { |
| | | return json.optJSONObject("tbk_tpwd_convert_response").optJSONObject("data").optLong("num_iid"); |
| | | JSONObject data = json.optJSONObject("tbk_tpwd_convert_response").optJSONObject("data"); |
| | | Gson gson = new Gson(); |
| | | |
| | | return gson.fromJson(data.toString(), TokenConvertResult.class); |
| | | } catch (Exception e) { |
| | | |
| | | return null; |
| | |
| | | } |
| | | |
| | | // 淘礼金创建 |
| | | //{"result":{"msg_code":"FAIL_CHECK_ITEM_DAILY_SEND_NUM_CHECK_ERROR","msg_info":"今日该商品淘礼金创建数已超上限,请您明日再试","success":false},"request_id":"10p30v02qadkq"} |
| | | //{"result":{"msg_code":"ASSET_ACCOUNT_BALANCE_NOT_ENOUGH","msg_info":"账户预算不足","success":false},"request_id":"5caz9izr7jqp"} |
| | | public static TaoLiJinDTO createTaoLiJin(Long auctionId, String name, BigDecimal perface, int totalNum, |
| | | Date sendStartTime, Date sendEndTime, Date useStartTime, Date useEndTime, TaoKeAppInfo app) |
| | | throws TaoLiJinCreateException, TaoKeApiException { |
| | |
| | | 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("pid", TaoBaoConstant.TAOBAO_PID_DEFAULT); |
| | | map.put("num_iids", auctionId + ""); |
| | | TaoKeAppInfo app = new TaoKeAppInfo(); |
| | | app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public static Date getTaoBaoSystemTime() { |
| | | Map<String, String> map = new HashMap<>(); |
| | | public static Date getTaoBaoSystemTime() { Map<String, String> map = new HashMap<>(); |
| | | map.put("method", "taobao.time.get"); |
| | | try { |
| | | JSONObject json = TaoKeBaseUtil.baseRequest(map, false); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | map.put("method", "taobao.tbk.itemid.coupon.get"); |
| | | map.put("platform", auctionId + ""); |
| | | map.put("num_iids", auctionId + ""); |
| | | map.put("pid", TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT); |
| | | map.put("pid", TaoBaoConstant.TAOBAO_PID_DEFAULT); |
| | | |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | JSONObject resultJSON = null; |
| | | try { |
| | | resultJSON = TaoKeBaseUtil.baseRequest(map, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, |
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT)); |
| | | TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_PID_DEFAULT)); |
| | | |
| | | JSONObject response = resultJSON.optJSONObject("tbk_dg_optimus_material_response"); |
| | | if (response != null && response.optJSONObject("result_list") != null) { |
| | |
| | | public BigDecimal coupon_start_fee;// 券起始金额 |
| | | } |
| | | |
| | | public static class TokenConvertResult { |
| | | private Long num_iid;// 商品Id |
| | | private String click_url;//商品淘客转链 |
| | | private String seller_id;//店铺卖家ID |
| | | private String origin_url;//入参淘口令对应原始链接 |
| | | private String origin_pid;//入参淘口令推广链接中的pid,如果不属于当前调用的推广者则展示“0” |
| | | |
| | | public Long getNum_iid() { |
| | | return num_iid; |
| | | } |
| | | |
| | | public void setNum_iid(Long num_iid) { |
| | | this.num_iid = num_iid; |
| | | } |
| | | |
| | | public String getClick_url() { |
| | | return click_url; |
| | | } |
| | | |
| | | public void setClick_url(String click_url) { |
| | | this.click_url = click_url; |
| | | } |
| | | |
| | | public String getSeller_id() { |
| | | return seller_id; |
| | | } |
| | | |
| | | public void setSeller_id(String seller_id) { |
| | | this.seller_id = seller_id; |
| | | } |
| | | |
| | | public String getOrigin_url() { |
| | | return origin_url; |
| | | } |
| | | |
| | | public void setOrigin_url(String origin_url) { |
| | | this.origin_url = origin_url; |
| | | } |
| | | |
| | | public String getOrigin_pid() { |
| | | return origin_pid; |
| | | } |
| | | |
| | | public void setOrigin_pid(String origin_pid) { |
| | | this.origin_pid = origin_pid; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |