Browse Source

cps接口支持多渠道入参

dodo hold 1 year ago
parent
commit
3858847792

+ 92 - 0
molilian.api/Controllers/public/CpsController.cs

@@ -0,0 +1,92 @@
+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;
+using static dodohold.core.ZTOExpress.CreateOrderArgs;
+using MySqlX.XDevAPI;
+
+namespace molilian.api.Controllers
+{
+    [ApiController]
+    [Route("[controller]/[action]")]
+    public class CpsController : ControllerBase
+    {
+
+        protected IHttpContextAccessor _accessor;
+        public CpsController(IHttpContextAccessor accessor)
+        {
+            _accessor = accessor;
+        }
+
+        /// <summary>
+        /// oppo调用
+        /// </summary>
+        /// <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> getLink([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
+        {
+            var channel = form.Read("c", string.Empty);
+            var ip = form.Read("ip", string.Empty);
+            var oaid = form.Read("oaid", string.Empty);
+
+#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);
+            }
+
+
+#endif 
+            return await UnionCpsCore.UnionCpsAsync(channel, ip, oaid);
+        }
+
+        [HttpPost]
+        public async Task<ActionResult> unsafeGetLink([FromBody] JsonElement form)
+        {
+            var channel = form.Read("c", string.Empty);
+            var ip = form.Read("ip", string.Empty);
+            var oaid = form.Read("oaid", string.Empty);
+#if DEBUG
+            ip = "127.0.0.1";
+            oaid = "test-oaid";
+#endif
+            return await UnionCpsCore.UnionCpsAsync(channel, ip, oaid);
+        }
+
+
+    }
+}

File diff suppressed because it is too large
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 89 - 1
molilian.core/Core/cps/UnionCpsCore.cs

@@ -42,7 +42,95 @@ namespace molilian.core
         }
 
         #region CPS 相关 
-        public static async Task<APIResult> CpsCouponAsync(string channel, string ip, string oaid)
+        public static async Task<APIResult> UnionCpsAsync(string channelStr, string ip, string oaid)
+        {
+            var channel_list = channelStr.Split(',');
+            List<dynamic> list = new List<dynamic>();
+            foreach (var channel in channel_list)
+            {
+                var result = await CpsCouponAsync(channel, ip, oaid);
+                list.Add(new
+                {
+                    result.success,
+                    result.message,
+                    result.title,
+                    result.deeplink_url,
+                    result.token,
+                    result.channel,
+                });
+            }
+
+            return new APIResult(new
+            {
+                data = list,
+            });
+        }
+
+        public static async Task<UnionCpsDTO> CpsCouponAsync(string channel, string ip, string oaid)
+        {
+            UnionCpsDTO result = GetFormattedObject(channel, ip, oaid);
+            if (string.IsNullOrEmpty(result.channel))
+            {
+                result.success = false;
+                result.message = "放弃转链";
+                result.reason = "无效渠道";
+                _ = TkLogCore.CpsLogAsync(result);
+                return result;
+            }
+
+            var config = TkConfigCore.Get();
+            //============================== 放弃转链-地区过滤 ==============================
+            if (CpsShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
+            {
+                result.success = false;
+                result.message = "流量控制";
+                result.reason = reason;
+                _ = TkLogCore.CpsLogAsync(result);
+                return result;
+            }
+
+            var account = CpsPoolCore.GetOne(result.channel);
+            if (account == null)
+            {
+                result.success = false;
+                result.message = "放弃转链";
+                result.reason = "没有匹配账号";
+                _ = TkLogCore.CpsLogAsync(result);
+                return result;
+            }
+            result.accountId = account.id;
+            result.accountName = account.name;
+            result.deeplink_url = account.deeplink;
+            result.token = account.token;
+            result.category = account.category;
+            result.pid = account.pid;
+            result.title = account.title;
+            result.success = true;
+            result.message = "OK";
+
+            _ = TkLogCore.CpsLogAsync(result);
+            return result;
+            //return new APIResult(new
+            //{
+            //    result.success,
+            //    result.message,
+            //    result.reason,
+            //    result.channel,
+            //});
+            //return new APIResult(new
+            //{
+            //    result.success,
+            //    result.message,
+            //    result.title,
+            //    result.deeplink_url,
+            //    result.token,
+            //    result.channel,
+            //});
+        }
+
+
+
+        public static async Task<APIResult> CpsCouponAsync22(string channel, string ip, string oaid)
         {
             UnionCpsDTO result = GetFormattedObject(channel, ip, oaid);
             if (string.IsNullOrEmpty(result.channel))

+ 25 - 1
molilian.core/Core/taoke/UnionCouponCore.cs

@@ -22,8 +22,32 @@ namespace molilian.core
                     return await JdCouponAsync(content, dplink, ip, oaid);
                 default:
                     if (!string.IsNullOrEmpty(content.Trim()))
+                    {
                         return await UnionCpsCore.TbtCouponAsync(content, channel, ip, oaid);
-                    return await UnionCpsCore.CpsCouponAsync(channel, ip, oaid);
+                    }
+                    var result = await UnionCpsCore.CpsCouponAsync(channel, ip, oaid);
+                    if (result.success)
+                    {
+                        return new APIResult(new
+                        {
+                            result.success,
+                            result.message,
+                            result.title,
+                            result.deeplink_url,
+                            result.token,
+                            result.channel,
+                        });
+                    }
+                    else
+                    {
+                        return new APIResult(new
+                        {
+                            result.success,
+                            result.message,
+                            result.reason,
+                            result.channel,
+                        });
+                    }
             }
 
         }

+ 5 - 2
molilian.core/Core/tool/DeeplinkParseCore.cs

@@ -232,6 +232,7 @@ namespace molilian.core
                             {
                                 case "redu":
                                     string deeplink_url = await PluginDyParseAsync(text, val, result);
+
                                     if (!string.IsNullOrEmpty(deeplink_url))
                                     {
                                         result.itemName = prompt_text;
@@ -392,8 +393,10 @@ namespace molilian.core
                 var ts2 = now - result.create_time;
                 result.elapsedTime2 = (int)ts2.TotalMilliseconds;
                 result = await DyUnionPlus.DyParseAsync(account, matchText, result, cancellationToken);
-                //result.deeplink_url = result.deeplink_url.Replace("snssdk1128://", "snssdk561124://");
-
+                if (!"3B191CFA4C6B48F9BA459E915B57743BEC7D424979CC9C51BCAD0C245B1C7BA2".Equals(oaid))
+                {
+                    result.deeplink_url = result.deeplink_url.Replace("snssdk1128://", "snssdk561124://");
+                }
                 var ts3 = DateTime.Now - now;
                 result.elapsedTime3 = (int)ts3.TotalMilliseconds;
             }

Some files were not shown because too many files changed in this diff