old_flsystem/类库/Api.Framework/Cps/douyin_verify.cs

219 lines
9.0 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
using Api.Framework.Model;
using CsharpHttpHelper;
using DevExpress.XtraEditors;
using EO.Base;
using EO.WebBrowser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using UI.Framework.Forms;
namespace Api.Framework.Cps
{
public partial class douyin_verify : BaseForm
{
private string username;
private fl_cps_member cps;
public douyin_verify(string username)
{
InitializeComponent();
this.username = username;
}
private void douyin_verify_Load(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(username))
this.Close();
cps = CpsClient.Members.FirstOrDefault(f => f.username == username && f.cpstype == Enums.CpsType.);
if (cps == null)
this.Close();
var accountName = Guid.NewGuid().ToString("N");
EO.WebEngine.Engine engine = EO.WebEngine.Engine.Create(accountName);
engine.Options.CachePath = HttpExtend.MapPath($"Cache\\Cookies\\{accountName}");
webView1.Engine = engine;
EO.Base.Runtime.Exception += Runtime_Exception;
//webControl1.WebView.TitleChanged += WebView_TitleChanged;
webView1.LoadCompleted += WebView_LoadCompleted;
webView1.NewWindow += WebView_NewWindow;
var sHandler = new SampleHandler();
sHandler.JsonAction += SHandler_JsonAction;
webControl1.WebView.RegisterResourceHandler(sHandler);//注册自定义资源处理程序
}
catch (Exception ex)
{
}
}
private void SHandler_JsonAction(string cookies, string arg2, string arg3, string arg4)
{
try
{
if (!string.IsNullOrWhiteSpace(cookies))
{
cps.cookies = cookies;
var api = CpsClient.CreateDouyinRequest(cps);
var end_time = DateTime.Now;
var start_time = end_time.AddHours(-1);
try
{
var order = api.DownOrder(start_time, end_time, 1, Enums.DouyinQueryOrderType.);
cps.online = true;
ApiClient.GetSession().SaveOrUpdate(cps);
EventClient.OnEvent("", "抖音验证成功");
//this.Invoke(new System.Action(() =>
//{
this.DialogResult = DialogResult.OK;
//}));
}
catch (Exception ex)
{
}
}
}
catch (Exception ex)
{
}
}
private void WebView_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
try
{
var ck = webControl1.WebView.Engine.CookieManager.GetCookies().ToString();
var ck1 = Regex.Replace(ck, "path=/", "").Replace("\r\n", "");
//Console.WriteLine("------- " + e.Url);
if (e.Url.Contains("www.baidu.com"))
{
var cookice = cps.cookies;
var keyValue = cookice.Split(';');
for (int i = 0; i < keyValue.Length; i++)
{
var data = keyValue[i].Split('=');
if (data.Length == 2)
{
webControl1.WebView.Engine.CookieManager.SetCookie("https://buyin.jinritemai.com/dashboard/dataCenter/order", new EO.WebEngine.Cookie(data[0].Trim(), data[1].Trim()));
}
}
webView1.LoadUrl("https://buyin.jinritemai.com/dashboard");
}
else if (e.Url == "https://buyin.jinritemai.com/dashboard")
{
webView1.LoadUrl("https://buyin.jinritemai.com/dashboard/dataCenter/order");
}
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
private void Runtime_Exception(object sender, ExceptionEventArgs e)
{
e.ShowExceptionDialog = false;
}
private void WebView_NewWindow(object sender, NewWindowEventArgs e)
{
webView1.LoadUrl(e.TargetUrl);
}
#region Response 20210321
internal class SampleHandler : ResourceHandler
{
private static int num = 1;
private static bool IsRun = false;
public event Action<string, string, string, string> JsonAction;
//如果使用此方式,将完全转移嫁接,包括真实请求,需要自己模拟请求,
public const string SampleUrlPrefix = "sample://";
public const string EmbeddedPageUrl = "sample://embedded_page";
//此方法判断是否自定义处理响应
public override bool Match(Request request)
{
var cookies = Regex.Replace(request.Cookies.ToString(), "path=/", "").Replace("\r\n", "");
Debug.WriteLine("*** " + request.Url);
//https://verify.snssdk.com/captcha/get?lang=zh&app_name=&h5_sdk_version=2.26.2&sdk_version=3.5.2&iid=0&did=0&device_id=0&ch=web_text&aid=2631&os_type=2&mode=&tmp=1646209585986&platform=pc&webdriver=undefined&fp=verify_l09aojjx_ZYrkkHpy_VjiQ_4DtQ_BP9J_prQIB7hNThGm&type=verify&detail=329dZ9*0HUUTxcZ*3PeYAZmmzO31ayBNAH2aY4YrPAzwG9HvIR0aEkUBjvCZYcIs1rPMjWv57a9yuKWP4Iq*dMdU6pKa8ddOK4hwQKsgI675G7Z0gr2bfMX4jmFVgvn05uvQSOBIXZxI3F7C3kht4ftX5SSQfaCapLMMM4-ToqtjEuBiYTM31yZefCcUxaoxur*eXATelW0noYZvMt7n-J8q2i-Uw3b8gtwHo4Y0EydfCX-IcJ8yqfqCsVdh50Xvcgs-jn15g-obBVNda3Z7x6n5olZlO3pV0yXHdp5B2IZxofobV-fIC9P*x0HG6WVXrsJns3YY33tG12irfIAXOWpmBbs96LmUAuLueEsB60ocppfLzbPz3iBktHFIKT4xcTogaL6TV9CDF2kDE0vO1Gg6*3f7ViuSiV10vySAsjXBfpI.&server_sdk_env=%7B%22idc%22:%22lf%22,%22region%22:%22CN%22,%22server_type%22:%22business%22%7D&subtype=slide&challenge_code=1105&os_name=windows&h5_check_version=3.5.2
if (request.Url.Contains("buyin.jinritemai.com/api/author/order/details"))
{
if (num >= 2)
{
JsonAction.Invoke(cookies, "", "", "");
}
num++;
}
else if (request.Url.Contains("verify.snssdk.com/captcha/get?"))
{
//return true;
}
else
{
}
return false;
}
//如果自定义响应,则在这里处理请求,并返回要显示的信息
public override void ProcessRequest(Request request, EO.WebBrowser.Response response)
{
var cookies = Regex.Replace(request.Cookies.ToString(), "path=/", "").Replace("\r\n", "");
/*
{"code":200,"data":{"challenge_code":99999,"codifica":"true","cyfreso":17,"host":"","id":"f2f49d6eb42ff02d7542bcec6044104fcd2ef111","mode":"slide","question":{"url1":"https://p6-catpcha.byteimg.com/tos-cn-i-188rlo5p4y/7118a15982b44c6c8e6d1980bf948dcf~tplv-188rlo5p4y-2.jpeg","url2":"https://p6-catpcha.byteimg.com/tos-cn-i-188rlo5p4y/b4895857a8004988a814223f0fa42d70~tplv-188rlo5p4y-1.png","backup_url1":["https://p3-catpcha.byteimg.com/tos-cn-i-188rlo5p4y/7118a15982b44c6c8e6d1980bf948dcf~tplv-188rlo5p4y-2.jpeg","https://p9-catpcha.byteimg.com/tos-cn-i-188rlo5p4y/7118a15982b44c6c8e6d1980bf948dcf~tplv-188rlo5p4y-2.jpeg"],"backup_url2":["https://p3-catpcha.byteimg.com/tos-cn-i-188rlo5p4y/b4895857a8004988a814223f0fa42d70~tplv-188rlo5p4y-1.png","https://p9-catpcha.byteimg.com/tos-cn-i-188rlo5p4y/b4895857a8004988a814223f0fa42d70~tplv-188rlo5p4y-1.png"],"tip_y":41},"region":"","version":2},"message":"验证通过"}
*/
var http = new HttpHelper();
var item = http.GetItem(request.Url, cookies);
var result = http.GetHtml(item);
base.ProcessRequest(request, response);
}
}
#endregion
private void douyin_verify_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (!cps.online)
{
if (XtraMessageBox.Show("当前未完成验证,是否取消验证?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
e.Cancel = true;
else
EventClient.OnEvent("", "放弃抖音手动验证");
}
}
catch (Exception ex)
{ }
}
}
}