using System.Web;
|
using Yw;
|
|
namespace PBS.Desktop
|
{
|
public partial class WechatLoginCtrl : DevExpress.XtraEditors.XtraUserControl, ILogin
|
{
|
public WechatLoginCtrl()
|
{
|
InitializeComponent();
|
}
|
|
/// <summary>
|
/// 登录开始事件
|
/// </summary>
|
public event Action LoginStartEvent;
|
|
/// <summary>
|
/// 登录取消事件
|
/// </summary>
|
public event Action LoginCancelEvent;
|
|
/// <summary>
|
/// 登录完成事件
|
/// </summary>
|
public event Action<Yw.Dto.UserLoginOutput> LoginEndEvet;
|
|
|
private bool _isInitialized = false;//初始化
|
private const string _template = "hzkw_wx_template";//微信登录模板
|
private const string _software = "HStation_XHS_DESKTOP";//软件编码
|
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
public async void Initial()
|
{
|
if (_isInitialized)
|
{
|
return;
|
}
|
_isInitialized = true;
|
var loginUrl = await BLLFactory<Yw.BLL.ToolWechat>.Instance.GetLoginUrl(_template);
|
await this.webView21.EnsureCoreWebView2Async();
|
this.webView21.Source = new Uri(loginUrl);
|
this.webView21.CoreWebView2.SourceChanged += CoreWebView2_SourceChanged;
|
}
|
|
//源改变
|
private async void CoreWebView2_SourceChanged(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2SourceChangedEventArgs e)
|
{
|
var collection = HttpUtility.ParseQueryString(this.webView21.Source.Query);
|
var code = collection["code"];
|
var state = collection["state"];
|
if (!string.IsNullOrEmpty(code))
|
{
|
LoginStartEvent?.Invoke();
|
var result = await BLLFactory<Yw.BLL.UserLogin>.Instance.LoginSoftwareStandardByWechatAccount(_template, _software, code, null);
|
LoginEndEvet?.Invoke(result);
|
}
|
}
|
|
|
}
|
}
|