12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using Autofac;
- using Bowin.Common.Log;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.Utility.OnlinePay;
- using Senparc.Weixin.TenPay.V3;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Linq;
- using System.ServiceProcess;
- using System.Text;
- namespace EMIS.Service
- {
- public partial class Service1 : ServiceBase
- {
- private System.Timers.Timer timer1 = new System.Timers.Timer();
- public Service1()
- {
- timer1.Interval = 180000;
- timer1.Elapsed += Timer1_Elapsed;
- InitializeComponent();
- }
- private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- timer1.Stop();
- try
- {
- LogHelper.WriteLog(LogType.ServiceLog, "----开始根据微信订单同步缴费状态-----");
- using (var scop = Program.AutofacContainer.BeginLifetimeScope())
- {
- IWechatPayServices WechatPayServices = scop.Resolve<IWechatPayServices>();
- var wecharPayList = WechatPayServices.SearchWeChatPayList();
- List<OrderQueryResult> orderList = new List<OrderQueryResult>();
- List<String> CanCloseOrderIDList = new List<string>();
- foreach (var wecharPay in wecharPayList)
- {
- OrderQueryResult query = WechatHelper.OrderQuery(wecharPay.OrderID);
- if (wecharPay.CreateTime != null)
- {
- if (DateTime.Now.Subtract(wecharPay.CreateTime.Value).TotalMinutes > 6)
- {
- var canClose = WechatHelper.CloseOrder(wecharPay.OrderID);
- if (canClose)
- {
- CanCloseOrderIDList.Add(wecharPay.OrderID);
- LogHelper.WriteLog(LogType.ServiceLog, "关单成功:商家订单号:" + wecharPay.OrderID + ";微信订单号:" + query.transaction_id + ";状态result_code:" + query.result_code + ";支付状态:" + query.trade_state);
- }
- else
- {
- LogHelper.WriteLog(LogType.ServiceLog, "关单失败:商家订单号:" + wecharPay.OrderID + ";微信订单号:" + query.transaction_id + ";状态result_code:" + query.result_code + ";支付状态:" + query.trade_state);
- }
- }
- }
- LogHelper.WriteLog(LogType.ServiceLog, "商家订单号:" + wecharPay.OrderID + ";微信订单号:" + query.transaction_id + ";状态result_code:" + query.result_code + ";支付状态:" + query.trade_state);
- orderList.Add(query);
- }
- WechatPayServices.UpdateWeChatPay(orderList);
- WechatPayServices.DeleteCanCloseWeChatPay(CanCloseOrderIDList);
- }
- LogHelper.WriteLog(LogType.ServiceLog, "----结束根据微信订单同步缴费状态-----");
- }
- catch (System.Exception err)
- {
- LogHelper.WriteLog(LogType.ServiceLog, "----根据微信订单同步缴费状态处理异常-----");
- LogHelper.WriteLog(LogType.ServiceLog, err.Message+err.StackTrace);
- }
- timer1.Start();
- }
- protected override void OnStart(string[] args)
- {
- timer1.Start();
- }
- protected override void OnStop()
- {
- timer1.Stop();
- }
- }
- }
|