old_flsystem/应用/CSIMTurnMoney/Class1.cs

166 lines
5.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using Api.Framework;
using Api.Framework.Enums;
using Api.Framework.Events;
using Api.Framework.Model;
using Api.Framework.SDK;
using Api.Framework.Tools;
using Api.Framework.Utils;
using Chat.Framework.WXSdk.IPAD;
using CSIMTurnMoney.Properties;
namespace CSIMTurnMoney
{
public class Class1 : Plugin
{
public Class1()
{
this.Name = "客服指令转账";
this.Note = "客服指令转账";
this.Logo = Resources.;
}
#region
public static Config Config;
private MainForm mainForm = null;
#endregion
public override void Start()
{
try
{
//创建配置文件
Config = this.ReadConfig<Config>();
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
public override void ShowForm()
{
try
{
if (mainForm == null || mainForm.IsDisposed)
{
mainForm = new MainForm();
mainForm.Show();
}
mainForm.TopMost = true;
mainForm.TopMost = false;
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
public override void Stop()
{
try
{
if (mainForm != null)
{
mainForm.CloseForm();
mainForm = null;
}
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
{
try
{
if (string.IsNullOrEmpty(e.Groupid)) //私聊信息
{
var _event = e.Event as Chat.Framework.WXSdk.Events.WXReiceveFriendMsg;
if (_event != null && _event.IsRobot) //判断是否自己给自己发送消息
{
if (string.IsNullOrWhiteSpace(Config.TurnCMD))
{
return;
}
try
{
var reg = Regex.Match(e.Message.Trim(), Config.TurnCMD, RegexOptions.IgnoreCase);
if (!reg.Success)
{
return;
}
var result = reg.Groups[1].Value;
var isSucc = double.TryParse(result, out var money);
if (!isSucc)
{
throw new Exception("可能客服指令转账指令设置有问题,导致获取金额异常");
}
if (Config.MaxMoney < money || money < 0.3)
{
e.SendMessage("执行失败,操作金额不合规");
return;
}
var member = e.GetMemberinfo();
string url = ApiClient.SendWechatPay(new { robot_name = e.RobotName, robot_nick = e.RobotNick, username = member.username, usernick = member.usernick }, $"转账成功:{money}{ApiClient.Setting.SystemConfig.PointName}", money, out var ispaid, out var appinfo);
if (string.IsNullOrWhiteSpace(url))
{
return;
}
var session = ApiClient.GetSession();
//member = session.ChangePoint(PointType.提现扣除, money, member.id, "客服指令转账成功");
session.Insertable(new fl_exchange_info() { point = money, state = ApplyType., time = DateTime.Now, check_time = DateTime.Now, uid = member.id, remark = $"客服指令转账成功 商户链接:{url}", rid = e.RobotInfo.id, IsTransmatic = true, groupid = e.Groupid }).ExecuteCommand();//保存记录
var mess = string.Empty;
if (!ispaid)
{
if (appinfo != null)
mess = Util.GetMiNiAppXml(appinfo, e.ChatType);
}
var pay_url = ApiClient.ShortURL(url).Result;
LogHelper.GetSingleObj().Info("客服指令转账成功 商户链接", $"{member.usernick}({member.username});金额:{money};原始:{url} => 缩短:{pay_url}");
if (string.IsNullOrWhiteSpace(mess))
{
mess = Config.MessInfo.Replace("[兑换金额]", money.ToString("0.00")).Replace("[领取地址]", pay_url).Replace("[长领取地址]", url);
}
ApiClient.SendMessage(
new temp_send_data() { Groupid = e.Groupid, Message = mess, Robot = e.RobotInfo, TouserName = member.username }
);
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
}
}
catch (Exception ex)
{
this.OnLog($"客服指令转账插件异常.:{ex.Message} - {ex.StackTrace}");
}
}
}
}