using Api.Framework; using Api.Framework.Model; using Api.Framework.Tools; using Chat.Framework; using Chat.Framework.WXSdk.IPAD; using DevExpress.XtraEditors; using Newtonsoft.Json; using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using UI.Framework.Forms; using static FLSystem.Forms.point_manage_control; namespace FLSystem.Forms { public partial class ExchangeStateForm : BaseForm { public ExchangeStateForm(exchange_list_temp exchange) { InitializeComponent(); this.exchange = exchange; } exchange_list_temp exchange; bool is_auto_pay = false; public string mess { get; set; } public string pay_url { get; private set; } private void ExchangeStateForm_Load(object sender, EventArgs e) { pay_url = string.Empty; try { this.settingControl1.Bind(exchange); } catch (Exception ex) { if (!this.IsDisposed) ShowError(ex); } } private void simpleButton4_Click(object sender, EventArgs e) { try { if (exchange.state == ApplyType.退回兑换) { var client = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == exchange.robot_name); if (client == null) { if (XtraMessageBox.Show( $@"{exchange.robot_name}机器人没有登录 用户将无法收到退回兑换消息 点击OK执行操作", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, DevExpress.Utils.DefaultBoolean.Default) == DialogResult.Cancel) { exchange.state = ApplyType.未审核; } } else { exchange.state = ApplyType.退回兑换; //throw new Exception("兑换退回失败,请稍后重试"); } } this.Close(); } catch (Exception ex) { BaseForm.ShowErrorAutoClose(ex); } } private void simpleButton3_Click(object sender, EventArgs e) { exchange.state = ApplyType.未审核; exchange.remark = string.Empty; this.Close(); } private CancellationTokenSource tokenSource = new CancellationTokenSource(); private async void simpleButton1_Click(object sender, EventArgs e) { ChangeBtn(this.simpleButton1); try { await Task.Run(() => { try { if (exchange.chattype != Api.Framework.SDK.ChatType.微信) throw new Exception("暂时不支持自动转账!"); var client = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == exchange.robot_name); if (client == null) throw new Exception(exchange.robot_name + ",该帐号没有登录!"); if (client.WeixinType != Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信) throw new Exception("您当前登录的微信版本,暂不支持自动转账!"); var session = ApiClient.GetSession(); var robot = session.FindRobotInfo(exchange.robot_name, exchange.chattype); if (robot == null) throw new Exception(exchange.robot_name + ",数据库丢失!"); var passInfo = session.FindWeixinpassword(robot.id);//微信自动转账 if (!string.IsNullOrWhiteSpace(exchange.groupid)) { var user = client.GetContact(exchange.username); if (user == null) throw new Exception("兑换用户数据异常"); if (!string.IsNullOrWhiteSpace(user.Ticket))//非好友 throw new Exception("该用户为非好友,请使用支付宝转账"); } if (passInfo != null && !string.IsNullOrEmpty(passInfo.password))//是否设置了账号密码 { var bank = passInfo.GetBank(); var pointConfig = ApiClient.GetPointManageConfig(); if (pointConfig == null) throw new Exception("获取积分管理配置为*"); string result = client.SendPay(exchange.username, pointConfig.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", exchange.point.ToString("0.00")), (int)((decimal)exchange.point * 100m), passInfo.password, 1, (PayType)Enum.ToObject(typeof(PayType), (int)pointConfig.Exchange_PayType), bank); if (!string.IsNullOrEmpty(result)) throw new Exception(robot.name + (bank != null ? "银行" : "余额") + "转账:" + exchange.point.ToString("0.00") + "," + result); exchange.state = ApplyType.已审核; exchange.check_time = DateTime.Now; exchange.remark = "手动审核【微信支付】"; is_auto_pay = true; ChangeBtn(this.simpleButton1, "微信支付"); } else throw new Exception($@"{robot.nick}({robot.name}),尚未设置支付密码! 请在机器人管理中,右击机器人设置密码!"); } catch (Exception ex) { exchange.state = ApplyType.未审核; //settingControl1.Bind(new exchange_list_temp()); this.settingControl1.Bind(exchange); if (!this.IsDisposed) ShowError(ex); ChangeBtn(this.simpleButton1, "微信支付"); } }, tokenSource.Token); } catch (Exception) { } } bool is_close = true; private void ChangeBtn(SimpleButton btn, string text = "") { if (!this.IsDisposed) this.UpdateUI(() => { btn.Text = string.IsNullOrEmpty(text) ? "支付中.." : text; btn.Enabled = string.IsNullOrEmpty(text) ? false : true; is_close = btn.Enabled; if (is_auto_pay) this.Close(); }); } private async void simpleButton2_Click(object sender, EventArgs e) { ChangeBtn(this.simpleButton2); try { await Task.Run(() => { try { //if (exchange.chattype != Api.Framework.SDK.ChatType.微信) // throw new Exception("暂时不支持自动转账!"); var client = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == exchange.robot_name); //var pcclient = ChatClient.PCRobotPool.GetSession(exchange.robot_name); if (client == null) throw new Exception(exchange.robot_name + ",该账号没有登录!"); var session = ApiClient.GetSession(); var robot = session.FindRobotInfo(exchange.robot_name, exchange.chattype); if (robot == null) throw new Exception(exchange.robot_name + ",数据库丢失!"); if (client != null && !string.IsNullOrWhiteSpace(exchange.groupid)) { var user = client.GetContact(exchange.username); if (user == null) throw new Exception("兑换用户数据异常"); if (!string.IsNullOrWhiteSpace(user.Ticket) && user.Ticket != "-1" && user.Ticket != "0")//非好友 throw new Exception("该用户为非好友或已拉黑,请使用支付宝转账"); } var pointConfig = ApiClient.GetPointManageConfig(); if (pointConfig == null) throw new Exception("获取积分管理配置为空_"); if (string.IsNullOrWhiteSpace(pointConfig.ExchangeCommercialPayTip)) throw new Exception("商户付款通知提示语不能为空,请到积分兑换插件中设置"); else if (!pointConfig.ExchangeCommercialPayTip.Contains("[领取地址]")) throw new Exception("商户付款通知提示语中不包含 [领取地址] 变量,请到积分兑换插件中设置"); EventClient.OnEvent(this, $"{robot.nick}【{robot.uin}】手动审核【商户付款】{exchange.username} begin:{DateTime.Now.ToString("u")}"); var ispaid = false; object appinfo = null; var ExchangePacketTitle = @"兑换成功:[兑换金额]"; if (!string.IsNullOrWhiteSpace(pointConfig.ExchangePacketTitle)) ExchangePacketTitle = pointConfig.ExchangePacketTitle; string url = ApiClient.SendWechatPay(new { robot_nick = robot.nick, robot_name = robot.name, username = exchange.username, usernick = exchange.usernick }, ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", exchange.point.ToString()), exchange.point, out ispaid, out appinfo); if (string.IsNullOrEmpty(url)) throw new Exception("服务器繁忙,请稍后重试"); if (ispaid) { var ExchangeCommercialEftTip = @"一一一一商 户 转 账 成 功一一一一 [兑换金额]兑换成功 已直接转入您的账户!"; if (!string.IsNullOrWhiteSpace(pointConfig.ExchangeCommercialEftTip)) ExchangeCommercialEftTip = pointConfig.ExchangeCommercialEftTip; this.mess = ExchangeCommercialEftTip.Replace("[兑换金额]", exchange.point.ToString("0.00")); } else { this.pay_url = url;//ApiClient.ShortURL(url).Result; bool isSendMiNi = false; if (pointConfig.ExchangeCommercialPayTip_MiniApp == Api.Framework.Enums.SwitchType.开启) { var xml = Util.GetMiNiAppXml(appinfo, robot.type); if (!string.IsNullOrWhiteSpace(xml)) { this.mess = xml; isSendMiNi = true; } } try { EventClient.OnEvent(this, $@"{robot.type.ToString()}->{robot.nick}【{robot.uin}】手动审核【{robot.name} - {exchange.username}({exchange.usernick})】 手动审核【商户付款】end:{DateTime.Now.ToString("u")} url:{url} pay_url:{pay_url} appinfo is null:{(appinfo == null)} appinfo = {(appinfo != null ? JsonConvert.SerializeObject(appinfo) : "NULL") } app开关:{(pointConfig.ExchangeCommercialPayTip_MiniApp == Api.Framework.Enums.SwitchType.开启)} 是否小程序:{isSendMiNi.ToString()} 回复长度:{(mess == null ? "0" : mess.Length + "")}"); } catch (Exception) { } if (!isSendMiNi) { var ExchangeCommercialPayTip = @"一一一一等 待 领 取一一一一 [领取地址] 点击链接,领取红包到您钱包!"; if (!string.IsNullOrWhiteSpace(pointConfig.ExchangeCommercialPayTip)) ExchangeCommercialPayTip = pointConfig.ExchangeCommercialPayTip; this.mess = ExchangeCommercialPayTip.Replace("[领取地址]", ApiClient.ShortURL(this.pay_url).Result).Replace("[兑换金额]", exchange.point.ToString("0.00")); } } exchange.state = ApplyType.已审核; exchange.check_time = DateTime.Now; exchange.remark = $"手动审核【商户付款】 商户链接:{url}"; is_auto_pay = true; EventClient.OnEvent(this, $"{robot.nick}【{robot.uin}】商户付款信息 = " + mess); ChangeBtn(this.simpleButton2, "商户支付"); } catch (Exception ex) { this.Invoke(new Action(delegate { ChangeBtn(this.simpleButton2, "商户支付"); exchange.state = ApplyType.未审核; //settingControl1.Bind(new exchange_list_temp()); this.settingControl1.Bind(exchange); if (!this.IsDisposed) ShowError(ex); })); } }, tokenSource.Token); } catch (Exception) { } } private void ExchangeStateForm_FormClosing(object sender, FormClosingEventArgs e) { if (!is_close) e.Cancel = true; else tokenSource.Cancel(); } } }