using dodohold.core; using Spire.Pdf.Xmp; using System.Data; using System.Drawing.Printing; using System.Text.Json; namespace molilian.core { public partial class AlimamaPlus { private const string base_orders_url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json"; public int GetHistoryOrders(int sleep) { DateTime endTime = DateTime.Now; DateTime startTime = endTime.AddDays(-90); ////找出数据库最新的一天 //var last = new DBContext.Table("tk_order_details") // .Order("modifiedTime DESC") // .Get("accountId=@accountId", new { accountId = _accountId }); //if (last != null) //{ // startTime = last.modifiedTime; //} //当日往前查询 return GetTkOrders(startTime, endTime, DateTime.MinValue, false, sleep); } public int GetIncyOrders(int sleep) { DateTime endTime = DateTime.Now; DateTime startTime = endTime.AddDays(-1); //找出数据库最新的一天 var last = new DBContext.Table("tk_order_details") .Order("modifiedTime DESC") .Get("accountId=@accountId", new { accountId = _accountId }); DateTime last_modifiedTime = DateTime.MinValue; if (last != null) { startTime = last.modifiedTime; last_modifiedTime = last.modifiedTime; } //当日往前查询 return GetTkOrders(startTime, endTime, last_modifiedTime, true, sleep); } public int GetTkOrders(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100) { // 确保 startTime 小于 endTime if (startTime > endTime) { (startTime, endTime) = (endTime, startTime); } int pageNo = 1; string positionIndex = string.Empty; int pageSize = 20; bool hasNext = true; int total = 0; while (hasNext) { var ts = DateTime.Now.Convert2UnixTimestamp(); //string jumpType = pageNo == 1 ? "0" : desc ? "1" : "-1"; string jumpType = desc ? pageNo == 1 ? "0" : "1" : "-1"; //string queryType = "1"; string queryType = "4"; string url = $"{base_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&jumpType={jumpType}&tkTradeId=&positionIndex={positionIndex}"; var client = new WebClientUtility().SetContentType("application/json;charset=utf-8") .AddHeaders("X-Requested-With", "XMLHttpRequest") .AddHeaders("Cookie", _cookies); #if DEBUG #else client.Proxy = _proxy; #endif if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent; var response = client.Request(url); if (response.ResponseException != null) { new LoggerLibrary("api_error", "fail") .Info(response.ResponseException.Message, response.ResponseException.StackTrace) .Save(); throw response.ResponseException; } var body = response.Body(); JsonElement data; try { var root = body.Convert2JsonElement(); var succss = root.Read("success"); data = root.ElementRead("data"); if (!succss) { throw new APIException(body); } } catch (Exception ex) { throw new APIException(body); } using var conn = DBContext.GetOpenConnection(); conn.Open(); try { foreach (var order in data.ElementRead("result").EnumerateArray()) { TkOrderDetailDTO item = order.GetRawText().Convert2Object(); // 处理每个订单数据 item.accountId = _accountId; item.accountName = _accountName; if (last_modifiedTime != DateTime.MinValue && last_modifiedTime.AddMinutes(-2) >= item.modifiedTime) { return total; } int? id = conn.Replace(item); total++; } } catch (Exception ex) { throw; } finally { conn.Dispose(); } pageNo++; hasNext = data.Read("hasNext"); positionIndex = data.Read("positionIndex"); if (sleep > 0) Thread.Sleep(sleep); } return total; } public void GetTkOrders222() { try { string url = "https://media.alimama.com/violationu2/warning_instance_page_v2.json?r=mx_208&toPage=1&pageSize=40¶ms="; var client = new WebClientUtility().SetContentType("application/json;charset=utf-8") .AddHeaders("X-Requested-With", "XMLHttpRequest") .AddHeaders("Cookie", _cookies); client.Proxy = _proxy; if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent; var response = client.Request(url); var body = response.Body(); var root = body.Convert2JsonElement(); int resultCode = root.Read("resultCode", 0); int totalCount = root.PathRead("data.totalCount", 0); bool success = root.Read("success", false); if (!success) { new LoggerLibrary("violationu", "warning_error") .Info(url, body) .Save(); throw new Exception(body); } if (totalCount == 0) return; new LoggerLibrary("violationu", "warning").Info(url, body).Save(); var list = root.ElementRead("data").ElementRead("result").EnumerateArray(); foreach (var data in list) { var violation_commission = data.PathRead("mediaInfo.订单虚假交易违规佣金", 0); new DBContext.Table("alimama_warning") .Fill(data) .Loader("filterRuleId", 0) .Loader("gmtCreate", 0) .Loader("id", 0, "ali_id") .Loader("idStr", string.Empty) .Loader("mediaDimension", 0) .Loader("mediaId", 0) .Loader("mediaInfo.abn_cnt", 0, "abn_cnt") .Add("violation_commission", violation_commission) .Loader("mediaInfo.warning_cnt", 0, "warning_cnt") .Loader("mediaName", string.Empty) .Loader("memberId", 0) .Loader("noticeCategory", string.Empty) .Loader("noticeTemplateId", 0) .Loader("noticeTemplateName", string.Empty) .Loader("orderFile", string.Empty) .Loader("pid", string.Empty) .Loader("punishRuleId", 0) .Loader("riskType", string.Empty) .Loader("roleName", string.Empty) .Loader("ruleLink", string.Empty) .Loader("showOrderDetail", false) .Loader("status", 0, "ali_status") .Loader("warningText", string.Empty) .Add("accountName", _accountName) .Add("status", true) .Add("create_time", DateTime.Now) .Add("last_time", DateTime.Now) .Create(DBContext.InsertType.REPLACE); } } catch (Exception ex) { } } } }