admin
2021-07-05 2f071296b9e1d7a3aa6b6f3818196aaa40af3300
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
package com.ks.lijin.utils.taobao;
 
 
import com.google.gson.Gson;
import com.ks.lijin.exception.*;
import com.ks.lijin.pojo.DTO.taobao.*;
import com.ks.lijin.pojo.PageEntity;
import com.taobao.api.internal.util.StringUtils;
import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.goods.facade.entity.taobao.TaoBaoHead;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.yeshi.utils.*;
 
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;
 
//淘宝客API接口
public class TaoKeApiUtil {
 
    private static long lastTime = 0;
    private static Map<String, Integer> invalidMap = new HashMap<>();
 
    // 淘礼金创建
    public static TaoLiJinDTO createTaoLiJin(Long auctionId, String name, BigDecimal perface, int totalNum,
                                             Date sendStartTime, Date sendEndTime, Date useStartTime, Date useEndTime, TaoKeAppInfo app)
            throws LiJinAccountException, LiJinAmountException, LiJinException, LiJinGoodsException {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.vegas.tlj.create");
        map.put("adzone_id", app.getPid().split("_")[3]);
        map.put("item_id", auctionId + "");
        map.put("total_num", totalNum + "");
        map.put("name", name);
        map.put("user_total_win_num_limit", "1");
        map.put("security_switch", "false");
        map.put("per_face", perface.toString());
        map.put("send_start_time", TimeUtil.getGernalTime(sendStartTime.getTime(), "yyyy-MM-dd HH:mm:ss"));
 
        if (sendEndTime != null)
            map.put("send_end_time", TimeUtil.getGernalTime(sendEndTime.getTime(), "yyyy-MM-dd HH:mm:ss"));
 
        if (useEndTime != null) {
            map.put("use_end_time", TimeUtil.getGernalTime(useEndTime.getTime(), "yyyy-MM-dd"));
            map.put("use_end_time_mode", "2");
        }
 
        if (useStartTime != null)
            map.put("use_start_time", TimeUtil.getGernalTime(useStartTime.getTime(), "yyyy-MM-dd"));
        try {
            String result = baseRequestForThreeTimes(map, app);
            JSONObject json = JSONObject.fromObject(result);
            System.out.println(json);
            JSONObject root = json.optJSONObject("tbk_dg_vegas_tlj_create_response");
            if (root != null && root.optJSONObject("result") != null) {
 
                if (root.optJSONObject("result").optBoolean("success")) {
                    JSONObject modelJson = root.optJSONObject("result").optJSONObject("model");
                    TaoLiJinDTO dto = new TaoLiJinDTO();
                    dto.setRightsId(modelJson.optString("rights_id"));
                    dto.setSendUrl(modelJson.optString("send_url"));
                    return dto;
                } else {
                    // 日志记录  TODO
                }
 
                // 接口返回异常
                String msgCode = root.optJSONObject("result").optString("msg_code");
                String msgInfo = root.optJSONObject("result").optString("msg_info");
                if (!StringUtil.isNullOrEmpty(msgCode)) {
                    // TLJLogHelper.info(auctionId, root.toString());// 淘礼金异常信息记录  TODO
                    switch (msgCode) {
                        case "FAIL_BIZ_ITEM_FORBIDDEN":
                            throw new LiJinGoodsException(LiJinGoodsException.CODE_GOODS_NOT_SUPPORT, "该商品不支持创建淘礼金红包");
                        case "FAIL_BIZ_ACCOUNT_UN_PAID":
                            throw new LiJinAccountException(LiJinAccountException.CODE_TLJ_UN_PAID, "您的淘礼金账户暂未创建,请前往资金管理页面充值");
                        case "PRE_FREEZE_ASSET_ACCOUNT_ERROR":
                            throw new LiJinAccountException(LiJinAccountException.CODE_TLJ_NO_MONEY, "官方玩法钱包余额不足");
                        case "ASSET_ACCOUNT_BALANCE_NOT_ENOUGH":
                            throw new LiJinAccountException(LiJinAccountException.CODE_TLJ_NO_MONEY, "账户预算不足");
                        case "FAIL_CHECK_MEMBER_DAILY_SEND_ITEM_ABOVE_LIMIT_ERROR":
                            throw new LiJinAccountException(LiJinAccountException.CODE_TLJ_NO_GOODS, "今日商品创建数已超上限,请您明日再试");
                        case "FAIL_CHECK_ITEM_DAILY_SEND_NUM_CHECK_ERROR":
                            throw new LiJinGoodsException(LiJinGoodsException.CODE_GOODS_CREATED_FULL, "今日该商品淘礼金创建数已超上限,请您明日再试");
 
                        case "FAIL_CHECK_TLJ_MIN_FACE_ERROR":
                            throw new LiJinAmountException(LiJinAmountException.CODE_LIJIN_AMOUNT_OUTOFRANGE, msgInfo);
                        default:
                            throw new LiJinException(1, root.toString());
                    }
                }
            }
        } catch (LiJinException e) {
            throw e;
        }
 
        return null;
    }
 
 
    /**
     * 淘礼金报告
     *
     * @param rightsId
     * @param app
     * @return
     * @throws LiJinAccountException
     * @throws LiJinAmountException
     * @throws LiJinException
     * @throws LiJinGoodsException
     */
    public static TaoLiJinReportDTO taolijinReport(String rightsId, TaoKeAppInfo app) {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.vegas.tlj.instance.report");
        map.put("rights_id", rightsId);
 
        String result = baseRequestForThreeTimes(map, app);
        JSONObject json = JSONObject.fromObject(result);
        System.out.println(json);
        JSONObject root = json.optJSONObject("tbk_dg_vegas_tlj_instance_report_response");
        if (root != null && root.optJSONObject("result") != null) {
            if (root.optJSONObject("result").optBoolean("success")) {
                JSONObject modelJson = root.optJSONObject("result").optJSONObject("model");
                TaoLiJinReportDTO dto = new Gson().fromJson(modelJson.toString(), TaoLiJinReportDTO.class);
                return dto;
            } else {
                // 日志记录  TODO
            }
        }
 
 
        return null;
    }
 
 
    public static String baseRequestForThreeTimes(Map<String, String> params, TaoKeAppInfo app) {
        JSONObject data = null;
        int count = 0;
        while (data == null && count < 3) {
            count++;
            try {
                data = baseRequest(params, app);
            } catch (TaoKeApiException e) {
                // 记录现场
//                TaoKeLogHelper.error(e.getParams(), e.getMsg());
            }
        }
        if (data != null)
            return data.toString();
        else
            return new JSONObject().toString();
    }
 
 
    public static JSONObject baseRequest(Map<String, String> param, TaoKeAppInfo app) throws TaoKeApiException {
        Map<String, String> params = new HashMap<>();
        if (param != null) {
            Iterator<String> its = param.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                params.put(key, param.get(key));
            }
        }
 
        // 获取有效的APPKey
        if (app == null) {
            throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
        }
 
        // 签名
        params.put("app_key", app.getAppKey());
        params.put("sign_method", "md5");
        params.put("v", "2.0");
        params.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
        params.put("format", "json");
        if (!StringUtil.isNullOrEmpty(app.getAdzoneId())) {
            params.put("adzone_id", app.getAdzoneId());
        }
        params.put("sign", getSign(params, "md5", app).toUpperCase());
        String result = taoKeGet(params);
        JSONObject data = JSONObject.fromObject(result);
        if (data != null) {
            if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 7
                    && "accesscontrol.limited-by-app-access-count"
                    .equalsIgnoreCase(data.optJSONObject("error_response").optString("sub_code"))) {
                reportAppInvalid(app.getAppKey());
                throw new TaoKeApiException(TaoKeApiException.CODE_APPKEY_LIMIT, "淘宝请求限制:" + result, params);
            } else if (data.optJSONObject("error_response") != null) {
                throw new TaoKeApiException(TaoKeApiException.CODE_API_ERROR, result, params);
            }
        } else
            throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
        reValid(app.getAppKey());
        return data;
    }
 
    /**
     * APPKey恢复可用
     *
     * @param appKey
     */
    static void reValid(String appKey) {
        if (invalidMap == null)
            return;
        Integer count = invalidMap.get(appKey);
        if (count != null && count > 0)
            invalidMap.put(appKey, count - 1);
    }
 
    /**
     * 报告该APPKey不能用
     *
     * @param appkey
     */
    static void reportAppInvalid(String appkey) {
        if (invalidMap == null)
            return;
        // 错误三次后再真正上报
        if (invalidMap.get(appkey) == null)
            invalidMap.put(appkey, 1);
        else
            invalidMap.put(appkey, invalidMap.get(appkey) + 1);
 
        if (invalidMap.get(appkey) < 4)
            return;
        invalidMap.put(appkey, 0);
        HttpUtil.get("http://193.112.35.168:8091/tb/taoke/reportappcannotuse?appkey=" + appkey);
        lastTime = 0;
    }
 
 
    /**
     * 获取签名参数
     *
     * @param params
     * @param signMethod
     * @param app
     * @return
     */
    public static String getSign(Map<String, String> params, String signMethod, TaoKeAppInfo app) {
        // 第一步:检查参数是否已经排序
        String[] keys = params.keySet().toArray(new String[0]);
        Arrays.sort(keys);
 
        // 第二步:把所有参数名和参数值串在一起
        StringBuilder query = new StringBuilder();
        if ("md5".equals(signMethod)) {
            query.append(app.getAppSecret());
        }
        for (String key : keys) {
            String value = params.get(key);
            if (StringUtils.areNotEmpty(key, value)) {
                query.append(key).append(value);
            }
        }
 
        query.append(app.getAppSecret());
        return StringUtil.Md5(query.toString());
    }
 
 
    public static String taoKeGet(Map<String, String> params) {
        String result = get("https://eco.taobao.com/router/rest", params, false);
        return result;
    }
 
 
    public static String get(String url, Map<String, String> params, boolean proxy) {
        HttpClient client = new HttpClient();
        try {
            Iterator<String> keys = params.keySet().iterator();
            url += "?";
            while (keys.hasNext()) {
                String key = keys.next();
                url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
            }
            System.out.println("淘客请求连接:" + url);
            GetMethod method = new GetMethod(url);
            // 3S的响应超时
            HttpConnectionManagerParams hparams = new HttpConnectionManagerParams();
            hparams.setConnectionTimeout(3000);
            client.getHttpConnectionManager().setParams(hparams);
            client.executeMethod(method);
            String result = method.getResponseBodyAsString();
            System.out.println(result);
            return method.getResponseBodyAsString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
 
 
    public static TaoBaoGoodsBrief searchGoodsDetail(Long id) throws TaoBaoGoodsDownException {
        return searchGoodsDetail(id, null, null);
    }
 
    /**
     * 搜索商品详情-详细
     *
     * @param id
     * @return
     * @throws
     */
    public static TaoBaoGoodsBrief searchGoodsDetail(Long id, String specialId, String relationId) throws TaoBaoGoodsDownException {
        TaoBaoGoodsBrief goods = getSimpleGoodsInfo(id);
        if (goods == null)
            return null;
        SearchFilter filter = new SearchFilter();
        filter.setKey(goods.getTitle());
        filter.setPage(1);
        filter.setPageSize(50);
        TaoBaoSearchResult result = searchWuLiaoForDetail(goods.getTitle(), goods.getZkPrice(), goods.getProvcity(),
                goods.getUserType(), specialId, relationId);
        if (result != null && result.getTaoBaoGoodsBriefs() != null)
            for (TaoBaoGoodsBrief g : result.getTaoBaoGoodsBriefs()) {
                System.out.println(goods.getAuctionId() + ":" + g.getAuctionId());
                if (goods.getAuctionId().longValue() == g.getAuctionId()) {
                    g.setId(goods.getAuctionId());
                    g.setCreatetime(new Date());
                    g.setMaterialLibType(goods.getMaterialLibType());
                    g.setProvcity(goods.getProvcity());
                    return g;
                }
            }
        goods.setCouponAmount(new BigDecimal("0"));
        goods.setTkMktStatus("1");
        goods.setTkRate(new BigDecimal("0"));
        goods.setReservePrice(new BigDecimal(0));
        goods.setTkCommFee(new BigDecimal(0));
        return goods;
    }
 
 
    /**
     * 获取商品详情,简版
     *
     * @param id -商品AuctionId
     * @return
     */
    public static TaoBaoGoodsBrief getSimpleGoodsInfo(Long id) throws TaoBaoGoodsDownException {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.item.info.get");
        map.put("num_iids", id + "");
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        System.out.println(resultStr);
        JSONObject data = JSONObject.fromObject(resultStr);
        // 商品下架
        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;
    }
 
 
    private static TaoBaoGoodsBrief parseSimpleGoodsInfo(JSONObject item) {
        TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
        goods.setAuctionId(item.optLong("num_iid"));
        goods.setAuctionUrl(item.optString("item_url"));
        goods.setBiz30day(item.optInt("volume"));
        if (item.optJSONObject("small_images") != null) {
            JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
            if (imgArray != null) {
                List<String> imgList = new ArrayList<>();
                for (int n = 0; n < imgArray.size(); n++) {
                    imgList.add(imgArray.optString(n));
                }
                goods.setImgList(imgList);
            }
        }
        goods.setTitle(item.optString("title"));
        goods.setUserType(item.optInt("user_type"));
        goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
        goods.setReservePrice(new BigDecimal(item.optString("zk_final_price")));
        goods.setAuctionUrl(item.optString("item_url"));
        goods.setProvcity(item.optString("provcity"));
        goods.setPictUrl(item.optString("pict_url"));
        goods.setShopTitle(item.optString("nick"));
        goods.setSellerId(item.optLong("seller_id"));
        goods.setRootCategoryName(item.optString("cat_name"));
        goods.setLeafName(item.optString("cat_leaf_name"));
 
        String optString = item.optString("shop_dsr");
        if (!StringUtil.isNullOrEmpty(optString)) {
            goods.setShopDsr(new Integer(optString));
        }
 
        String ratesum = item.optString("ratesum");
        if (!StringUtil.isNullOrEmpty(ratesum)) {
            goods.setRatesum(new Integer(ratesum));
        }
 
        if (item.optBoolean("is_prepay"))
            goods.setIsPrepay(1);
 
        if (item.optBoolean("i_rfd_rate"))
            goods.setRfdRate(1);
 
        if (item.optBoolean("h_good_rate"))
            goods.setGoodRate(1);
 
        if (item.optBoolean("h_pay_rate30"))
            goods.setPayRate30(1);
 
        if (item.optBoolean("free_shipment"))
            goods.setFreeShipment(1);
 
        if (!StringUtil.isNullOrEmpty(item.optString("material_lib_type"))) {
            try {
                String materialLibType = item.optString("material_lib_type");
                goods.setMaterialLibType(Integer.parseInt(materialLibType.split(",")[0]));
            } catch (Exception e) {
                goods.setMaterialLibType(0);
            }
 
        } else
            goods.setMaterialLibType(0);
 
        goods.setRootCategoryName(item.optString("cat_name"));
        goods.setLeafName(item.optString("cat_leaf_name"));
 
        goods = loadYuShouInfo(goods, item);
        return goods;
    }
 
    private static TaoBaoGoodsBrief loadYuShouInfo(TaoBaoGoodsBrief goods, JSONObject item) {
        if (goods != null && item != null) {
            // 预售相关解析
            goods.setYsylClickUrl(item.optString("ysyl_click_url"));
            if (!StringUtil.isNullOrEmpty(item.optString("ysyl_commission_rate")))
                goods.setYsylCommissionRate(new BigDecimal(item.optString("ysyl_commission_rate")));
            goods.setYsylTljFace(item.optString("ysyl_tlj_face"));
            goods.setYsylTljSendTime(item.optString("ysyl_tlj_send_time"));
            goods.setYsylTljUseEndTime(item.optString("ysyl_tlj_use_end_time"));
            goods.setYsylTljUseStartTime(item.optString("ysyl_tlj_use_start_time"));
 
            goods.setPresaleDeposit(item.optString("presale_deposit"));
            goods.setPresaleDiscountFeeText(item.optString("presale_discount_fee_text"));
            goods.setPresaleEndTime(item.optString("presale_end_time"));
            goods.setPresaleStartTime(item.optString("presale_start_time"));
            goods.setPresaleTailEndTime(item.optString("presale_tail_end_time"));
            goods.setPresaleTailStartTime(item.optString("presale_tail_start_time"));
 
            return goods;
        }
        return goods;
    }
 
 
    /**
     * 商品物料搜索
     *
     * @param title
     * @param zkPrice
     * @param provcity
     * @param userType
     * @param specialId
     * @param relationId
     * @return
     */
    public static TaoBaoSearchResult searchWuLiaoForDetail(String title, BigDecimal zkPrice, String provcity,
                                                           int userType, String specialId, String relationId) {
        if (provcity.trim().contains(" "))
            provcity = provcity.split(" ")[provcity.split(" ").length - 1];
        TaoBaoSearchResult taoBaoSearchResult = new TaoBaoSearchResult();
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.tbk.dg.material.optional");
        map.put("page_size", 50 + "");
        map.put("page_no", 1 + "");
        map.put("start_price", (int) zkPrice.subtract(new BigDecimal(1)).doubleValue() + "");
        map.put("end_price", (int) zkPrice.add(new BigDecimal(1)).doubleValue() + "");
        map.put("is_tmall", (userType == 1) + "");
        map.put("q", title);
        map.put("itemloc", provcity);
 
        if (!StringUtil.isNullOrEmpty(specialId) && !StringUtil.isNullOrEmpty(relationId)) {
            map.put("special_id", specialId);
        } else if (!StringUtil.isNullOrEmpty(specialId)) {
            map.put("special_id", specialId);
        } else if (!StringUtil.isNullOrEmpty(relationId)) {
            map.put("relation_id", relationId);
        }
 
        String resultStr = TaoKeBaseUtil.baseRequestForThreeTimes(map, true);
        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) {
            JSONArray array = data.optJSONObject("tbk_dg_material_optional_response").optJSONObject("result_list")
                    .optJSONArray("map_data");
            List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
            if (array != null) {
                for (int i = 0; i < array.size(); i++) {
                    TaoBaoGoodsBrief goods = parseWuLiaoItem(array.optJSONObject(i));
                    if (goods != null)
                        goodsList.add(goods);
                }
            }
            taoBaoSearchResult.setTaoBaoGoodsBriefs(goodsList);
        }
 
        List<TaoBaoSearchNav> navList = new ArrayList<>();
 
        TaoBaoHead taoBaoHead = new TaoBaoHead();
        taoBaoHead.setDocsfound(1000);
        taoBaoSearchResult.setTaoBaoHead(taoBaoHead);
        taoBaoSearchResult.setPageEntity(new PageEntity());
 
        taoBaoSearchResult.setNavList(navList);
 
        return taoBaoSearchResult;
    }
 
 
    // 解析物料
    private static TaoBaoGoodsBrief parseWuLiaoItem(JSONObject item) {
        TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
        goods.setPictUrl(item.optString("pict_url"));
 
        if (!StringUtil.isNullOrEmpty(item.optString("white_image"))) {
            goods.setPictUrlWhite(item.optString("white_image"));
        }
 
        goods.setAuctionId(item.optLong("num_iid"));
        goods.setAuctionUrl("https:" + item.optString("url"));
        goods.setBiz30day(item.optInt("volume"));
        goods.setCouponInfo(item.optString("coupon_info"));
 
        if (goods.getCouponInfo() != null)
            goods.setCouponInfo(goods.getCouponInfo().replace(".00", ""));
 
        if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
            List<BigDecimal> quanInfo = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo());
            goods.setCouponAmount(quanInfo.get(1));
            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"));
            goods.setCouponActivityId(item.optString("coupon_id"));
        } else {
            goods.setCouponAmount(new BigDecimal(0));
        }
 
        goods.setDayLeft(-1);
        if (item.optJSONObject("small_images") != null) {
            JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string");
            if (imgArray != null) {
                List<String> imgList = new ArrayList<>();
                for (int n = 0; n < imgArray.size(); n++) {
                    imgList.add(imgArray.optString(n));
                }
                goods.setImgList(imgList);
            }
        }
 
        if (item.optBoolean("include_mkt"))
            goods.setTkMktStatus("1");
        else
            goods.setTkMktStatus("0");
 
        if (item.optBoolean("include_dxjh"))
            goods.setIncludeDxjh(1);
 
        goods.setSellerId(item.optLong("seller_id"));
        goods.setShopTitle(item.optString("shop_title"));
        goods.setTitle(item.optString("title"));
        goods.setProvcity(item.optString("provcity"));
 
        if (!StringUtil.isNullOrEmpty(item.optString("level_one_category_id"))) {
            goods.setRootCatId(item.optInt("level_one_category_id"));
        }
        goods.setRootCategoryName(item.optString("level_one_category_name"));
 
        if (!StringUtil.isNullOrEmpty(item.optString("category_id"))) {
            goods.setLeafCatId(item.optInt("category_id"));
        }
        goods.setLeafName(item.optString("category_name"));
 
        goods.setTkRate(new BigDecimal(item.optString("commission_rate")).divide(new BigDecimal(100)));
        goods.setTotalNum(1000);
        goods.setUserType(item.optInt("user_type"));
        goods.setUserTypeName("");
        goods.setZkPrice(new BigDecimal(item.optString("zk_final_price")));
 
        if (item.optBoolean("include_dxjh")) {
            goods.setDxjhInfo(item.optString("info_dxjh"));
        }
 
        if (StringUtil.isNullOrEmpty(goods.getCouponInfo())) {// 无券
            goods.setTkCommFee(goods.getZkPrice().multiply(goods.getTkRate()).divide(new BigDecimal(100)));
        } else if (goods.getZkPrice().compareTo(goods.getCouponStartFee()) >= 0// 有券
                && goods.getZkPrice().compareTo(goods.getCouponAmount()) >= 0) {
            BigDecimal finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount());
            goods.setTkCommFee(finalPrice.multiply(goods.getTkRate()).divide(new BigDecimal(100)));
        } else {
            goods.setTkCommFee(new BigDecimal(0));
        }
        if (!StringUtil.isNullOrEmpty(item.optString("reserve_price")))
            goods.setReservePrice(new BigDecimal(item.optString("reserve_price")));
        goods.setTotalFee(new BigDecimal("0"));
        // 推荐语
        goods.setDescription(item.optString("item_description"));
 
        goods = loadYuShouInfo(goods, item);
        return goods;
    }
 
    public static Date getTaoBaoSystemTime() {
        Map<String, String> map = new HashMap<>();
        map.put("method", "taobao.time.get");
        try {
            JSONObject json = TaoKeBaseUtil.baseRequest(map, false);
            String time = json.optJSONObject("time_get_response").optString("time");
            return new Date(TimeUtil.convertToTimeTemp(time, "yyyy-MM-dd HH:mm:ss"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
 
    public static void main(String[] args) {
        TaoLiJinReportDTO dto = taolijinReport("eC2%2FoV8gigdzVO5CvuRDjDVC0SEP1L7d", new TaoKeAppInfo("27743325", "527a23554f71557d7b786bc479fcd5fe"));
        System.out.println(dto);
    }
 
}