|
@@ -1,10 +1,19 @@
|
|
|
-using Microsoft.AspNetCore.Http.Metadata;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Http.Metadata;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using Newtonsoft.Json;
|
|
|
using Qiniu.Util;
|
|
|
+using StackExchange.Profiling.Internal;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Expressions;
|
|
|
+using System.Net;
|
|
|
+using System.Net.Http;
|
|
|
+using System.Net.Http.Json;
|
|
|
+using System.Security.Cryptography;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using ZhonTai.Admin.Core.Attributes;
|
|
@@ -19,12 +28,17 @@ using ZhonTai.Admin.Repositories.KuaKe;
|
|
|
using ZhonTai.Admin.Repositories.Project;
|
|
|
using ZhonTai.Admin.Repositories.ProjectLink;
|
|
|
using ZhonTai.Admin.Services.DiTuiAPI.Dto;
|
|
|
+using ZhonTai.Admin.Services.DiTuiAPI.Dto.ObserveDto;
|
|
|
using ZhonTai.Admin.Services.Notice.Dto;
|
|
|
using ZhonTai.Admin.Services.Project;
|
|
|
using ZhonTai.Admin.Services.ProjectLink.Dto;
|
|
|
using ZhonTai.Admin.Services.ProjectStat.Dto;
|
|
|
using ZhonTai.DynamicApi;
|
|
|
using ZhonTai.DynamicApi.Attributes;
|
|
|
+using System.Reactive;
|
|
|
+using System.Security.Cryptography.Xml;
|
|
|
+using ZhonTai.Common.Helpers;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
{
|
|
@@ -699,6 +713,157 @@ namespace ZhonTai.Admin.Services.DiTuiAPI
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 监测
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet]
|
|
|
+ [AllowAnonymous]
|
|
|
+ [NoOprationLog]
|
|
|
+ public string Observe(ObserveInput input)
|
|
|
+ {
|
|
|
+ string postUrl = "https://api.ads.heytapmobi.com/api/uploadActiveData";
|
|
|
+
|
|
|
+ TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
|
+ long timestamp = Convert.ToInt64(ts.TotalMilliseconds);
|
|
|
+ string salt = "e0u6fnlag06lc3pl";
|
|
|
+ ObservePostData postData = new ObservePostData();
|
|
|
+
|
|
|
+ postData.imei = input.Imei;
|
|
|
+ postData.requestId = input.ReqId;
|
|
|
+ postData.mac = "";
|
|
|
+ postData.clientIp = "";
|
|
|
+ postData.timestamp = timestamp;
|
|
|
+ postData.pkg = input.Pkg;
|
|
|
+ postData.dataType = 15;
|
|
|
+ postData.payId = "";
|
|
|
+ //postData.customType = "";
|
|
|
+ postData.channel = 1;
|
|
|
+ postData.type = 1;
|
|
|
+ postData.appType = 1;
|
|
|
+ //postData.payAmount = 100;
|
|
|
+ postData.ascribeType = 1;
|
|
|
+ postData.adId = input.AdId;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ string contents = postData.ToJson() + timestamp + salt;
|
|
|
+ string signature = this.GenerateMD5(contents);
|
|
|
+
|
|
|
+ var resultJson = this.JsonPostUrl(postUrl, signature, timestamp, postData.ToJson());
|
|
|
+ //JsonReader reader = new JsonTextReader(new StringReader(resultJson));
|
|
|
+
|
|
|
+ //JObject jo = JObject.Parse(resultJson);
|
|
|
+ //string[] values = jo.Properties().Select(item => item.Value.ToString()).ToArray();
|
|
|
+ //ObserveResult result = (ObserveResult)JsonHelper.Deserialize(resultJson);
|
|
|
+ //string reutrn = "123";
|
|
|
+ return resultJson;
|
|
|
+ }
|
|
|
+
|
|
|
+ private string JsonPostUrl(string url, string signature, long timestamp, string postData)
|
|
|
+ {
|
|
|
+ string result = "";
|
|
|
+
|
|
|
+ HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
|
|
+
|
|
|
+ req.Method = "POST";
|
|
|
+
|
|
|
+ // req.TimeOut = "800";//设置请求超时时间,单位为毫秒
|
|
|
+ req.Headers.Add("signature", signature);
|
|
|
+ req.Headers.Add("timestamp", timestamp.ToString());
|
|
|
+ req.ContentType = "application/json";
|
|
|
+
|
|
|
+ byte[] data = Encoding.UTF8.GetBytes(postData);
|
|
|
+
|
|
|
+ req.ContentLength = data.Length;
|
|
|
+
|
|
|
+ using (Stream reqStream = req.GetRequestStream())
|
|
|
+ {
|
|
|
+ reqStream.Write(data, 0, data.Length);
|
|
|
+
|
|
|
+ reqStream.Close();
|
|
|
+ }
|
|
|
+
|
|
|
+ HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
|
|
+
|
|
|
+ Stream stream = resp.GetResponseStream();
|
|
|
+
|
|
|
+ //获取响应内容
|
|
|
+ using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
|
|
+ {
|
|
|
+ result = reader.ReadToEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private string HttpPost(string url,string signature, long timestamp, string content)
|
|
|
+ {
|
|
|
+ string getAccessToken = "";
|
|
|
+ HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
|
|
+ req.Headers.Add("signature",signature);
|
|
|
+ req.Headers.Add("timestamp", timestamp.ToString());
|
|
|
+ req.Method = "POST";
|
|
|
+ req.ContentType = "application/json";
|
|
|
+
|
|
|
+ //#region 添加Post 参数
|
|
|
+ byte[] data = Encoding.UTF8.GetBytes(content);
|
|
|
+ req.ContentLength = data.Length;
|
|
|
+ using (Stream reqStream = req.GetRequestStream())
|
|
|
+ {
|
|
|
+ reqStream.Write(data, 0, data.Length);
|
|
|
+ reqStream.Close();
|
|
|
+ }
|
|
|
+ //#endregion
|
|
|
+
|
|
|
+ HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
|
|
+ Stream stream = resp.GetResponseStream();
|
|
|
+ //获取响应内容
|
|
|
+ using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
|
|
|
+ {
|
|
|
+ getAccessToken = reader.ReadToEnd();
|
|
|
+ reader.Close();
|
|
|
+ }
|
|
|
+ JObject getToken = (JObject)JsonConvert.DeserializeObject(getAccessToken);
|
|
|
+
|
|
|
+ // 同样根据接口规则去取得返回Token
|
|
|
+ string getTheToken = getToken["{access_token}"].ToString();
|
|
|
+ return "";
|
|
|
+ // 后续操作参上GET
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private string GenerateMD5(string txt)
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ using (MD5 mi = MD5.Create())
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ byte[] buffer = Encoding.Default.GetBytes(txt);
|
|
|
+
|
|
|
+ //开始加密
|
|
|
+
|
|
|
+ byte[] newBuffer = mi.ComputeHash(buffer);
|
|
|
+
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+
|
|
|
+ for (int i = 0; i < newBuffer.Length; i++)
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ sb.Append(newBuffer[i].ToString("x2"));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return sb.ToString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 判断字符串是否是手机号
|
|
|
/// </summary>
|