| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using Org.BouncyCastle.Ocsp;
- using System.Text.Json;
- using System.Runtime.InteropServices;
- using System.Net;
- using System.Security.Cryptography;
- using Microsoft.AspNetCore.Authentication;
- using TencentCloud.Ecm.V20190719.Models;
- using COSXML.Network;
- using System.Linq;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [Route("[controller]/[action]")]
- public class TkController : ControllerBase
- {
- protected IHttpContextAccessor _accessor;
- public TkController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- /// <summary>
- /// oppo调用
- /// </summary>
- /// <param name="s">正文</param>
- /// <param name="c">渠道。tb/jd</param>
- /// <param name="a">分配的客户端账号</param>
- /// <param name="t">11位时间戳</param>
- /// <param name="sign">签名</param>
- /// <param name="ip">客户的IP</param>
- /// <param name="oaid">客户的唯一ID</param>
- /// <returns></returns>
- [HttpPost]
- public async Task<ActionResult> unionParse([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
- {
- //正文
- var content = form.Read("s", string.Empty);
- var channel = form.Read("c", string.Empty);
- var ip = form.Read("ip", string.Empty);
- var oaid = form.Read("oaid", string.Empty);
- //验证签名
- if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
- {
- return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
- }
- DateTime time1 = t.Convert2Datetime();
- if (time1 < DateTime.Now.AddMinutes(-10))
- {
- return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
- }
- var account = ApiAccountCore.GetOne(a);
- if (account == null)
- {
- return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
- }
- string app_sign = $"{account.api_secret}@{t}".MD5();
- if (sign != app_sign)
- {
- return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
- }
- return await UnionParseCore.UnionParseAsync(content, channel, ip, oaid);
- }
- [HttpPost]
- public async Task<ActionResult> unsafeParse([FromBody] JsonElement form)
- {
- var content = form.Read("s", string.Empty);
- var channel = form.Read("c", string.Empty);
- var ip = form.Read("ip", string.Empty);
- var oaid = form.Read("oaid", string.Empty);
- return await UnionParseCore.UnionParseAsync(content, channel, ip, oaid);
- }
- [HttpPost]
- public async Task<ActionResult> unionCoupon([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
- {
- //正文
- var content = form.Read("s", string.Empty);
- var channel = form.Read("c", string.Empty);
- var ip = form.Read("ip", string.Empty);
- var oaid = form.Read("oaid", string.Empty);
- //验证签名
- if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
- {
- return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
- }
- DateTime time1 = t.Convert2Datetime();
- if (time1 < DateTime.Now.AddMinutes(-10))
- {
- return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
- }
- var account = ApiAccountCore.GetOne(a);
- if (account == null)
- {
- return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
- }
- string app_sign = $"{account.api_secret}@{t}".MD5();
- if (sign != app_sign)
- {
- return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
- }
- return await UnionCouponCore.UnionCouponAsync(content, channel, ip, oaid);
- }
- [HttpPost]
- public async Task<ActionResult> unsafeCoupon([FromBody] JsonElement form)
- {
- var content = form.Read("s", string.Empty);
- var channel = form.Read("c", string.Empty);
- var ip = form.Read("ip", string.Empty);
- var oaid = form.Read("oaid", string.Empty);
- return await UnionCouponCore.UnionCouponAsync(content, channel, ip, oaid);
- }
- /// <summary>
- /// 第三方调用
- /// </summary>
- /// <param name="s"></param>
- /// <param name="s2"></param>
- /// <returns></returns>
- [HttpGet]
- public async Task<ActionResult> parse(string s, string s2 = "", string ip = "", string oaid = "")
- {
- AlimamaPlus alimama = null;
- ip = AlimamaPlus.OppoDecode(ip);
- oaid = AlimamaPlus.OppoDecode(oaid);
- var result = AlimamaPlus.GetFormattedObject(s, ip, oaid);
- string body = "";
- string content = s.UrlDecode();
- string content2 = s2.UrlDecode();
- string account_name = string.Empty;
- result.rawContent = content;
- result.rawContent2 = content2;
- try
- {
- if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = reason;
- _ = TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
- if (account == null)
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "没有匹配账号";
- _ = TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- result.accountId = account.id;
- account_name = account.name;
- alimama = new AlimamaPlus(account);
- if (alimama.ShouldIgnoreOtherAff(s2))
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "其他推广链接";
- _ = TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- result = await alimama.UnionParseAsync(content, result);
- }
- catch (Exception ex)
- {
- if (ex.Message.Contains("A task was canceled"))
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "请求超时";
- }
- else
- {
- new LoggerLibrary("api_error", "parse")
- .Info(s, s2)
- .Info($"【taobao】{account_name}", body)
- .Info(ex.Message, ex.StackTrace)
- .Save();
- NotifyCore.Notify(new NifyMessage
- {
- message = $"【转链接口异常】{account_name}\n{content}\n{content2}\n{body}\n\n{ex.Message}\n{ex.StackTrace}",
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- result.success = false;
- result.message = "放弃转链";
- result.reason = "转链接口异常";
- }
- }
- _ = TkLogCore.LogAsync(result, alimama);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- [HttpGet]
- public ActionResult parse2(string s, string s2 = "", string ip = "", string oaid = "")
- {
- AlimamaPlus alimama = null;
- ip = AlimamaPlus.OppoDecode(ip);
- oaid = AlimamaPlus.OppoDecode(oaid);
- var result = AlimamaPlus.GetFormattedObject(s, ip, oaid);
- string body = "";
- string content = s.UrlDecode();
- string content2 = s2.UrlDecode();
- string account_name = string.Empty;
- result.rawContent = content;
- result.rawContent2 = content2;
- try
- {
- if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = reason;
- _ = TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
- if (account == null)
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "没有匹配账号";
- _ = TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- account_name = account.name;
- alimama = new AlimamaPlus(account);
- if (alimama.ShouldIgnoreOtherAff(s2))
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "其他推广链接";
- _ = TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- alimama.UnionParse(content, ref result);
- //result.ip = ip;
- //result.oaid = oaid;
- }
- catch (Exception ex)
- {
- new LoggerLibrary("api_error", "parse")
- .Info(s, s2)
- .Info($"【taobao】{account_name}", body)
- .Info(ex.Message, ex.StackTrace)
- .Save();
- NotifyCore.Notify(new NifyMessage
- {
- message = $"【转链接口异常】{account_name}\n{content}\n{content2}\n{body}\n\n{ex.Message}\n{ex.StackTrace}",
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- result.success = false;
- result.message = "放弃转链";
- result.reason = "转链接口异常";
- }
- _ = TkLogCore.LogAsync(result, alimama);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.content,
- result.couponAmount,
- result.taoToken,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- [HttpGet]
- public ActionResult jd_parse(string s, string s2 = "", string ip = "", string oaid = "")
- {
- var result = JdUnionPlus.GetFormattedObject(s, ip, oaid);
- string body = "";
- string content = s.UrlDecode();
- string content2 = s2.UrlDecode();
- try
- {
- if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = reason;
- result.rawContent = content;
- result.rawContent2 = content2;
- TkLogCore.LogAsync(result);
- return new APIResult(result);
- }
- var api = DataokeCore.GetOne();
- if (api == null)
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "没有匹配账号";
- result.rawContent = content;
- result.rawContent2 = content2;
- TkLogCore.LogAsync(result);
- return new APIResult(result);
- }
- var account = JdPoolCore.GetOne();
- if (account == null)
- {
- result.success = false;
- result.message = "放弃转链";
- result.reason = "没有匹配账号";
- result.rawContent = content;
- result.rawContent2 = content2;
- TkLogCore.LogAsync(result);
- return new APIResult(result);
- }
- result = DataokeCore.JdParse(result, api, account, content);
- }
- catch (Exception ex)
- {
- new LoggerLibrary("api_error")
- .Info(s, s2)
- .Info("【jd】", body)
- .Info(ex.Message, ex.StackTrace)
- .Save();
- NotifyCore.Notify(new NifyMessage
- {
- message = $"【转链接口异常】\n{content}\n{content2}\n{body}\n\n{ex.Message}\n{ex.StackTrace}",
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- result.success = false;
- result.message = "放弃转链";
- result.reason = "转链接口异常";
- }
- result.rawContent = content;
- result.rawContent2 = content2;
- TkLogCore.LogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.shortLinkurl,
- result.deeplink_url,
- });
- }
- //[HttpGet]
- //public Task<ActionResult> parse3(string s, string s2, string ip = "", string oaid = "")
- //{
- // var result = AlimamaPlus.GetFormattedObject(s, ip, oaid);
- // string body = "";
- // string content = s.UrlDecode();
- // string content2 = s2.UrlDecode();
- // try
- // {
- // if (AlimamaPlus.ShouldIgnoreRequest("", ""))
- // {
- // result.success = false;
- // result.message = "放弃转链";
- // }
- // else
- // {
- // var account = VeapiPoolCore.GetOne();
- // if (account == null)
- // {
- // result.success = false;
- // result.message = "内部错误(500)";
- // }
- // else
- // {
- // var core = new VeapiPlus(account.name, account.key, account.sessionKey);
- // result = core.UnionParse(content);
- // }
- // }
- // }
- // catch (Exception ex)
- // {
- // NotifyCore.Notify(new NifyMessage
- // {
- // message = $"【转链接口异常】\n{body}",
- // priority = NifyMessagePriority.high,
- // tags = ["red_circle"]
- // });
- // result.success = false;
- // result.message = "转链接口异常";
- // }
- // _ = TkLogCore.Log(content, content2, result);
- // return Task.FromResult<ActionResult>(new APIResult(result));
- //}
- [HttpGet("{ignorePercentage}")]
- public ActionResult set_ignore(int ignorePercentage = 0)
- {
- TkConfigCore.Update(ignorePercentage);
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet("{ignorePercentage}")]
- public ActionResult set_jd_ignore(int ignorePercentage = 0)
- {
- TkConfigCore.JdUpdate(ignorePercentage);
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public ActionResult reload()
- {
- ApiAccountCore.Refresh();
- ProxyNodesCore.Refresh();
- DataokeCore.Refresh();
- JdPoolCore.Refresh();
- PangolinPoolCore.Refresh();
- TkConfigCore.Refresh();
- TkPoolCore.Refresh();
- VeapiPoolCore.Refresh();
- return new APIResult(new
- {
- success = true,
- message = "ok",
- });
- }
- [HttpPost]
- public ActionResult updateCookies([FromBody] JsonElement form)
- {
- string cookie = form.Read<string>("cookie", string.Empty);
- var user_agent = _accessor.HttpContext.Request.UserAgent();
- TkPoolCore.UpdateCookies(cookie, user_agent);
- return new APIResult(new
- {
- success = true,
- message = "ok"
- });
- }
- [HttpGet]
- public async Task<ActionResult> dplist([FromQuery] string query = "", [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
- {
- #if DEBUG
- #else
- //验证签名
- if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
- {
- return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
- }
- DateTime time1 = t.Convert2Datetime();
- if (time1 < DateTime.Now.AddMinutes(-10))
- {
- return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
- }
- var account = ApiAccountCore.GetOne(a);
- if (account == null)
- {
- return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
- }
- string app_sign = $"{account.api_secret}@{t}".MD5();
- if (sign != app_sign)
- {
- return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
- }
- if (string.IsNullOrEmpty(query))
- {
- return new APIResult(new { success = false, message = "查询条件不能为空" });
- }
- #endif
- string filter = $"batchId=@query";
- string orderBy = "paid_time ASC";
- var data = new DBContext.Table("tk_order_tracking")
- .Where(filter, new { query })
- .Order(orderBy)
- .Select<TkOrderTrackingDTO>();
- List<object> list = new();
- foreach (var item in data)
- {
- list.Add(new { url = item.deeplinkUrl, count = 1, time = item.exp_time });
- }
- return new APIResult(new
- {
- success = true,
- message = list.Count == 0 ? "none" : "ok",
- count = list.Count,
- data = list,
- });
- }
- [HttpGet]
- public async Task<ActionResult> unsafeParseDpList([FromQuery] string query = "", [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
- {
- string filter = $"batchId=@query";
- var account_list = TkPoolCore.List();
- List<int> account_ids = [];
- if (account_list.Any())
- {
- account_ids = account_list.Where(e => e.enable_fake_click).Select(e => e.id).ToList();
- filter += $" AND accountId IN @account_ids";
- }
- string orderBy = "paid_time ASC";
- var data = new DBContext.Table("tk_order_tracking")
- .Where(filter, new { query, account_ids })
- .Order(orderBy)
- .Select<TkOrderTrackingDTO>();
- List<object> list = [];
- foreach (var item in data)
- {
- list.Add(new { url = item.deeplinkUrl, count = item.click_num, time = item.exp_time });
- }
- return new APIResult(new
- {
- success = true,
- message = list.Count == 0 ? "none" : "ok",
- count = list.Count,
- data = list,
- });
- }
- }
- }
|