|
|
using MQTTnet;
|
|
|
using MQTTnet.Client.Receiving;
|
|
|
using MQTTnet.Server;
|
|
|
using Newtonsoft.Json;
|
|
|
using POSV.Payment.AllinPay;
|
|
|
using POSV.Payment.AllinPay.Models.ParamModels;
|
|
|
using POSV.Payment.AllinPay.Models.ResponseModels;
|
|
|
using POSV.ShoppingCart;
|
|
|
using POSV.Utils;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace POSV
|
|
|
{
|
|
|
public partial class Form1 : Form
|
|
|
{
|
|
|
IMqttServer server;
|
|
|
|
|
|
delegate void set_Text(string s); //定义委托
|
|
|
|
|
|
set_Text Set_Text; //定义委托
|
|
|
|
|
|
public Form1()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
private void btnRegister_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
this.txtResponseResult.Text = "";
|
|
|
if (string.IsNullOrEmpty(this.txtCustomerUserId.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "外部系统收款方编号不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var model = new RegisterModel
|
|
|
{
|
|
|
customerUserId = this.txtCustomerUserId.Text,
|
|
|
memberType = "3",
|
|
|
source = "2"
|
|
|
};
|
|
|
|
|
|
|
|
|
var param = new RegisterParamInfo
|
|
|
{
|
|
|
|
|
|
bizContent = JsonConvert.SerializeObject(model)
|
|
|
};
|
|
|
var _data = AllinpayHelper.RegisterMember(param);
|
|
|
this.txtMethod.Text = param.method;
|
|
|
this.txtResponseResult.Text = JsonConvert.SerializeObject(_data);
|
|
|
|
|
|
if (_data.IsSuccess)
|
|
|
{
|
|
|
|
|
|
var result = JsonConvert.DeserializeObject<RegisterResultModel>(_data.ResultInfo.data);
|
|
|
|
|
|
this.txtBizUserId.Text = result.bizUserId;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void btnSendVerificationCode_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
this.txtResponseResult.Text = "";
|
|
|
if (string.IsNullOrEmpty(this.txtBizUserId2.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "BizUserId不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(this.txtPhone.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "手机号不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var model = new SendVerificationCodeModel
|
|
|
{
|
|
|
bizUserId = this.txtBizUserId2.Text,
|
|
|
codeType = "9",
|
|
|
phone = this.txtPhone.Text
|
|
|
};
|
|
|
|
|
|
var param = new SendVerificationCodeParamInfo
|
|
|
{
|
|
|
bizContent = JsonConvert.SerializeObject(model)
|
|
|
};
|
|
|
this.txtMethod.Text = param.method;
|
|
|
var _data = AllinpayHelper.SendVerificationCode(param);
|
|
|
|
|
|
this.txtResponseResult.Text = JsonConvert.SerializeObject(_data);
|
|
|
|
|
|
if (_data.IsSuccess)
|
|
|
{
|
|
|
var result = JsonConvert.DeserializeObject<SendVerificationCodeResultModel>(_data.ResultInfo.data);
|
|
|
this.txtVerificationCode.Text = result.phone;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void btnBindPhone_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
this.txtResponseResult.Text = "";
|
|
|
if (string.IsNullOrEmpty(this.txtBizUserId2.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "BizUserId不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(this.txtPhone.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "手机号不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var model = new BindPhoneModel
|
|
|
{
|
|
|
bizUserId = this.txtBizUserId2.Text,
|
|
|
verificationCode = this.txtVerificationCode.Text,
|
|
|
phone = this.txtPhone.Text
|
|
|
};
|
|
|
|
|
|
var param = new BindPhoneParamInfo { bizContent = JsonConvert.SerializeObject(model) };
|
|
|
this.txtMethod.Text = param.method;
|
|
|
var _data = AllinpayHelper.BindPhone(param);
|
|
|
|
|
|
this.txtResponseResult.Text = JsonConvert.SerializeObject(_data);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void btnVspTermidInfoManage_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(txtVspMerchantid.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "VspMerchantid不能为空";
|
|
|
return;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(this.txtVspCusid.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "VspCusid不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(this.txtTermno.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "Termno不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var model = new VspTermidInfoManageModel
|
|
|
{
|
|
|
vspMerchantid = txtVspMerchantid.Text,
|
|
|
vspCusid = txtVspCusid.Text,
|
|
|
termno = txtTermno.Text,
|
|
|
operation = cboOperation.SelectedItem != null ? ((DevComponents.Editors.ComboItem)cboOperation.SelectedItem).Value.ToString() : "",
|
|
|
devicetype = cboDevicetype.SelectedItem != null ? ((DevComponents.Editors.ComboItem)cboDevicetype.SelectedItem).Value.ToString() : "",
|
|
|
termsn = txtTermsn.Text,
|
|
|
termstate = cboTermstate.SelectedItem != null ? ((DevComponents.Editors.ComboItem)cboTermstate.SelectedItem).Value.ToString() : "",
|
|
|
termaddress = txtTermaddress.Text
|
|
|
};
|
|
|
|
|
|
var param = new VspTermidInfoManageParamInfo { bizContent = JsonConvert.SerializeObject(model) };
|
|
|
this.txtMethod.Text = param.method;
|
|
|
|
|
|
txtRequest.Text = JsonConvert.SerializeObject(param);
|
|
|
|
|
|
var _data = AllinpayHelper.VspTermidInfoManage(param);
|
|
|
|
|
|
this.txtResponseResult.Text = JsonConvert.SerializeObject(_data);
|
|
|
}
|
|
|
|
|
|
private void label19_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void btnTermInfoManage_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(txtVspMerchantid.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "VspMerchantid不能为空";
|
|
|
return;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(this.txtVspCusid.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "VspCusid不能为空";
|
|
|
return;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(this.txtTermno.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "Termno不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(this.txtSybappid.Text))
|
|
|
{
|
|
|
this.txtResponseResult.Text = "appid不能为空";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var model = new TermInfoManageModel
|
|
|
{
|
|
|
vspMerchantid = txtVspMerchantid.Text,
|
|
|
vspCusId = txtVspCusid.Text,
|
|
|
operationType = cboOperationType.SelectedItem != null ? ((DevComponents.Editors.ComboItem)cboOperationType.SelectedItem).Value.ToString() : "",
|
|
|
vspTermid = txtTermno.Text,
|
|
|
appid = txtSybappid.Text,
|
|
|
bizUserId = txtBizUserId.Text
|
|
|
};
|
|
|
|
|
|
var param = new TermInfoManageParamInfo { bizContent = JsonConvert.SerializeObject(model) };
|
|
|
this.txtMethod.Text = param.method;
|
|
|
|
|
|
txtRequest.Text = JsonConvert.SerializeObject(param);
|
|
|
|
|
|
var _data = AllinpayHelper.TermInfoManage(param);
|
|
|
|
|
|
this.txtResponseResult.Text = JsonConvert.SerializeObject(_data);
|
|
|
}
|
|
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void button8_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
private void btnOrder2Split_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
Global.Instance.Worker = new Entity.Worker();
|
|
|
Global.Instance.Worker.StoreInfo = new Entity.StoreInfo();
|
|
|
Global.Instance.Worker.StoreInfo.Ext1 = "{\"payuserid\":\"ZHTGR_OUT16890691048742475\",\"vspCusid\":\"563162058142L1E\",\"vspCusname\":\"大同市平城区云滋快餐店\",\"bizUserId\":\"ZHTQY_OUT16968223767100078\"}";
|
|
|
lock (Global.Instance.SyncLock)
|
|
|
{
|
|
|
Stopwatch sw = new Stopwatch();
|
|
|
|
|
|
sw.Start();
|
|
|
|
|
|
var pageSize = 10;
|
|
|
var lists = new List<OrderObject>();
|
|
|
//单据明细
|
|
|
var items = new List<OrderItem>();
|
|
|
//支付明细
|
|
|
var pays = new List<PayItem>();
|
|
|
//支付方式分摊明细
|
|
|
var itemPays = new List<OrderItemPay>();
|
|
|
try
|
|
|
{
|
|
|
using (var db = Global.Instance.OpenDataBase)
|
|
|
{
|
|
|
var count = db.Query<OrderObject>($"where saleDate between '{DateTime.Now.ToString("yyyy-MM-dd 00:00:00")}' and '{DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00")}'").Count();
|
|
|
//主单数据
|
|
|
//lists = db.Query<OrderObject>("where syncStatus = 0 and uploadErrors < 3000 order by uploadErrors limit @0;", 1).ToList();
|
|
|
|
|
|
var pageCount = count % pageSize != 0 ? count / pageSize + 1 : count / pageSize;
|
|
|
|
|
|
for (int i = 0; i < pageCount; i++)
|
|
|
{
|
|
|
lists = db.Query<OrderObject>($"where saleDate between '{DateTime.Now.ToString("yyyy-MM-dd 00:00:00")}' and '{DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00")}' limit ({i * pageSize}), {pageSize}").ToList();
|
|
|
|
|
|
var ids = string.Join("','", lists.ConvertAll(x => x.Id).ToArray());
|
|
|
|
|
|
var condition = " where orderId in ('" + ids + "');";
|
|
|
|
|
|
//单据明细
|
|
|
items = db.Query<OrderItem>(condition).ToList();
|
|
|
|
|
|
//支付明细
|
|
|
pays = db.Query<PayItem>(condition).ToList();
|
|
|
|
|
|
itemPays = db.Query<OrderItemPay>(condition).ToList();
|
|
|
|
|
|
foreach (var orderObject in lists)
|
|
|
{
|
|
|
orderObject.Items = items.FindAll(x => x.OrderId == orderObject.Id);
|
|
|
|
|
|
//将支付方式附加到主单
|
|
|
orderObject.Pays = pays.FindAll(x => x.OrderId == orderObject.Id);
|
|
|
|
|
|
foreach (var item in orderObject.Items)
|
|
|
{
|
|
|
item.ItemPayList = itemPays.FindAll(x => x.OrderId == orderObject.Id);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (lists.Count > 0)
|
|
|
{
|
|
|
foreach (var orderObject in lists)
|
|
|
{
|
|
|
SplitPayUtils.Instance.SaveSplitPayInfo(orderObject);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine("保存订单的分账信息错误<{0}>", ex.Message);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
sw.Stop();
|
|
|
|
|
|
Console.WriteLine("保存订单的分账信息结束<{0}>", sw.ElapsedMilliseconds);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void btnMqttServerStart_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
StartMqttServer();
|
|
|
}
|
|
|
|
|
|
private void MessageReceivedHandler(MqttApplicationMessageReceivedEventArgs obj)
|
|
|
{
|
|
|
//Console.WriteLine("===================================================");
|
|
|
//Console.WriteLine("收到消息:");
|
|
|
//Console.WriteLine($"客户端:{obj.ClientId}");
|
|
|
//Console.WriteLine($"主题:{obj.ApplicationMessage.Topic}");
|
|
|
//Console.WriteLine($"消息:{Encoding.UTF8.GetString(obj.ApplicationMessage.Payload)}");
|
|
|
//Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
//Console.WriteLine();
|
|
|
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { "===================================================" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { "收到消息:" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"客户端:{obj.ClientId}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"主题:{obj.ApplicationMessage.Topic}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"消息:{Encoding.UTF8.GetString(obj.ApplicationMessage.Payload)}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { "+++++++++++++++++++++++++++++++++++++++++++++++++++" });
|
|
|
}
|
|
|
|
|
|
private void ClientDisconnectedHandler(MqttServerClientDisconnectedEventArgs obj)
|
|
|
{
|
|
|
//Console.WriteLine($"断开连接的客户端:{obj.ClientId}");
|
|
|
//Console.WriteLine($"断开连接类型:{obj.DisconnectType.ToString()}");
|
|
|
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"断开连接的客户端:{obj.ClientId}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"断开连接类型:{obj.DisconnectType.ToString()}" });
|
|
|
}
|
|
|
|
|
|
private void ClientConnectedHandler(MqttServerClientConnectedEventArgs obj)
|
|
|
{
|
|
|
//Console.WriteLine($"{obj.ClientId}此客户端已连接至服务器!");
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"{obj.ClientId}此客户端已连接至服务器!" });
|
|
|
}
|
|
|
|
|
|
private void btnMqttInit_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
server = new MqttFactory().CreateMqttServer();
|
|
|
// 客户端连接事件
|
|
|
server.ClientConnectedHandler = new MqttServerClientConnectedHandlerDelegate(ClientConnectedHandler);
|
|
|
//客户端断开连接事件
|
|
|
server.ClientDisconnectedHandler = new MqttServerClientDisconnectedHandlerDelegate(ClientDisconnectedHandler);
|
|
|
server.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(MessageReceivedHandler);
|
|
|
server.UseApplicationMessageReceivedHandler(args =>
|
|
|
{
|
|
|
//Console.WriteLine("===================================================");
|
|
|
//Console.WriteLine("收到消息:");
|
|
|
//Console.WriteLine($"客户端:{args.ClientId}");
|
|
|
//Console.WriteLine($"主题:{args.ApplicationMessage.Topic}");
|
|
|
//Console.WriteLine($"消息:{Encoding.UTF8.GetString(args.ApplicationMessage.Payload)}");
|
|
|
//Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
//Console.WriteLine();
|
|
|
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { "===================================================" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { "收到消息:" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"客户端:{args.ClientId}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"主题:{args.ApplicationMessage.Topic}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { $"消息:{Encoding.UTF8.GetString(args.ApplicationMessage.Payload)}" });
|
|
|
txtMqttLog.Invoke(Set_Text, new object[] { "+++++++++++++++++++++++++++++++++++++++++++++++++++" });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 打开MQTT Server 服务
|
|
|
/// </summary>
|
|
|
/// <param name="port">端口号:默认为1883</param>
|
|
|
public async void StartMqttServer(int port = 1883)
|
|
|
{
|
|
|
if (server.IsStarted)
|
|
|
return;
|
|
|
MqttServerOptionsBuilder serverOptions = new MqttServerOptionsBuilder();
|
|
|
serverOptions.WithDefaultEndpointPort(port);
|
|
|
await server.StartAsync(serverOptions.Build());
|
|
|
}
|
|
|
|
|
|
public async void CloseMqttServer(int port = 1883)
|
|
|
{
|
|
|
if (!server.IsStarted)
|
|
|
return;
|
|
|
MqttServerOptionsBuilder serverOptions = new MqttServerOptionsBuilder();
|
|
|
serverOptions.WithDefaultEndpointPort(port);
|
|
|
await server.StopAsync();
|
|
|
}
|
|
|
|
|
|
private void btnMqttServerClose_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
CloseMqttServer();
|
|
|
}
|
|
|
|
|
|
private void set_lableText(string s) //主线程调用的函数
|
|
|
{
|
|
|
txtMqttLog.Text += s + "\r\n";
|
|
|
}
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
Set_Text = new set_Text(set_lableText); //实例化
|
|
|
}
|
|
|
}
|
|
|
}
|