using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using Yw;
namespace HStation.WinFrmUI
{
public partial class WechatBindingCtrl : DevExpress.XtraEditors.XtraUserControl
{
public WechatBindingCtrl()
{
InitializeComponent();
}
///
/// 绑定事件
///
public event Action LoginStartEvent;
///
/// 登录取消事件
///
public event Action LoginCancelEvent;
private bool _isInitialized = false;//初始化
private const string _template = "hzkw_wx_template";//微信登录模板
///
/// 初始化
///
public async void Initial()
{
var loginUrl = await BLLFactory.Instance.GetLoginUrl(_template);
await this.webView21.EnsureCoreWebView2Async();
this.webView21.Source = new Uri(loginUrl);
this.webView21.CoreWebView2.SourceChanged += CoreWebView2_SourceChanged;
}
//源改变
private 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(code);
}
}
}
}