Exemple #1
0
        public override void ProcessNotify()
        {
            WxPayData notifyData = GetNotifyData();

            //检查支付结果中transaction_id是否存在
            if (!notifyData.IsSet("transaction_id"))
            {
                //若transaction_id不存在,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "支付结果中微信订单号不存在");
                page.Response.Write(res.ToXml());
                page.Response.End();
            }

            string transaction_id = notifyData.GetValue("transaction_id").ToString();

            //查询订单,判断订单真实性
            if (!QueryOrder(transaction_id))
            {
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                page.Response.Write(res.ToXml());
                page.Response.End();
            }
            //查询订单成功
            else
            {
                string out_trade_no = notifyData.GetValue("out_trade_no").ToString();
                string trade_no     = transaction_id;
                string result_code  = notifyData.GetValue("result_code").ToString();
                //金额回传原始为分,转换成元
                decimal total_fee = Convert.ToDecimal(notifyData.GetValue("total_fee").ToString()) / 100;
                //支付成功
                if (result_code == "SUCCESS")
                {
                    var type = out_trade_no.Substring(0, 2);
                    if (type == BillType.VIP_BUY)
                    {
                        //充值购买
                        AlipayNotifyHelper.FinishBuy(out_trade_no, PayOption.WEIXIN.Id, trade_no, total_fee);
                    }
                    else if (type == BillType.VIP_USE)
                    {
                        //消费支付
                        AlipayNotifyHelper.FinishUse(out_trade_no, PayOption.WEIXIN.Id, trade_no, total_fee);
                    }
                }

                WxPayData res = new WxPayData();
                res.SetValue("return_code", "SUCCESS");
                res.SetValue("return_msg", "OK");
                page.Response.Write(res.ToXml());
                page.Response.End();
            }
        }
Exemple #2
0
    private void Excute()
    {
        SortedDictionary <string, string> sPara = GetRequestPost();

        if (sPara.Count > 0)//判断是否有带返回参数
        {
            Notify aliNotify    = new Notify();
            bool   verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]);

            if (verifyResult)//验证成功
            {
                //商户订单号
                string out_trade_no = Request.Form["out_trade_no"];

                //支付宝交易号
                string trade_no = Request.Form["trade_no"];

                //交易金额
                decimal total_fee = Convert.ToDecimal(Request.Form["total_fee"]);

                //交易状态
                string trade_status = Request.Form["trade_status"];
                if (trade_status == "TRADE_SUCCESS")
                {
                    //付款完成后,支付宝系统发送该交易状态通知
                    //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                    var type = out_trade_no.Substring(0, 2);
                    if (type == BillType.VIP_BUY)
                    {
                        //充值购买
                        AlipayNotifyHelper.FinishBuy(out_trade_no, PayOption.ALIPAY.Id, trade_no, total_fee);
                    }
                    else if (type == BillType.VIP_USE)
                    {
                        //消费支付
                        AlipayNotifyHelper.FinishUse(out_trade_no, PayOption.ALIPAY.Id, trade_no, total_fee);
                    }

                    /*
                     * else if (type == BillType.VIP_VENUE_BILL)
                     * {
                     *  //场馆结算支付
                     *  PayHelper.FinishVenueBill(out_trade_no, PayOption.ALIPAY.Id, trade_no, total_fee);
                     * }
                     * else if (type == BillType.VIP_REFUND)
                     * {
                     *  //退款支付
                     *  PayHelper.FinishRefund(out_trade_no, PayOption.ALIPAY.Id, trade_no, total_fee);
                     * }*/
                }
                else if (trade_status == "TRADE_FINISHED")
                {
                    //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
                    //请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
                }
                else
                {
                }

                Response.Write("success");  //请不要修改或删除
            }
            else//验证失败
            {
                Response.Write("fail");
            }
        }
        else
        {
            Response.Write("无通知参数");
        }
    }