From c9fdff7d45ae118eac10397d8f34661e9f2e968a Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 12 一月 2022 10:28:18 +0800 Subject: [PATCH] 礼金bug修复 --- facade-lijin/src/main/java/com/ks/lijin/utils/taobao/TaoKeApiUtil.java | 199 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 197 insertions(+), 2 deletions(-) diff --git a/facade-lijin/src/main/java/com/ks/lijin/utils/taobao/TaoKeApiUtil.java b/facade-lijin/src/main/java/com/ks/lijin/utils/taobao/TaoKeApiUtil.java index 9b47b9d..17b9c78 100644 --- a/facade-lijin/src/main/java/com/ks/lijin/utils/taobao/TaoKeApiUtil.java +++ b/facade-lijin/src/main/java/com/ks/lijin/utils/taobao/TaoKeApiUtil.java @@ -1,6 +1,7 @@ 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; @@ -80,12 +81,162 @@ 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 "DAILY_DRAW_ITEM_ABOVE_LIMIT": 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(Integer.parseInt(msgCode), root.toString()); + 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.report"); + map.put("adzone_id", app.getPid().split("_")[3]); + 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_report_response"); + + if (root != null && root.optBoolean("result_success")) { + JSONObject modelJson = root.optJSONObject("model").optJSONObject("extra"); + if (modelJson != null && modelJson.size() > 0) { + TaoLiJinReportDTO report = new TaoLiJinReportDTO(); + report.setWin_amount(new BigDecimal(modelJson.optString("win_sum_amt"))); + report.setWin_num(modelJson.optInt("win_pv")); + report.setRefund_amount(new BigDecimal(modelJson.optString("refund_sum_amt"))); + report.setRefund_num(modelJson.optInt("refund_num")); + report.setAlipay_amount(new BigDecimal(modelJson.optString("alipay_amt"))); + report.setUse_amount(new BigDecimal(modelJson.optString("use_sum_amt"))); + report.setUse_num(modelJson.optInt("use_num")); + report.setUnfreeze_amount(new BigDecimal(modelJson.optString("remaining_amt"))); + report.setUnfreeze_num(modelJson.optInt("remaining_num")); + report.setPre_commission_amount(new BigDecimal(modelJson.optString("pre_pub_share_fee_for_disp"))); + return report; + } + } +// 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 TaoLiJinDTO createLieBianTaoLiJin(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.lbtlj.create"); + map.put("adzone_id", app.getPid().split("_")[3]); + map.put("item_id", auctionId + ""); + //娣樼ぜ閲戞�讳釜鏁� + map.put("rights_num", totalNum + ""); + //瑁傚彉娣樼ぜ閲戞�讳釜鏁� + map.put("task_rights_num", totalNum + ""); + //瑁傚彉鍗曚釜娣樼ぜ閲戦潰棰濓紝鏀寔涓や綅灏忔暟锛屽崟浣嶅厓 + map.put("task_rights_per_face", "1.01"); + //瑁傚彉娣樼ぜ閲戦個璇蜂汉鏁� + map.put("invite_num", "2"); + //瑁傚彉娣樼ぜ閲戦個璇锋椂闀匡紱鍗曚綅锛氬垎閽燂紱鏈�澶�120鍒嗛挓 + map.put("invite_time_limit", "60"); + + + map.put("name", name); + map.put("user_total_win_num_limit", "1"); + map.put("security_switch", "false"); + map.put("rights_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"); + } + + map.put("accept_start_time", TimeUtil.getGernalTime(sendStartTime.getTime(), "yyyy-MM-dd HH:mm:ss")); + map.put("accept_end_time", TimeUtil.getGernalTime(sendEndTime.getTime(), "yyyy-MM-dd HH:mm:ss")); + + + 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(result); + 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 "DAILY_DRAW_ITEM_ABOVE_LIMIT": + 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()); } } } @@ -137,8 +288,9 @@ 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())) + 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); @@ -237,6 +389,7 @@ 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(); @@ -579,6 +732,48 @@ 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); + TaoKeAppInfo app = new TaoKeAppInfo("24980167", "e0a2e05deabf5ce039b52e5b492d5382", "mm_124933865_56750082_19511350325"); + + Long auctionId = 648785782467L; + String name = "瑁傚彉娣樼ぜ閲�"; + BigDecimal perface = new BigDecimal(1); + int totalNum = 1; + Date sendStartTime = new Date(); + Date sendEndTime = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 4L); + Date useStartTime = sendStartTime; + Date useEndTime = sendEndTime; + + try { + createLieBianTaoLiJin(auctionId, name, perface, totalNum, + sendStartTime, sendEndTime, useStartTime, useEndTime, app); + } catch (LiJinAccountException e) { + e.printStackTrace(); + } catch (LiJinAmountException e) { + e.printStackTrace(); + } catch (LiJinException e) { + e.printStackTrace(); + } catch (LiJinGoodsException e) { + e.printStackTrace(); + } + } + } -- Gitblit v1.8.0