예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            WxPayAPI.Log.Info(this.GetType().ToString(), "--异步回调处理开始--");
            Dictionary <string, string> data = GetRequestPost();
            string notify_id    = Request.Form["notify_id"]; //获取notify_id
            string sign         = Request.Form["sign"];      //获取sign
            string SerialNo     = Request.Form["out_trade_no"];
            string TradeNo      = Request.Form["trade_no"];
            string price        = Request.Form["buyer_pay_amount"];
            string trade_status = Request.Form["trade_status"];
            string gmt_payment  = Request.Form["notify_time"];

            WxPayAPI.Log.Info("Form:", AlipaySignature.GetSignContent(data));
            if (notify_id == null || notify_id == "")
            {
                WxPayAPI.Log.Info("", "参数错误");
                return;
            }
            Notify aliNotify = new Notify();

            if (aliNotify.GetResponseTxt(notify_id) != "true")
            {
                WxPayAPI.Log.Info("", "参数错误");
                return;
            }
            WxPayAPI.Log.Info("订单号:", SerialNo);
            bool flag = aliNotify.GetSignVeryfy(data, sign);     //AlipaySignature.RSACheckV1(sPara, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, "RSA", false);

            // bool checkSign = AlipaySignature.RSACheckV2(data, AlipayConfig.ALIPAY_PUBLIC_KEY);
            if (flag)
            {
                WxPayAPI.Log.Info("", "验签成功");
                _database = new Database("ecard");
                using (var _databaseInstance = new DatabaseInstance(_database))
                {
                    var sql  = "select * from fz_Orders where orderNo=@orderNo";
                    var item = new QueryObject <Ecard.Models.Order>(_databaseInstance, sql, new { orderNo = SerialNo }).FirstOrDefault();
                    if (item != null)
                    {
                        if (item.payState == Ecard.Models.PayStates.non_payment && item.orderState == Ecard.Models.OrderStates.awaitPay)
                        {
                            WxPayAPI.Log.Info("payAmount", item.payAmount.ToString());
                            WxPayAPI.Log.Info("price", price);
                            decimal amount = 0;
                            decimal.TryParse(price, out amount);
                            WxPayAPI.Log.Info("amount", amount.ToString());
                            if (item.payAmount == amount)
                            {
                                WxPayAPI.Log.Info("金额", "成功");
                                _databaseInstance.BeginTransaction();
                                item.payState   = Ecard.Models.PayStates.paid;
                                item.orderState = Ecard.Models.OrderStates.paid;
                                item.payType    = PayTypes.Alipay;
                                item.submitTime = DateTime.Now;
                                _databaseInstance.Update(item, "fz_Orders");



                                var sql2  = "select * from fz_Accounts where accountId=@accountId";
                                var item2 = new QueryObject <Ecard.Models.Account>(_databaseInstance, sql2, new { accountId = item.userId }).FirstOrDefault();
                                if (item2 != null)
                                {
                                    if (!string.IsNullOrWhiteSpace(item2.openID))
                                    {
                                        var message = new Fz_Messages();
                                        message.accountId  = item2.accountId;
                                        message.openId     = item2.openID;
                                        message.state      = MessagesState.staySend;
                                        message.submitTime = DateTime.Now;
                                        message.keyword1   = item.orderNo;
                                        message.keyword2   = "已付款";
                                        message.msgType    = MsgType.orderState;
                                        _databaseInstance.Insert(message, "Fz_Messages");
                                    }
                                }

                                _databaseInstance.Commit();
                            }
                        }
                    }
                }
                WxPayAPI.Log.Info("交易", "成功");
                //交易成功
                Response.Write("success");
            }
            else
            {
                WxPayAPI.Log.Info("", "验签失败");
            }
        }
예제 #2
0
 public void OnAutomaticReceiptTimer(object source, System.Timers.ElapsedEventArgs e)
 {
     try
     {
         var container1          = getContainer();
         var IMessagesService    = container1.Resolve <IMessagesService>();
         var IOrderService       = container1.Resolve <IOrderService>();
         var IOrderDetailService = container1.Resolve <IOrderDetailService>();
         var IRebateService      = container1.Resolve <IRebateService>();
         var ISiteService        = container1.Resolve <ISiteService>();
         var IAccountService     = container1.Resolve <IAccountService>();
         var TransactionHelper   = container1.Resolve <TransactionHelper>();
         var site = ISiteService.Query(null).FirstOrDefault();
         if (site == null)
         {
             log.Debug(string.Format("请先设置配置信息!"));
             return;
         }
         var list = IOrderService.GetOrder();
         if (list == null)
         {
             return;
         }
         foreach (var item in list)
         {
             var order = IOrderService.GetById(item.orderId);
             if (order != null)
             {
                 if (order.orderState != OrderStates.shipped)
                 {
                     continue;
                 }
                 if (order.ShipTime == null)
                 {
                     continue;
                 }
                 if (order.ShipTime.Value.AddDays(8) < DateTime.Now)
                 {
                     continue;
                 }
                 order.orderState = OrderStates.complete;
                 TransactionHelper.BeginTransaction();
                 if (IOrderService.Update(order) > 0)
                 {
                     var account = IAccountService.GetById(order.userId);
                     if (!string.IsNullOrWhiteSpace(account.openID))
                     {
                         var message = new Fz_Messages();
                         message.accountId  = account.accountId;
                         message.keyword1   = order.orderNo;
                         message.keyword2   = "订单完成";
                         message.msg        = "";
                         message.msgType    = MsgType.orderState;
                         message.openId     = account.openID;
                         message.state      = MessagesState.staySend;
                         message.submitTime = DateTime.Now;
                         IMessagesService.Insert(message);
                     }
                     TransactionHelper.Commit();
                     IRebateService.Rebate(order.orderId);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         WxPayAPI.Log.Debug("OnAutomaticReceiptTimer", ex.Message);
     }
 }