admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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 {
 
    }
 
 
}