/// <summary> /// /// </summary> /// <param name="stateInfo"></param> public static void NotifyCheckStatus(Object stateInfo) { OrderNotify notify = (OrderNotify)stateInfo; string notifyUrl = GetCallBackUrl(notify.orderInfo); if (string.IsNullOrEmpty(notifyUrl)) { notify.tmr.Dispose(); notify.tmr = null; } else { string callback = WebClientHelper.GetString(notifyUrl, string.Empty, "GET", System.Text.Encoding.GetEncoding("GB2312")); if (callback.ToLower() == "ok" || notify.orderInfo.notifycount == 10) { notify.tmr.Dispose(); notify.tmr = null; } if (notify.orderInfo.notifycount == 0 || callback.ToLower() == "ok") { notify.orderInfo.notifycount++; notify.orderInfo.notifystat = callback.ToLower() == "ok" ? 2 : 4; notify.orderInfo.againNotifyUrl = notifyUrl; notify.orderInfo.notifycontext = callback; OrderBankFactory.NotifyResult(notify.orderInfo); } (notify.tmr).Change(TimeSpan.FromSeconds(10 * notify.orderInfo.notifycount), TimeSpan.FromSeconds(10 * notify.orderInfo.notifycount)); } }
//#region ProcessNotify ///// <summary> ///// 记录在队列中失败列表 重新补发 ///// </summary> //private static void ProcessNotify() //{ // DataSet ds = BankNotify.Instance.GetNotifyFailList(); // if (ds != null) // { // try // { // foreach (var row in ds.Tables[0].Rows) // { // var apiNotify = new APINotification(); // var notifyInfo = new OrderNotifyX { Class = 1 // , NotifyUrl = row["againNotifyUrl"].ToString() // , OrderId = row["orderid"].ToString() // }; // var tmr = new Timer(apiNotify.NotifyCheckStatus, notifyInfo, 0, 1000); // notifyInfo.Tmr = tmr; // } // } // catch (Exception exception) // { // ExceptionHandler.HandleException(exception); // } // } // //var apiNotify = new APINotification(); // //for (int j = 0; j < NotifybatchSize; j++) // //{ // // try // // { // // var order = apiNotify.ReceiveFromQueue(NotifyqueueTimeout); // // order.notifycount = 0; // // var notifyInfo = new OrderNotify { OrderInfo = order }; // // var tmr = new Timer(apiNotify.NotifyCheckStatus, notifyInfo, 0, 1000); // // notifyInfo.Tmr = tmr; // // } // // catch (Exception exception) // // { // // ExceptionHandler.HandleException(exception); // // } // //} //} //#endregion #region ProcessNotify /// <summary> /// 记录在队列中失败列表 重新补发 /// </summary> private static void ProcessNotify() { var apiNotify = new APINotification(); for (int j = 0; j < NotifybatchSize; j++) { try { var order = apiNotify.ReceiveFromQueue(NotifyqueueTimeout); if (order != null) { order.notifycount = 0; var notifyInfo = new OrderNotify { OrderInfo = order }; //var tmr = notifyInfo.Tmr = new Timer(apiNotify.NotifyCheckStatus, notifyInfo, 0, 1000);; } else { break; } } catch (Exception exception) { ExceptionHandler.HandleException(exception); } } }
public void StartTask(OrderNotify info) { Thread threadHand1 = new Thread(() => Process(info)); threadHand1.IsBackground = true; threadHand1.SetApartmentState(ApartmentState.STA); threadHand1.Start(); }
private bool UpdateOrder(OrderNotify notify) { DbCommand storedProcCommand = this.database.GetStoredProcCommand("ss_UpdateHadPayOrder"); this.database.AddInParameter(storedProcCommand, "GatewayOrderId", DbType.String, ""); int ret = this.database.ExecuteNonQuery(storedProcCommand); if (ret > 0) { return(true); } return(false); }
protected void btnOK_Click(object sender, System.EventArgs e) { WriteBackOrders(); IList <string> orders = ShoppingProcessor.GetPayingOrder(); if (orders.Count == 0) { return; } ErrorLog.Write("start go WXOrderCheckJob"); StringBuilder sb = new StringBuilder(); foreach (var orderId in orders) { sb.Append(orderId); } ErrorLog.Write(sb.ToString()); masterSettings = SettingsManager.GetMasterSettings(false); NotifyClient notifyClient = new NotifyClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey); foreach (var orderItem in orders) { ErrorLog.Write("开始准备请求微信服务器"); string payOrderInfo = LoadWXHadPayOrder(orderItem); ErrorLog.Write(payOrderInfo); OrderNotify orderNotify = notifyClient.GetOrderStatusNotify(payOrderInfo); if (orderNotify != null) { if (orderNotify.result_code == "SUCCESS" && !string.IsNullOrEmpty(orderNotify.transaction_id)) { //UpdateOrder(orderNotify); OrderInfo orderInfo = ShoppingProcessor.GetOrderInfo(orderItem); orderInfo.GatewayOrderId = orderNotify.transaction_id; DateTime payDate = DateTime.MinValue; DateTime.TryParseExact(orderNotify.time_end, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out payDate); orderInfo.PayDate = payDate; if (orderInfo != null) { PayOrder(orderInfo); ErrorLog.Write(string.Format("用户已支付成功,检测到的未即时回写订单状态的订单{0}使用jobs回写状态!", orderNotify.out_trade_no)); } } } } }
public static void addNotify(OrderNotify notify) { if (pool.Count > poolSize) { pool.Clear(); } string key = getKey(notify.openid, notify.appid, notify.out_trade_no); if (!pool.ContainsKey(key)) { pool.Add(key, notify); } else { pool[key] = notify; } }
public OrderNotify GetOrderStatusNotify(string xml) { OrderNotify result = null; try { if (string.IsNullOrEmpty(xml)) { result = null; } else { result = Utils.GetNotifyObject <OrderNotify>(xml); } } catch { } return(result); }
public void orderNotify() { OrderNotify notify = XmlConvert.getObj <OrderNotify>(Request.InputStream); WxBaseMsg resp = new WxBaseMsg() { return_code = WxReturnCode.FAIL, return_msg = "OK" }; if (notify.return_code.Equals(WxReturnCode.SUCCESS)) { OrderNotifyPool.addNotify(notify); notify.return_code = WxReturnCode.SUCCESS; notify.return_code = "Recive notify fail"; Response.Write(notify.toXml()); } else { Response.Write(notify.toXml()); } }
/// <summary> /// 记录在队列中失败列表 重新补发 /// </summary> private static void ProcessNotify() { BLL.OrderBankNotify notifyBLL = new viviapi.BLL.OrderBankNotify(); for (int j = 0; j < notifybatchSize; j++) { try { OrderBankInfo _order = notifyBLL.ReceiveFromQueue(notifyqueueTimeout); _order.notifycount = 0; OrderNotify notifyInfo = new OrderNotify(); notifyInfo.orderInfo = _order; Timer Tmr = new Timer(notifyBLL.NotifyCheckStatus, notifyInfo, 0, 1000); notifyInfo.tmr = Tmr; } catch { } } }
public IList <CheckResult <AddressDTO> > CheckAddress(CallSource callSource, IUnitOfWork db, AddressDTO address, long?orderId, out AddressDTO addressWithCorrection) { if (orderId.HasValue && orderId.Value == 0) { throw new ArgumentOutOfRangeException("order.Id", "Should be non zero"); } addressWithCorrection = null; var checkResults = _addressService.CheckAddress(callSource, address); OrderNotify dbStampsOrderNotify = null; foreach (var subResult in checkResults) { //Stamps if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckStamps.ToString()) { if (orderId.HasValue) { dbStampsOrderNotify = new OrderNotify() { OrderId = orderId.Value, Type = (int)OrderNotifyType.AddressCheckStamps, Message = StringHelper.Substring(subResult.Message, 512), Status = (int)subResult.Status, CreateDate = _time.GetAppNowTime() }; db.OrderNotifies.Add(dbStampsOrderNotify); } } //Previous correction address if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckWithPerviousCorrection.ToString()) { addressWithCorrection = subResult.Data; if (orderId.HasValue) { db.OrderNotifies.Add(new OrderNotify() { OrderId = orderId.Value, Type = (int)OrderNotifyType.AddressCheckWithPerviousCorrection, Message = StringHelper.Substring(subResult.Message, 512), Status = subResult.Status, CreateDate = _time.GetUtcTime() }); } if (subResult.Status < (int)AddressValidationStatus.Invalid && subResult.Status != (int)AddressValidationStatus.None) { if (addressWithCorrection != null && String.IsNullOrEmpty(addressWithCorrection.Address1) && String.IsNullOrEmpty(addressWithCorrection.Address2) && String.IsNullOrEmpty(addressWithCorrection.City) && String.IsNullOrEmpty(addressWithCorrection.State) && String.IsNullOrEmpty(addressWithCorrection.Country) && String.IsNullOrEmpty(addressWithCorrection.Zip) && String.IsNullOrEmpty(addressWithCorrection.ZipAddon)) { addressWithCorrection = null; } if (addressWithCorrection != null) { /* * Похоже идея автоматически менять адрес на предыдущий не совсем хорошая, есть клиент например который хотел послать посылку на новый адрес а мы послали на старый 110-4229580-1843404 * Давай теперь вместо автоматического исправления адреса просто писать коммент, «previous delivery to %Old_Address% was successful” */ if (orderId.HasValue) { var addressString = AddressHelper.ToString(addressWithCorrection, ", "); db.OrderComments.Add(new OrderComment() { OrderId = orderId.Value, Message = String.Format("[System] Previous delivery to \"{0}\" was successful", addressString), Type = (int)CommentType.Address, CreateDate = _time.GetUtcTime() }); } //NOTE: Previous correction address uses only to create order comment addressWithCorrection = null; } } } if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckMelissa.ToString()) { //Nothing } if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckGoogleGeocode.ToString()) { if (orderId.HasValue) { db.OrderNotifies.Add(new OrderNotify() { OrderId = orderId.Value, Type = (int)OrderNotifyType.AddressCheckGoogleGeocode, Message = StringHelper.Substring(subResult.Message, 512), Status = subResult.Status, CreateDate = _time.GetUtcTime() }); } } if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckFedex.ToString()) { if (orderId.HasValue) { db.OrderNotifies.Add(new OrderNotify() { OrderId = orderId.Value, Type = (int)OrderNotifyType.AddressCheckFedex, Message = StringHelper.Substring(subResult.Message, 512), Status = subResult.Status, CreateDate = _time.GetUtcTime() }); } var stampsResult = checkResults.FirstOrDefault(r => r.AdditionalData[0] == OrderNotifyType.AddressCheckStamps.ToString()); if (stampsResult != null && stampsResult.Status >= (int)AddressValidationStatus.Invalid) { if (subResult.Status < (int)AddressValidationStatus.Invalid) { if (addressWithCorrection == null && subResult.Data != null) { var correctionCandidate = subResult.Data; correctionCandidate.FullName = address.FullName; //TASK: If stamps verify it replace it, and don’t show errors. var addressCandidateResults = _addressService.CheckAddress(callSource, correctionCandidate, new Core.Models.Settings.AddressProviderType[] { Core.Models.Settings.AddressProviderType.Stamps }); var stampsCandidateResult = addressCandidateResults.FirstOrDefault(r => r.AdditionalData[0] == OrderNotifyType.AddressCheckStamps.ToString()); if (stampsCandidateResult.Status < (int)AddressValidationStatus.Invalid) { _log.Info("Replacing address to Fedex Effective address"); stampsResult.Status = stampsCandidateResult.Status; if (dbStampsOrderNotify != null) { dbStampsOrderNotify.Status = stampsCandidateResult.Status; } if (orderId.HasValue) { db.OrderComments.Add(new OrderComment() { OrderId = orderId.Value, Message = String.Format("[System] Address was replaced by Fedex \"Effective address\""), Type = (int)CommentType.Address, CreateDate = _time.GetUtcTime() }); } addressWithCorrection = subResult.Data; } } } } } } return(checkResults); }
public void Execute(XmlNode node) { ErrorLog.Write("start go WXOrderCheckJob"); WriteBackOrders(); // 取支付方式 partners = GetWxPayPartners(); IDictionary <string, string> orders = ShoppingProcessor.GetWxPayingOrder(); if (orders.Count == 0) { return; } StringBuilder sb = new StringBuilder(); foreach (var order in orders) { sb.Append(order.Key); } ErrorLog.Write(sb.ToString()); masterSettings = SettingsManager.GetMasterSettings(false); NotifyClient notifyClient = null; WxPayPartner partner = null; foreach (var order in orders) { ErrorLog.Write("开始准备请求微信服务器"); string orderId = order.Key; string gateway = order.Value.ToLower(); partner = null; if (!partners.TryGetValue(gateway, out partner)) { ErrorLog.Write("找不到支付网关信息:" + gateway); continue; } string payOrderInfo = LoadWXHadPayOrder(orderId, partner); ErrorLog.Write(payOrderInfo); notifyClient = new NotifyClient(partner.AppId, partner.AppSecret, partner.PartnerId, partner.PartnerKey, partner.SignKey); OrderNotify orderNotify = notifyClient.GetOrderStatusNotify(payOrderInfo); if (orderNotify != null) { if (orderNotify.result_code == "SUCCESS" && !string.IsNullOrEmpty(orderNotify.transaction_id)) { //UpdateOrder(orderNotify); OrderInfo orderInfo = ShoppingProcessor.GetOrderInfo(orderId); orderInfo.GatewayOrderId = orderNotify.transaction_id; DateTime payDate = DateTime.MinValue; DateTime.TryParseExact(orderNotify.time_end, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out payDate); orderInfo.PayDate = payDate; if (orderInfo != null) { PayOrder(orderInfo); ErrorLog.Write(string.Format("用户已支付成功,检测到的未即时回写订单状态的订单{0}使用jobs回写状态!", orderNotify.out_trade_no)); } } } } }
/// <summary> /// /// </summary> /// <param name="info"></param> private void Process(OrderNotify info) { try { string notifyUrl = info.NotifyUrl; if (string.IsNullOrEmpty(notifyUrl)) { return; } string callback = string.Empty; string status = string.Empty; string message = string.Empty; string statusCode = string.Empty; string statusDesc = string.Empty; bool isOk = false; try { callback = viviLib.Web.WebClientHelper.GetString(notifyUrl , string.Empty , "GET" , Encoding.GetEncoding("GB2312") , 1 * 60 * 1000); isOk = Utility.CheckCallBackIsSuccess(info.OrderInfo.version, callback); } catch (WebException e) { message = e.Message; status = e.Status.ToString(); if (e.Status == WebExceptionStatus.ProtocolError) { statusCode = ((HttpWebResponse)e.Response).StatusCode.ToString(); statusDesc = ((HttpWebResponse)e.Response).StatusDescription; } } catch (Exception e) { message = e.Message; } int notifystat = isOk ? 2 : 4; var notifyInfo = new Model.Order.Bank.BankNotify() { orderid = info.OrderInfo.orderid, status = status, message = message, httpStatusCode = statusCode, StatusDescription = statusDesc, againNotifyUrl = notifyUrl, notifystat = notifystat, notifycontext = callback, notifytime = DateTime.Now }; BankNotify.Instance.Insert(notifyInfo); if (isOk) { if (info.Tmr != null) { info.Tmr.Dispose(); info.Tmr = null; } } } catch (Exception exception) { ExceptionHandler.HandleException(exception); } }