Browse Source

数据监测回传功能

lifa 1 year ago
parent
commit
9523624172

+ 9 - 0
src/platform/ZhonTai.Admin/Domain/Observe/IObserveRepository.cs

@@ -0,0 +1,9 @@
+using ZhonTai.Admin.Core.Repositories;
+
+namespace ZhonTai.Admin.Domain.Observe
+{
+    public interface IObserveRepository : IRepositoryBase<ObserveEntity>
+    {
+
+    }
+}

+ 21 - 0
src/platform/ZhonTai.Admin/Domain/Observe/ObserveEntity.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Entities;
+using FreeSql.DataAnnotations;
+
+namespace ZhonTai.Admin.Domain.Observe
+{
+    /// <summary>
+    /// 平台用户
+    /// </summary>
+    [Table(Name = "ditui_observe")]
+    public class ObserveEntity : EntityTenant
+    {
+        public int Id { get; set; }
+        public string InputString { get; set; }
+        public string OutputString { get; set; }
+    }
+}

+ 19 - 0
src/platform/ZhonTai.Admin/Repositories/Observe/ObserveRepository.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Db.Transaction;
+using ZhonTai.Admin.Domain.Observe;
+using ZhonTai.Admin.Domain.Platform;
+
+namespace ZhonTai.Admin.Repositories.Observe
+{
+    public class ObserveRepository : AdminRepositoryBase<ObserveEntity>, IObserveRepository
+    {
+        public ObserveRepository(UnitOfWorkManagerCloud muowm) : base(muowm)
+        {
+
+        }
+    }
+}

+ 1 - 1
src/platform/ZhonTai.Admin/Services/DiTuiAPI/Dto/ObserveDto/ObserveInput.cs

@@ -73,7 +73,7 @@ namespace ZhonTai.Admin.Services.DiTuiAPI.Dto.ObserveDto
         /// <summary>
         /// 广告ID
         /// </summary>
-        public long AdId { get; set; }
+        public string AdId { get; set; }
         /// <summary>
         /// 广告名称,需要urlencode
         /// </summary>

+ 11 - 11
src/platform/ZhonTai.Admin/Services/DiTuiAPI/Dto/ObserveDto/ObservePostData.cs

@@ -17,19 +17,19 @@ namespace ZhonTai.Admin.Services.DiTuiAPI.Dto.ObserveDto
         //public string ouId { get; set; }
 
         public string requestId { get; set; }
-        public string mac { get; set; }
-        public string clientIp { get; set; }
-        public long timestamp { get; set; }
+        public string? mac { get; set; }
+        public string? clientIp { get; set; }
+        public string timestamp { get; set; }
         public string pkg { get; set; }
-        public int dataType { get; set; }
-        public string payId { get; set; }
-        public int? customType { get; set; }
-        public int channel { get; set; }
-        public int type { get; set; }
-        public int appType { get; set; }
+        public string dataType { get; set; }
+        public string? payId { get; set; }
+        public string? customType { get; set; }
+        public string channel { get; set; }
+        public string type { get; set; }
+        public string appType { get; set; }
         public long? payAmount { get; set; }
-        public int ascribeType { get; set; }
-        public long adId { get; set; }
+        public string ascribeType { get; set; }
+        public string adId { get; set; }
     }
 
     public class ObserveResult

+ 90 - 14
src/platform/ZhonTai.Admin/Services/DiTuiAPI/ProjectsService.cs

@@ -39,6 +39,10 @@ using System.Reactive;
 using System.Security.Cryptography.Xml;
 using ZhonTai.Common.Helpers;
 using NPOI.SS.Formula.Functions;
+using ZhonTai.Admin.Domain.Observe;
+using ZhonTai.Admin.Repositories.Observe;
+using Microsoft.AspNetCore.DataProtection.KeyManagement;
+using System.Runtime.InteropServices;
 
 namespace ZhonTai.Admin.Services.DiTuiAPI
 {
@@ -55,6 +59,7 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
         private ProjectStatRepository _projectStatRepository;
         private ProjectConfigRepository _projectConfigRepository;
         private KuaKeRepository _kuaKeRepository;
+        private ObserveRepository _observeRepository;
 
         public ProjectsService(
             ProjectLinkRepository projectLinkRepository,
@@ -62,7 +67,8 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             ProjectPriceRepository projectPriceRepository,
             ProjectStatRepository projectStatRepository,
             ProjectConfigRepository projectConfigRepository,
-            KuaKeRepository kuaKeRepository
+            KuaKeRepository kuaKeRepository,
+            ObserveRepository observeRepository
             )
         {
             _ProjectLinkRepository = projectLinkRepository;
@@ -71,6 +77,7 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             _projectStatRepository = projectStatRepository;
             _projectConfigRepository = projectConfigRepository;
             _kuaKeRepository = kuaKeRepository;
+            _observeRepository = observeRepository;
         }
 
         /// <summary>
@@ -159,6 +166,7 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
                     if(priceConfig is null)
                     {
                         // 未单独设置佣金抽成 默认抽取 5% 取 一位小数
+                        // 当前只 计算了公司抽成,尚未计算 平台抽成  实际显示金额 应为 结算价格=项目价格-公司默认抽成-平台默认或指定抽成
                         projectItem.Price = (Convert.ToDecimal(maxPrice.ProjectPrice) - ProjectPriceService.GetDrawAmount(Convert.ToDecimal(maxPrice.ProjectPrice),Convert.ToDecimal(5.00))).ToString();
                     }
                     else
@@ -727,32 +735,39 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
             long timestamp = Convert.ToInt64(ts.TotalMilliseconds);
             string salt = "e0u6fnlag06lc3pl";
+            string Base64Key = "XGAXicVG5GMBsx5bueOe4w==";
+            string DecodeBase64Key = Base64Decode(Base64Key);
             ObservePostData postData = new ObservePostData();
 
-            postData.imei = input.Imei;
-            postData.requestId = input.ReqId;
-            postData.mac = "";
-            postData.clientIp = "";
-            postData.timestamp = timestamp;
+            //postData.imei = AESEncryptedString(input.Imei, Base64Key,"");
+            postData.imei = AesEncrypt(input.Imei, Base64Key);
+            //postData.requestId = input.ReqId;
+            //postData.mac = "";
+            //postData.clientIp = "";
+            postData.timestamp = timestamp.ToString();
             postData.pkg = input.Pkg;
-            postData.dataType = 15;
-            postData.payId = "";
+            postData.dataType = "15";
+            //postData.payId = "";
             //postData.customType = "";
-            postData.channel = 1;
-            postData.type = 1;
-            postData.appType = 1;
+            postData.channel = "1";
+            postData.type = "1";
+            postData.appType = "1";
             //postData.payAmount = 100;
-            postData.ascribeType = 1;
+            postData.ascribeType = "1";
             postData.adId = input.AdId;
 
             
 
             string contents = postData.ToJson() + timestamp + salt;
-            string signature = this.GenerateMD5(contents);
+            string signature = this.GenerateMD5($"");
+            string sign2 = this.GenerateMD5("123456");
 
             var resultJson = this.JsonPostUrl(postUrl, signature, timestamp, postData.ToJson());
             //JsonReader reader = new JsonTextReader(new StringReader(resultJson));
-
+            ObserveEntity entity = new ObserveEntity();
+            entity.InputString = input.ToJson();
+            entity.OutputString = resultJson.ToString();
+            var res = _observeRepository.Insert(entity);
             //JObject jo = JObject.Parse(resultJson);
             //string[] values = jo.Properties().Select(item => item.Value.ToString()).ToArray();
             //ObserveResult result = (ObserveResult)JsonHelper.Deserialize(resultJson);
@@ -760,6 +775,67 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
             return resultJson;
         }
 
+        //private string AesEncrypt2(string encrypteStr, string key)
+        //{
+        //    byte[] aesBytes = Encoding.UTF8.GetBytes(encrypteStr);
+        //    byte[] aesKey = new byte[32];
+        //    //直接转
+        //    //Array.Copy(Convert.FromBase64String(key), aesKey, aesKey.Length);
+        //    //当长度不够时,右侧添加空格
+        //    Array.Copy(Encoding.UTF8.GetBytes(key.PadRight(aesKey.Length)), aesKey, aesKey.Length);
+
+        //    using MemoryStream memoryStream = new();
+        //    Rijndael Aes = Rijndael.Create();
+        //    //或者采用下方生成Aes
+        //    //RijndaelManaged Aes = new();
+
+        //    Aes.Mode = CipherMode.ECB;
+        //    Aes.Padding = PaddingMode.PKCS7;
+        //    Aes.KeySize = 128;
+        //    Aes.Key = aesKey;
+        //    using CryptoStream cryptoStream = new(memoryStream, Aes.CreateEncryptor(), CryptoStreamMode.Write);
+        //    cryptoStream.Write(aesBytes, 0, aesBytes.Length);
+        //    cryptoStream.FlushFinalBlock();
+        //    Aes.Clear();
+        //    return Convert.ToBase64String(memoryStream.ToArray());
+        //}
+        public static string Base64Decode(string result)
+        {
+            return Base64Decode(Encoding.UTF8, result);
+        }
+        public static string Base64Decode(Encoding encodeType, string result)
+        {
+            string decode = string.Empty;
+            byte[] bytes = Convert.FromBase64String(result);
+            try
+            {
+                decode = encodeType.GetString(bytes);
+            }
+            catch
+            {
+                decode = result;
+            }
+            return decode;
+        }
+
+        public static string AesEncrypt(string str, string key)
+        {
+            if (string.IsNullOrEmpty(str)) return null;
+            Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
+
+            System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
+            {
+                Key = Encoding.UTF8.GetBytes(key),
+                Mode = System.Security.Cryptography.CipherMode.ECB,
+                Padding = System.Security.Cryptography.PaddingMode.PKCS7
+            };
+
+            System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
+            Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
+
+            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
+        }
+
         private string JsonPostUrl(string url, string signature, long timestamp, string postData)
         {
             string result = "";

+ 16 - 3
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -8842,13 +8842,14 @@
             <param name="EffecDate">状态 2上架 3下架 4暂停</param>
              <returns></returns>    
         </member>
-        <member name="M:ZhonTai.Admin.Services.ProjectStat.ProjectStatService.GetCommission(System.Decimal,System.Decimal,System.Int32)">
+        <member name="M:ZhonTai.Admin.Services.ProjectStat.ProjectStatService.GetCommission(System.Decimal,System.Decimal,System.Int32,System.Decimal)">
             <summary>
             获取佣金
             </summary>
             <param name="price">项目价格</param>
-            <param name="ratio">公司抽成比率,抽成方式是2,则抽成金额</param>
-            <param name="drawType">抽成方式1比率 2佣金</param>
+            <param name="compnayRatio">公司抽成比率,抽成方式是2,则抽成金额</param>
+            <param name="companyDrawWay">抽成方式1比率 2佣金</param>
+            <param name="tenantRatio">平台抽成比率</param>
         </member>
         <member name="P:ZhonTai.Admin.Services.Project.Dto.CompanyDrawInput.DrawRatio">
             <summary>
@@ -8920,6 +8921,11 @@
             抽成价格
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Services.Project.Dto.PriceGetPageOutput_Price.IsExistNextInfo">
+            <summary>
+            是否存在抽成信息 1存在 0不存在
+            </summary>
+        </member>
         <member name="P:ZhonTai.Admin.Services.Project.Dto.ProjectAddInput.Id">
             <summary>
             项目Id
@@ -9100,6 +9106,13 @@
             <param name="input"></param>
             <returns></returns>
         </member>
+        <member name="M:ZhonTai.Admin.Services.Project.ProjectPriceService.GetDrawInfoAsync(ZhonTai.Admin.Services.Project.Dto.DrawInfoInput)">
+            <summary>
+            下次生效信息
+            </summary>
+            <param name="input"></param>
+            <returns></returns>
+        </member>
         <member name="M:ZhonTai.Admin.Services.Project.ProjectPriceService.ExecuteTaskCompanyDraw">
             <summary>
             执行公司抽成任务