Exemplo n.º 1
0
        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));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        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));
                        }
                    }
                }
            }
        }