コード例 #1
0
ファイル: OrderRepair.cs プロジェクト: damoOnly/e-commerce
        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));
                        }
                    }
                }
            }
        }