781 lines
34 KiB
C#
781 lines
34 KiB
C#
using AllBase;
|
|
using AllBase.Model.Result;
|
|
using CefSharp;
|
|
using CefSharp.WinForms;
|
|
using NaiBa.CefHelper;
|
|
using NaiBa.CefHelper.Handler;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TemuKJD.BaseForms;
|
|
using TemuKJD.Helper;
|
|
using Work;
|
|
|
|
namespace TemuKJD.VDianForms
|
|
{
|
|
public partial class VDianLoginForm : BaseGeneralForm
|
|
{
|
|
public static bool IsRun = false;
|
|
|
|
/// <summary>
|
|
/// 微店进店操作url
|
|
/// </summary>
|
|
public string vDianManageUrl = "https://d.weidian.com/weidian-pc/weidian-loader/#/pc-vue-micro-index/index";
|
|
|
|
/// <summary>
|
|
/// 微店相关接口默认地址
|
|
/// </summary>
|
|
public static string VDianUrl { get; set; } = BaseClass.LoginApiUrl;
|
|
//public static string VDianUrl = "http://192.168.8.191:82/";
|
|
/// <summary>
|
|
/// 微店文件夹目录
|
|
/// </summary>
|
|
//public static string VDianFolder = "/bak";
|
|
public static string VDianFolder = "";
|
|
/// <summary>
|
|
/// 微店授权接口
|
|
/// </summary>
|
|
//http://new.qixiaoke.com/weidian/authorize.php?appkey=691685
|
|
static string vDianApiAuthUrl = VDianUrl + "weidian" + VDianFolder + "/authorize.php"; // ?appkey={appkey}
|
|
/// <summary>
|
|
/// 微店授权成功页面判断部分
|
|
/// </summary>
|
|
static string vDianApiAuthSuccessUrl = "weidian/weidian.php?code=";
|
|
/// <summary>
|
|
/// 1000调用次数接口授权成功页面判断
|
|
/// </summary>
|
|
static string[] vDianMultiApiAuthSuccessUrls = new string[] { "http://weidian.e57.cn/", "http://new.qixiaoke.com/weidian/", "http://wd.6nt.cn" };
|
|
/// <summary>
|
|
/// 微店测试授权接口回调页面(成功页面)
|
|
/// </summary>
|
|
static string vDianApiAuthCodeUrl = VDianUrl + "weidian" + VDianFolder + "/weidian.php"; // ?code={code}&appkey={appkey}
|
|
/// <summary>
|
|
/// 获取所有appkey的地址
|
|
/// </summary>
|
|
static string VDianApiAppKeyListUrl = VDianUrl + "weidian" + VDianFolder + "/wd_list.php";
|
|
/// <summary>
|
|
/// 默认appkey
|
|
/// </summary>
|
|
static string defaultAppKey = "691685";
|
|
|
|
/// <summary>
|
|
/// 全局微店AppKey列表 "691685" 威武宝宝, "691402" 开箱小店
|
|
/// </summary>
|
|
public static List<VDianAppKey> lstVDianAppKey = new List<VDianAppKey>();
|
|
|
|
string vDianBaseUrl = "https://www.weidian.com";
|
|
string vDianLoginUrl = "https://d.weidian.com/loginNew/#/login/loginMain";
|
|
string vDianAuthUrl = "https://weidian.com/pay/member/credential-status.html?essentials=twoParam&redirect=https://d.weidian.com/weidian-pc/pc-vue-item/";
|
|
|
|
/// <summary>
|
|
/// 第三方微店授权url
|
|
/// </summary>
|
|
//string vDianApi2AuthUrl = "https://h5.weidian.com/m/signin/index.html?redirect=https%3a%2f%2fapi.vdian.com%2foauth2%2fauthorize%3fappkey%3d690473%26redirect_uri%3dhttp%3a%2f%2f2up.shuaishou.com%2fwdsc.aspx%26response_type%3dcode%26state%3d123";
|
|
string vDianApi2AuthUrl = "https://h5.weidian.com/m/signin/index.html?redirect=https%3a%2f%2fapi.vdian.com%2foauth2%2fauthorize%3fappkey%3d690473%26redirect_uri%3dhttp%3a%2f%2f2up.shuaishou.com%2fwdsc.aspx%26response_type%3dcode%26state%3d124";
|
|
|
|
string loginType = "";
|
|
List<Cookie> lstCookie = new List<Cookie>();
|
|
VDianShopLoginInfo vDianInfo = null;
|
|
string vDianShopName = "";
|
|
string vDianShopId = "";
|
|
/// <summary>
|
|
/// 微店账户手机号
|
|
/// </summary>
|
|
string phone = "";
|
|
/// <summary>
|
|
/// 微店账户密码
|
|
/// </summary>
|
|
string password = "";
|
|
/// <summary>
|
|
/// 当前要授权的appkey
|
|
/// </summary>
|
|
VDianAppKey appKey = null;
|
|
private ChromiumWebBrowser cefWebBrowser = null;
|
|
|
|
/// <summary>
|
|
/// 获取全部的可授权appkey及状态。
|
|
/// </summary>
|
|
public static void GetVDianAppKeys()
|
|
{
|
|
// 获取所有微店Api接口
|
|
var data = UserLogin.GetSignaturex();
|
|
var html = GetHtml.PostUtf8(VDianApiAppKeyListUrl, data);
|
|
|
|
if (!string.IsNullOrEmpty(html))
|
|
{
|
|
var appkeyArr = html.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
|
if (appkeyArr.Length > 0)
|
|
{
|
|
foreach (var item in appkeyArr)
|
|
{
|
|
var itemArr = item.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
if (itemArr.Length > 1)
|
|
{
|
|
var appkey = lstVDianAppKey.FirstOrDefault(a => a.AppKey == itemArr[0]);
|
|
if (appkey == null)
|
|
lstVDianAppKey.Add(new VDianAppKey() { AppKey = itemArr[0], Status = itemArr[1], GoodsCountStatus = "ok", ImgsCountStatus = "ok", PropCountStatus = "ok" });
|
|
else
|
|
{
|
|
appkey.Status = itemArr[1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 如果获取失败了,赋一个默认appkey
|
|
if (lstVDianAppKey.Count == 0)
|
|
lstVDianAppKey.Add(new VDianAppKey() { AppKey = defaultAppKey, Status = "ok", GoodsCountStatus = "ok", ImgsCountStatus = "ok", PropCountStatus = "ok" });
|
|
}
|
|
|
|
public VDianLoginForm(string _phone = "", string _password = "")
|
|
{
|
|
InitializeComponent();
|
|
phone = _phone;
|
|
password = _password;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 授权等的操作
|
|
/// </summary>
|
|
/// <param name="_vDianInfo">店铺信息</param>
|
|
/// <param name="type">操作类型</param>
|
|
/// <param name="_appKey">appKey</param>
|
|
public VDianLoginForm(VDianShopLoginInfo _vDianInfo, string type = "", VDianAppKey _appKey = null)
|
|
{
|
|
InitializeComponent();
|
|
this.vDianInfo = _vDianInfo;
|
|
this.loginType = type;
|
|
phone = _vDianInfo.Phone;
|
|
password = _vDianInfo.Password;
|
|
appKey = _appKey;
|
|
this.lstCookie = ConvertStringCookieToCefCookie(_vDianInfo.Cookies, "weidian.com");
|
|
}
|
|
|
|
private void ProductMappingVDianLoginForm_Load(object sender, EventArgs e)
|
|
{
|
|
TitleText = this.Text;
|
|
string url = vDianLoginUrl;
|
|
if (loginType == "apiAuth")
|
|
{
|
|
url = vDianApiAuthUrl + "?appkey=" + appKey?.AppKey;
|
|
}
|
|
else if (loginType == "api2Auth")
|
|
{
|
|
url = vDianApi2AuthUrl;
|
|
}
|
|
else if (loginType == "upAuth")
|
|
{
|
|
url = vDianAuthUrl;
|
|
}
|
|
else if (loginType == "mainAuth")
|
|
{
|
|
url = "https://h5.weidian.com/m/shop-certify/status.html";
|
|
}
|
|
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(url, false);
|
|
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
|
|
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
|
var lifeSapnHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
|
|
cefWebBrowser.LifeSpanHandler = lifeSapnHandler;
|
|
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
|
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
|
|
|
|
|
|
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
|
|
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
|
|
cefWebBrowser.Dock = DockStyle.Fill;
|
|
|
|
splitContainer1.Panel1.Controls.Add(cefWebBrowser);
|
|
|
|
if (loginType == "api2Auth")
|
|
{
|
|
cefWebBrowser.SendToBack();
|
|
}
|
|
else
|
|
{
|
|
cefWebBrowser.BringToFront();
|
|
}
|
|
|
|
if (loginType == "apiAuth")
|
|
{
|
|
if (lstCookie != null && lstCookie.Count > 0)
|
|
{
|
|
var cookieManager = cefWebBrowser.RequestContext.GetCookieManager(null);
|
|
foreach (Cookie cookie in lstCookie)
|
|
{
|
|
Task<bool> t = cookieManager.SetCookieAsync(vDianBaseUrl, cookie);
|
|
t.Wait();
|
|
}
|
|
}
|
|
cefWebBrowser.Load(url);
|
|
}
|
|
else if (loginType == "upAuth" || loginType == "mainAuth")
|
|
{
|
|
if (lstCookie != null && lstCookie.Count > 0)
|
|
{
|
|
var cookieManager = cefWebBrowser.RequestContext.GetCookieManager(null);
|
|
foreach (Cookie cookie in lstCookie)
|
|
{
|
|
Task<bool> t = cookieManager.SetCookieAsync(url, cookie);
|
|
t.Wait();
|
|
}
|
|
}
|
|
cefWebBrowser.Load(url);
|
|
}
|
|
else if (loginType == "manage")
|
|
{
|
|
if (lstCookie != null && lstCookie.Count > 0)
|
|
{
|
|
var cookieManager = cefWebBrowser.RequestContext.GetCookieManager(null);
|
|
foreach (Cookie cookie in lstCookie)
|
|
{
|
|
Task<bool> t = cookieManager.SetCookieAsync(url, cookie);
|
|
t.Wait();
|
|
}
|
|
}
|
|
cefWebBrowser.Load(vDianManageUrl);
|
|
}
|
|
else
|
|
{
|
|
cefWebBrowser.Load(url);
|
|
}
|
|
}
|
|
|
|
private void CefWebBrowser_AddressChanged(object sender, AddressChangedEventArgs e)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
textBox1.Text = e.Address;
|
|
this.TitleText = "登录微店 " + e.Address;
|
|
this.Text = "登录微店 " + e.Address;
|
|
}));
|
|
|
|
if (e.Address.Contains("/shopSelect"))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
SelectShop(cefWebBrowser);
|
|
});
|
|
}
|
|
}
|
|
|
|
public static void InputUserNameAndPassword(ChromiumWebBrowser webBrowser, string _phone, string _password)
|
|
{
|
|
// 用户名
|
|
string jsStr = "var txt = document.getElementsByClassName('el-input__inner')[1]; "
|
|
+ "txt.value = '" + _phone + "'; txt.dispatchEvent(new Event('input'));";
|
|
var response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait();
|
|
//Thread.Sleep(1500 + Randomx.GetId(1000));
|
|
Thread.Sleep(500 + Randomx.GetId(500));
|
|
// 密码
|
|
jsStr = "var pass = document.getElementsByClassName('el-input__inner')[2]; "
|
|
+ "pass.value = '" + _password + "'; pass.dispatchEvent(new Event('input'));";
|
|
var response2 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response2.Wait();
|
|
Thread.Sleep(500 + Randomx.GetId(500));
|
|
|
|
jsStr = "document.getElementsByClassName('el-checkbox__inner')[0].click();";
|
|
var response3 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response3.Wait();
|
|
Thread.Sleep(500 + Randomx.GetId(500));
|
|
}
|
|
|
|
public static void ClickLogin(ChromiumWebBrowser webBrowser)
|
|
{ // 获取登录位置后CEF模拟点击
|
|
string code = "function getPos() { var box = document.getElementsByClassName('el-button weidian-button el-button--primary')[0];" +
|
|
"if (box == null) return '0|0';" +
|
|
"var actualLeft = box.offsetLeft;" +
|
|
"var actualTop = box.offsetTop;" +
|
|
"var parent = box.offsetParent;" +
|
|
"while (parent !== null) { actualLeft += parent.offsetLeft; actualTop += parent.offsetTop; parent = parent.offsetParent; }" +
|
|
"return '' + actualLeft + '|' + actualTop;}" +
|
|
"getPos();";
|
|
var task = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(code);
|
|
task.Wait(5000);
|
|
var result = task.Result.Result;
|
|
if (result != null && result.ToString() != "0|0")
|
|
{
|
|
var arr = result.ToString().Split('|');
|
|
if (arr.Length == 2)
|
|
{
|
|
int x = Convert.ToInt32(arr[0]);
|
|
int y = Convert.ToInt32(arr[1]);
|
|
int x1 = x + 50 + new Random(DateTime.Now.Millisecond).Next(50);
|
|
int y1 = y + 10 + new Random(DateTime.Now.Millisecond).Next(10);
|
|
var host = webBrowser.GetBrowser().GetHost();
|
|
//host.SendFocusEvent(true);
|
|
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, false, 1, CefEventFlags.None); // 按下鼠标左键
|
|
Thread.Sleep(70 + new Random(DateTime.Now.Millisecond).Next(50));
|
|
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, true, 1, CefEventFlags.None); // 松开鼠标左键
|
|
Thread.Sleep(500 + new Random(DateTime.Now.Millisecond).Next(500));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 模拟鼠标按键,获取焦点后JS才能提交登录
|
|
var x1 = 100 + Randomx.GetId(100);
|
|
var y1 = 200 + Randomx.GetId(100);
|
|
var host = webBrowser.GetBrowser().GetHost();
|
|
//host.SendFocusEvent(true);
|
|
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, false, 1, CefEventFlags.None); // 按下鼠标左键
|
|
Thread.Sleep(70 + Randomx.GetId(50));
|
|
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, true, 1, CefEventFlags.None); // 松开鼠标左键
|
|
|
|
// 登录
|
|
Thread.Sleep(1500 + Randomx.GetId(1000));
|
|
string jsStr = "var sub = document.getElementsByClassName('el-button weidian-button el-button--primary')[0];"
|
|
+ "sub.click();";
|
|
var response3 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response3.Wait(5000);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点击选择店铺
|
|
/// </summary>
|
|
public static void SelectShop(ChromiumWebBrowser webBrowser)
|
|
{
|
|
Thread.Sleep(1250);
|
|
|
|
var x1 = 320 + Randomx.GetId(70);
|
|
var y1 = 310 + Randomx.GetId(40);
|
|
cefClick(webBrowser, x1, y1);
|
|
|
|
Thread.Sleep(250);
|
|
x1 = 320 + Randomx.GetId(70);
|
|
y1 = 310 + Randomx.GetId(40);
|
|
cefClick(webBrowser, x1, y1);
|
|
}
|
|
|
|
private void AutoLogin()
|
|
{
|
|
if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(phone))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(1000);
|
|
InputUserNameAndPassword(cefWebBrowser, phone, password);
|
|
ClickLogin(cefWebBrowser);
|
|
|
|
Thread.Sleep(30000);
|
|
if (this != null && this.Created && !this.IsDisposed)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
//this.Close();
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void AutoApiAuth()
|
|
{
|
|
if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(phone))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Invoke(new Action(() => { label2.Text = 5 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
Thread.Sleep(1270 + Randomx.GetId(250));
|
|
|
|
Invoke(new Action(() => { label2.Text = 10 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
var x1 = 757 + Randomx.GetId(50);
|
|
var y1 = 250 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
|
|
Invoke(new Action(() => { label2.Text = 15 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
x1 = 643 + Randomx.GetId(50);
|
|
y1 = 123 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
|
|
Invoke(new Action(() => { label2.Text = 25 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
x1 = 700 + Randomx.GetId(50);
|
|
y1 = 244 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
|
|
Invoke(new Action(() => { label2.Text = 35 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
#region 模拟输入用户名和密码
|
|
cefInput(vDianInfo.Phone);
|
|
|
|
Invoke(new Action(() => { label2.Text = 57 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
cefClick(cefWebBrowser, 710 + Randomx.GetId(50), 302 + Randomx.GetId(20));
|
|
|
|
Invoke(new Action(() => { label2.Text = 75 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
cefInput(vDianInfo.Password);
|
|
|
|
Invoke(new Action(() => { label2.Text = 85 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
#endregion
|
|
|
|
x1 = 758 + Randomx.GetId(50);
|
|
y1 = 374 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
x1 = 758 + Randomx.GetId(50);
|
|
y1 = 374 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
|
|
Invoke(new Action(() => { label2.Text = 90 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
Thread.Sleep(1000);
|
|
Invoke(new Action(() => { label2.Text = 95 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
|
|
Thread.Sleep(14000);
|
|
if (this.Created)
|
|
{
|
|
Invoke(new Action(() => { this.label2.Text = "过长时间没有响应,可能是授权失败\r\n或者密码错误,请核对帐户密码后重试。"; }));
|
|
Thread.Sleep(10000);
|
|
}
|
|
});
|
|
}
|
|
else { Invoke(new Action(() => { BaseMsgForm.ShowConfirm("微店手机号或登录密码为空,请删除店铺后重新导入\r\n导入格式为:手机号-----密码"); })); }
|
|
}
|
|
|
|
private static void cefClick(ChromiumWebBrowser webBrowser, int x1, int y1)
|
|
{
|
|
try
|
|
{
|
|
var host = webBrowser.GetBrowser().GetHost();
|
|
//host.SendFocusEvent(true);
|
|
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, false, 1, CefEventFlags.None); // 按下鼠标左键
|
|
Thread.Sleep(70 + Randomx.GetId(50));
|
|
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, true, 1, CefEventFlags.None); // 松开鼠标左键
|
|
Thread.Sleep(270 + Randomx.GetId(250));
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void cefInput(string text)
|
|
{
|
|
try
|
|
{
|
|
var host = cefWebBrowser.GetBrowser().GetHost();
|
|
foreach (var word in text)
|
|
{
|
|
var key = Encoding.ASCII.GetBytes(word.ToString())[0];
|
|
Thread.Sleep(10 + Randomx.GetId(10));
|
|
host.SendKeyEvent(new CefSharp.KeyEvent() { WindowsKeyCode = key, Type = KeyEventType.Char });
|
|
Thread.Sleep(50 + Randomx.GetId(40));
|
|
Thread.Sleep(50 + Randomx.GetId(40));
|
|
}
|
|
Thread.Sleep(1000 + Randomx.GetId(500));
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private async void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
cefWebBrowser.Visible = true;
|
|
}));
|
|
string url = e.Frame.Url;
|
|
string html = await e.Frame.GetSourceAsync();
|
|
|
|
// 微店网页自动登录
|
|
if (url.Contains("https://d.weidian.com/loginNew/") || url.Contains("loginMain"))
|
|
{
|
|
AutoLogin();
|
|
}
|
|
|
|
// 微店api自动登录以便授权
|
|
if (url.Contains("https://sso.weidian.com/login/index.php"))
|
|
{
|
|
this.AutoApiAuth();
|
|
}
|
|
|
|
// 微店工具箱自动点击授权
|
|
if (url.StartsWith("https://api.vdian.com/oauth2/authorize?appkey=690473"))
|
|
{
|
|
Invoke(new Action(() => { label2.Text = 97 + Randomx.GetId(10) / 5.0 + "%"; }));
|
|
Thread.Sleep(1000 + Randomx.GetId(2000));
|
|
Invoke(new Action(() => { label2.Text = 100 + "%"; }));
|
|
|
|
var x1 = 630 + Randomx.GetId(20);
|
|
var y1 = 400 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
|
|
}
|
|
|
|
// 公司Api接口自动点击授权
|
|
if (url.StartsWith("https://oauth.open.weidian.com/oauth2/authorize?appkey="))
|
|
{
|
|
Thread.Sleep(5000 + Randomx.GetId(5000));
|
|
var x1 = 630 + Randomx.GetId(20);
|
|
var y1 = 370 + Randomx.GetId(20);
|
|
cefClick(cefWebBrowser, x1, y1);
|
|
}
|
|
|
|
// 第三方Api接口授权成功后操作
|
|
if (url.Contains("http://2up.shuaishou.com/wdsc.aspx"))
|
|
{
|
|
BaseMsgForm.ShowError("第三方工具已不支持,请使用其他接口");
|
|
|
|
//Invoke(new Action(() =>
|
|
//{
|
|
// cefWebBrowser.Visible = false;
|
|
//}));
|
|
//if (url.Contains("code="))
|
|
//{
|
|
// var code = url.Substring(url.IndexOf("code=")).Replace("code=", "");
|
|
// var realToken = MappingVDianThirdApiBLL.GetTok(code);
|
|
|
|
// if (!string.IsNullOrEmpty(realToken))
|
|
// {
|
|
// if (realToken.Contains("订购该应用"))
|
|
// {
|
|
// Invoke(new Action(() => { this.label2.Text = "授权失败。"; }));
|
|
// Thread.Sleep(5000);
|
|
// if (this.Created)
|
|
// Invoke(new Action(() =>
|
|
// {
|
|
// this.OnSaveComplete(vDianInfo);
|
|
// this.Close();
|
|
// }));
|
|
// }
|
|
// else
|
|
// {
|
|
// vDianInfo.WdApi2Token = realToken;
|
|
// vDianInfo.WdApi2RefreshToken = "";
|
|
// if (this.Created)
|
|
// Invoke(new Action(() =>
|
|
// {
|
|
// this.OnSaveComplete(vDianInfo);
|
|
// this.Close();
|
|
// }));
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
|
|
// 微店Api授权成功回调页面
|
|
//if (url.Contains(vDianApiAuthSuccessUrl) || url.Replace("state=STATE&", "").Contains(vDianApiAuthSuccessUrl)
|
|
// || url.Replace(VDianFolder, "").Contains(vDianApiAuthSuccessUrl))
|
|
if (url.Contains(vDianApiAuthSuccessUrl) || url.Replace("state=STATE&", "").Contains(vDianApiAuthSuccessUrl)
|
|
|| vDianMultiApiAuthSuccessUrls.Any(u => url.Contains(u)) || (url.Contains("appkey=") && url.Contains("redirect_uri=")))
|
|
{
|
|
if (!Created)
|
|
return;
|
|
|
|
var task = cefWebBrowser.GetBrowser().MainFrame.GetSourceAsync();
|
|
task.Wait();
|
|
// 两个主要的接口的回调信息
|
|
if (task.Result.Contains("授权成功"))
|
|
{
|
|
Thread.Sleep(2000);
|
|
if (this.Created)
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.OnSaveComplete(vDianInfo);
|
|
this.Close();
|
|
}));
|
|
}
|
|
// 1000次调用的api接口
|
|
else if (task.Result.Contains("\"openid\":"))
|
|
{
|
|
Thread.Sleep(Randomx.GetId(500, 1500));
|
|
// 获取json数据读取AccessToken等信息
|
|
if (appKey != null)
|
|
{
|
|
string str = task.Result;
|
|
if (appKey.ImgsCountStatus == "ok")
|
|
{
|
|
vDianInfo.MultiImgApiToken = new VDianApiToken();
|
|
vDianInfo.MultiImgApiToken.LastRefreshDate = DateTime.Now.Date.ToString("yyyyMMdd");
|
|
vDianInfo.MultiImgApiToken.ApiAuth = "已授权";
|
|
vDianInfo.MultiImgApiToken.ApiAccessToken = BaseRegex.GetStringJson(ref str, "access_token");
|
|
vDianInfo.MultiImgApiToken.AppKey = appKey;
|
|
}
|
|
if ((appKey.PropCountStatus == "ok"))
|
|
{
|
|
vDianInfo.MultiAttrApiToken = new VDianApiToken();
|
|
vDianInfo.MultiAttrApiToken.LastRefreshDate = DateTime.Now.Date.ToString("yyyyMMdd");
|
|
vDianInfo.MultiAttrApiToken.ApiAuth = "已授权";
|
|
vDianInfo.MultiAttrApiToken.ApiAccessToken = BaseRegex.GetStringJson(ref str, "access_token");
|
|
vDianInfo.MultiAttrApiToken.AppKey = appKey;
|
|
}
|
|
if ((appKey.GoodsCountStatus == "ok"))
|
|
{
|
|
vDianInfo.MultiProductApiToken = new VDianApiToken();
|
|
vDianInfo.MultiProductApiToken.LastRefreshDate = DateTime.Now.Date.ToString("yyyyMMdd");
|
|
vDianInfo.MultiProductApiToken.ApiAuth = "已授权";
|
|
vDianInfo.MultiProductApiToken.ApiAccessToken = BaseRegex.GetStringJson(ref str, "access_token");
|
|
vDianInfo.MultiProductApiToken.AppKey = appKey;
|
|
}
|
|
}
|
|
|
|
Thread.Sleep(2000);
|
|
if (this.Created)
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.Close();
|
|
}));
|
|
}
|
|
else if (task.Result.Contains("授权失败"))
|
|
{
|
|
// 本地回调保存accesstoken数据,测试用
|
|
if (url.Contains("state=STATE"))
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
var code = "";
|
|
if (url.Contains("code="))
|
|
code = url.Substring(url.IndexOf("code=")).Substring("code=".Length);
|
|
if (!string.IsNullOrEmpty(code))
|
|
{
|
|
var testUrl = vDianApiAuthCodeUrl + "?code=" + code + "&appkey=" + appKey?.AppKey;
|
|
cefWebBrowser.Load(testUrl);
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
else if (task.Result == "<html><head></head><body></body></html>")
|
|
{
|
|
Thread.Sleep(2000);
|
|
if (this.Created)
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.Close();
|
|
}));
|
|
}
|
|
}
|
|
|
|
// 微店登录成功后退出
|
|
if (url.Contains("https://qiyukf.com/sdk/res/delegate.html?") || url.Contains("/weidian-loader/#/pc-vue-micro-index/index"))
|
|
{
|
|
if (loginType != "manage")
|
|
{
|
|
VDianShopLoginInfo vDianShopLoginInfo = new VDianShopLoginInfo();
|
|
vDianShopLoginInfo.ShopName = this.vDianShopName;
|
|
vDianShopLoginInfo.ShopId = this.vDianShopId;
|
|
vDianShopLoginInfo.LoginStatus = 1;
|
|
vDianShopLoginInfo.Cookies = "";
|
|
vDianShopLoginInfo.LstWdApiToken = new List<VDianApiToken>();
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList("weidian.com", cefWebBrowser.RequestContext.GetCookieManager(null));
|
|
if (cookieList != null && cookieList.Count > 0)
|
|
{
|
|
foreach (var cookie in cookieList)
|
|
{
|
|
vDianShopLoginInfo.Cookies += cookie.Name + "=" + cookie.Value + "; ";
|
|
if (cookie.Name == "wdtoken")
|
|
vDianShopLoginInfo.Wdtoken = cookie.Value;
|
|
}
|
|
vDianShopLoginInfo.Cookies = vDianShopLoginInfo.Cookies.Trim().TrimEnd(';');
|
|
}
|
|
if (!string.IsNullOrEmpty(vDianShopLoginInfo.ShopName) && !string.IsNullOrEmpty(vDianShopLoginInfo.ShopId)
|
|
&& !string.IsNullOrEmpty(vDianShopLoginInfo.Cookies) && !string.IsNullOrEmpty(vDianShopLoginInfo.Wdtoken))
|
|
{
|
|
vDianShopLoginInfo.Phone = this.phone;
|
|
vDianShopLoginInfo.Password = this.password;
|
|
if (this.Created)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.OnSaveComplete(vDianShopLoginInfo);
|
|
this.Close();
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
|
{
|
|
if (url.Contains("getShopInfoByList"))
|
|
{
|
|
vDianShopId = AllBase.BaseRegex.GetMatchRegexString(responseData, "shop_id\":\"([\\s\\S]*?)\"");
|
|
vDianShopName = AllBase.BaseRegex.GetMatchRegexString(responseData, "shop_name\":\"([\\s\\S]*?)\"");
|
|
}
|
|
// 实名认证
|
|
else if (url.Contains("authentication/realname.queryAuthStatus"))
|
|
{
|
|
if (responseData.Contains("\"status\":\"SUCCESS\"") && this.vDianInfo != null) // \"status\":\"UNAUTH\" 未认证
|
|
{
|
|
if (loginType == "upAuth")
|
|
{
|
|
if (this.Created)
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.OnSaveComplete(vDianInfo);
|
|
this.Close();
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
else if (url.Contains("https://thor.weidian.com/authentication/realname.getUserAuthInfoWithScopes"))
|
|
{
|
|
if (responseData.Contains("\"CERT\"") && this.vDianInfo != null) // 验证成功了
|
|
{
|
|
if (this.Created)
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.OnSaveComplete(vDianInfo);
|
|
this.Close();
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnReload_Click(object sender, EventArgs e)
|
|
{
|
|
if (cefWebBrowser != null)
|
|
{
|
|
cefWebBrowser.Load(textBox1.Text);
|
|
//cefWebBrowser.Reload();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// name1=value1; name2=value2... 的格式转换为 Cef Cookie
|
|
/// </summary>
|
|
/// <param name="cookies"></param>
|
|
/// <returns></returns>
|
|
List<Cookie> ConvertStringCookieToCefCookie(string cookies, string domain)
|
|
{
|
|
List<Cookie> cookieList = new List<Cookie>();
|
|
if (string.IsNullOrEmpty(cookies))
|
|
return cookieList;
|
|
|
|
string[] cookieArr = cookies.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (var item in cookieArr)
|
|
{
|
|
if (item.Contains("="))
|
|
{
|
|
Cookie cookie = new Cookie();
|
|
cookie.Name = item.Substring(0, item.IndexOf('=')).Trim();
|
|
cookie.Value = item.Substring(item.IndexOf('=') + 1).Trim();
|
|
cookie.Domain = domain;
|
|
cookie.Path = "/";
|
|
cookieList.Add(cookie);
|
|
}
|
|
}
|
|
return cookieList;
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
IsRun = false;
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|