package com.yeshi.fanli.util.taobao;
|
|
import com.google.gson.Gson;
|
import com.google.gson.reflect.TypeToken;
|
import com.yeshi.common.entity.taobao.TaoKeAppInfo;
|
import com.yeshi.fanli.dto.taobao.koubei.KouBeiOrderDTO;
|
import com.yeshi.fanli.dto.taobao.TaoKeListResult;
|
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
|
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
import java.lang.reflect.Type;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
//口碑本地生活API接口
|
public class TaoKeKouBeiApiUtil {
|
|
final static TaoKeAppInfo appInfo = new TaoKeAppInfo("33227121", "207014b8b57a42f82205619d508777ac", "alsc_12859804_145002_121004");
|
|
private static JSONObject getResult(String resultKey, JSONObject data) throws Exception {
|
data = data.optJSONObject(resultKey);
|
if (data.optBoolean("result_success")) {
|
|
if (data.optJSONObject("result") == null) {
|
throw new Exception("请求结果为空");
|
}
|
return data.optJSONObject("result");
|
} else {
|
throw new Exception("请求返回未成功");
|
}
|
}
|
|
|
/**
|
* @return com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief
|
* @author hxh
|
* @description https://open.taobao.com/api.htm?docId=58766&docType=2&scopeId=24408
|
* @date 18:20 2021/11/25
|
**/
|
public static TaoBaoGoodsBrief getGoodsList() throws Exception {
|
Map<String, String> map = new HashMap<>();
|
// map.put("session", "6101725762ec88b0993ed5a2fd0a459c41df4fff2b829313327215652");
|
map.put("method", "alibaba.alsc.union.kb.item.promotion");
|
map.put("pid", "alsc_12859804_145002_121004");
|
map.put("settle_type", "1");
|
map.put("page_size", "20");
|
map.put("page_number", "1");
|
|
JSONObject data = TaoKeBaseUtil.baseRequest(map, appInfo);
|
System.out.println(data.toString());
|
// // 商品下架
|
// if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 15
|
// && data.optJSONObject("error_response").optInt("sub_code") == 50001) {
|
// throw new TaobaoGoodsDownException(data.optJSONObject("error_response").optInt("code"), "商品下架");
|
// }
|
//
|
// if (data.optJSONObject("tbk_item_info_get_response") == null)
|
// return null;
|
// JSONArray array = data.optJSONObject("tbk_item_info_get_response").optJSONObject("results")
|
// .optJSONArray("n_tbk_item");
|
// if (array != null && array.size() > 0) {
|
// JSONObject item = array.optJSONObject(0);
|
// return parseSimpleGoodsInfo(item);
|
// }
|
return null;
|
}
|
|
|
public static String createPid(String pidName) throws TaoKeApiException, Exception {
|
Map<String, String> map = new HashMap<>();
|
map.put("method", "alibaba.alsc.union.media.zone.add");
|
map.put("zone_name", pidName);
|
JSONObject data = TaoKeBaseUtil.baseRequest(map, appInfo);
|
JSONObject result = getResult("alibaba_alsc_union_media_zone_add_response", data);
|
return result.optString("pid");
|
}
|
|
public static TaoKeListResult<KouBeiOrderDTO> listOrders() throws TaoKeApiException, Exception {
|
Map<String, String> map = new HashMap<>();
|
map.put("method", "alibaba.alsc.union.kbcpa.order.details.get");
|
map.put("start_date", "2021-11-01 10:00:00");
|
JSONObject data = TaoKeBaseUtil.baseRequest(map, appInfo);
|
JSONObject result = getResult("alibaba_alsc_union_kbcpa_order_details_get_response", data);
|
JSONArray array = result.optJSONArray("order_detail_report_dto");
|
|
List<KouBeiOrderDTO> orderList = new ArrayList<>();
|
if (array != null) {
|
Type type = new TypeToken<List<KouBeiOrderDTO>>() {
|
}.getType();
|
orderList = new Gson().fromJson(array.toString(), type);
|
}
|
int count = data.optJSONObject("alibaba_alsc_union_kbcpa_order_details_get_response").optInt("total_count");
|
return new TaoKeListResult<KouBeiOrderDTO>(orderList, count);
|
}
|
|
|
public static void main(String[] args) throws Exception {
|
|
}
|
|
|
}
|