protected void Page_Load(object sender, EventArgs e) { //读取站点配置信息 Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(); SortedDictionary<string, string> sPara = GetRequestGet(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign")); if (verifyResult)//验证成功 { //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 string trade_no = DTRequest.GetString("trade_no"); //支付宝交易号 string order_no = DTRequest.GetString("out_trade_no"); //获取订单号 string trade_status = DTRequest.GetString("trade_status"); //交易状态 if (trade_status == "WAIT_SELLER_SEND_GOODS" || trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") { //成功状态 Response.Redirect(new Web.UI.BasePage().linkurl("payment", "succeed", order_no)); return; } } } //失败状态 Response.Redirect(new Web.UI.BasePage().linkurl("payment", "error")); return; }
protected void Page_Load(object sender, EventArgs e) { //读取站点配置信息 Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(DTKeys.FILE_SITE_XML_CONFING); SortedDictionary<string, string> sPara = GetRequestGet(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign")); if (verifyResult)//验证成功 { //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表 string trade_no = DTRequest.GetString("trade_no"); //支付宝交易号 string order_no = DTRequest.GetString("out_trade_no"); //获取订单号 string total_fee = DTRequest.GetString("total_fee"); //获取总金额 string subject = DTRequest.GetString("subject"); //商品名称、订单名称 string body = DTRequest.GetString("body"); //商品描述、订单备注、描述 string buyer_email = DTRequest.GetString("buyer_email"); //买家支付宝账号 string trade_status = DTRequest.GetString("trade_status"); //交易状态 string order_type = DTRequest.GetString("extra_common_param"); //订单交易类别 if (DTRequest.GetString("trade_status") == "TRADE_FINISHED" || DTRequest.GetString("trade_status") == "TRADE_SUCCESS") { //成功状态 Response.Redirect(new Web.UI.BasePage().linkurl("payment1", "succeed", order_type, order_no)); return; } } } //失败状态 Response.Redirect(new Web.UI.BasePage().linkurl("payment", "error")); return; }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary<string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign")); //写日志 //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "验证结果:" + verifyResult.ToString() + "\n", System.Text.Encoding.UTF8); if (verifyResult)//验证成功 { string trade_no = DTRequest.GetString("trade_no"); //支付宝交易号 string order_no = DTRequest.GetString("out_trade_no").ToUpper(); //获取订单号 string total_fee = DTRequest.GetString("total_fee"); //获取总金额 string trade_status = DTRequest.GetString("trade_status"); //交易状态 if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS") { if (order_no.StartsWith("R")) //充值订单 { BLL.user_amount_log bll = new BLL.user_amount_log(); Model.user_amount_log model = bll.GetModel(order_no); if (model == null) { Response.Write("该订单号不存在"); return; } if (model.status == 1) //已成功 { Response.Write("success"); return; } if (model.value != decimal.Parse(total_fee)) { Response.Write("订单金额和支付金额不相符"); return; } model.trade_no = trade_no; model.status = 1; model.complete_time = DateTime.Now; bool result = bll.Update(model); if (!result) { Response.Write("修改订单状态失败"); return; } } else if (order_no.StartsWith("B")) //商品订单 { //写日志 //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "商品订单\n", System.Text.Encoding.UTF8); BLL.orders bll = new BLL.orders(); Model.orders model = bll.GetModel(order_no); if (model == null) { //写日志 //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "订单号:" + order_no + "不存在\n", System.Text.Encoding.UTF8); Response.Write("该订单号不存在"); return; } if (model.payment_status == 2) //已付款 { //写日志 //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "订单号:" + order_no + "已付款\n", System.Text.Encoding.UTF8); Response.Write("success"); return; } if (model.order_amount != decimal.Parse(total_fee)) { //写日志 //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "订单号:" + order_no + "订单金额" + model.order_amount + "和支付金额" + total_fee + "不相符\n", System.Text.Encoding.UTF8); Response.Write("订单金额和支付金额不相符"); return; } bool result = bll.UpdateField(order_no, "trade_no='" + trade_no + "',status=2,payment_status=2,payment_time='" + DateTime.Now + "'"); if (!result) { Response.Write("修改订单状态失败"); return; } //写日志 //System.IO.File.AppendAllText(Utils.GetMapPath("alipaylog.txt"), "修改订单状态:" + result.ToString() + "\n", System.Text.Encoding.UTF8); //扣除积分 if (model.point < 0) { new BLL.user_point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no, false); } } } Response.Write("success"); //请不要修改或删除 } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary<string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { Notify aliNotify = new Notify(); bool verifyResult = aliNotify.Verify(sPara, DTRequest.GetString("notify_id"), DTRequest.GetString("sign")); if (verifyResult)//验证成功 { string trade_no = DTRequest.GetString("trade_no"); //支付宝交易号 string order_no = DTRequest.GetString("out_trade_no"); //获取订单号 string total_fee = DTRequest.GetString("total_fee"); //获取总金额 string subject = DTRequest.GetString("subject"); //商品名称、订单名称 string body = DTRequest.GetString("body"); //商品描述、订单备注、描述 string buyer_email = DTRequest.GetString("buyer_email"); //买家支付宝账号 string trade_status = DTRequest.GetString("trade_status"); //交易状态 string order_type = DTRequest.GetString("extra_common_param"); //订单交易类别 if (DTRequest.GetString("trade_status") == "TRADE_FINISHED" || DTRequest.GetString("trade_status") == "TRADE_SUCCESS") { //修改支付状态、时间 if (order_type.ToLower() == DTEnums.AmountTypeEnum.Recharge.ToString().ToLower()) //在线充值 { BLL.amount_log bll = new BLL.amount_log(); Model.amount_log model = bll.GetModel(order_no); if (model == null) { Response.Write("该订单号不存在"); return; } if (model.value != decimal.Parse(total_fee)) { Response.Write("订单金额和支付金额不相符"); return; } model.status = 1; model.complete_time = DateTime.Now; bool result = bll.Update(model); if (!result) { Response.Write("修改订单状态失败"); return; } } else if (order_type.ToLower() == DTEnums.AmountTypeEnum.BuyGoods.ToString().ToLower()) //购买商品 { BLL.orders bll = new BLL.orders(); Model.orders model = bll.GetModel(order_no); if (model == null) { Response.Write("该订单号不存在"); return; } if (model.order_amount != decimal.Parse(total_fee)) { Response.Write("订单金额和支付金额不相符"); return; } bool result = bll.UpdateField(order_no, "payment_status=2,payment_time='" + DateTime.Now + "'"); if (!result) { Response.Write("修改订单状态失败"); return; } //扣除积分 if (model.point < 0) { new BLL.point_log().Add(model.user_id, model.user_name, model.point, "换购扣除积分,订单号:" + model.order_no); } } } Response.Write("success"); //请不要修改或删除 } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }