public static string CancelOrder(string Order_id) { try { Rc.Model.Resources.Model_UserOrder order = new Rc.Model.Resources.Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); order = bll.GetModel(Order_id.Filter()); if (order != null) { order.UserOrder_Status = 4; order.UserOrder_FinishTime = DateTime.Now; } if (bll.Update(order)) { return("1"); } else { return(""); } } catch (Exception) { 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, Request.Form["notify_id"], Request.Form["sign"]); if (verifyResult)//验证成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //商户订单号 string out_trade_no = Request.Form["out_trade_no"].Filter(); //支付宝交易号 string trade_no = Request.Form["trade_no"].Filter(); //交易状态 string trade_status = Request.Form["trade_status"].Filter(); //买家支付宝账号 string buyer_email = Request.Form["buyer_email"]; int orderStatus = 1;// (int)XHZ.Model.UOrderStatus.等待付款; if (trade_status.ToUpper() == "TRADE_FINISHED") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知 orderStatus = (int)UOrderStatus.付款成功; } else if (trade_status.ToUpper() == "TRADE_SUCCESS") { //判断该笔订单是否在商户网站中已经做过处理 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 //注意: //付款完成后,支付宝系统发送该交易状态通知 orderStatus = (int)UOrderStatus.付款成功; } else { } //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— Rc.Web.Payment.Core.LogHandler.WriteLogForPay(out_trade_no, "付款成功", trade_no); #region 付款成功 异步更新订单表 author:Ethan Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(out_trade_no); if (orderStatus == (int)UOrderStatus.付款成功 && model.UserOrder_Status == (int)UOrderStatus.待付款) { model.UserOrder_Paytool = UserOrder_PaytoolEnum.ALIPAY.ToString(); model.UsreOrder_Buyeremail = buyer_email; model.trade_no = trade_no; model.trade_status = trade_status; model.UserOrder_Status = (int)UOrderStatus.完成; model.UserOrder_FinishTime = DateTime.Now; bool executeFlag = false; if (new BLL_UserBuyResources().GetRecordCount(string.Format("UserId='{0}' and Book_id='{1}' ", model.UserId, model.Book_Id)) == 0) { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = model.UserId; buyModel.Book_id = model.Book_Id; buyModel.BookPrice = model.Book_Price; buyModel.BuyType = UserOrder_PaytoolEnum.ALIPAY.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = "******"; #endregion executeFlag = bll.UpdateAndAddUserBuyResources(model, buyModel); } else { executeFlag = bll.Update(model); } if (executeFlag) { //try //{ // P_User userModel = new P_UserBLL().GetModel(model.user_id); // pfunction.SendSMS(userModel.moblie, "您的订单" + model.OrderNo + "已支付成功"); //} //catch //{ //} //if (new U_OrdersHandleBLL().GetRecordCount("OrderId='" + model.OrderId + "' and OperateUser='******'") == 0) //{ // pfunction.InsertOrderHandle(model.OrderId, "您已" + XHZ.Common.EnumService.GetDescription<UOrderStatus>(orderStatus), "支付接口异步回调"); //} new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(Request.Url.ToString(), string.Format("支付宝回调。购买资源成功,购买人:{0},资源标识:{1}" , model.UserId, model.Book_Id)); Response.Write("success"); //请不要修改或删除 } } #endregion ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
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", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); 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", "订单查询失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { Log.Info(this.GetType().ToString(), "订单支付成功,异步回调"); #region 支付成功,异步更新订单表2016-06-30TS Model_UserOrder model = new Model_UserOrder(); BLL_UserOrder bll = new BLL_UserOrder(); model = bll.GetModelByOrderNo(notifyData.GetValue("out_trade_no").ToString()); if (model.UserOrder_Status == (int)UOrderStatus.待付款 || string.IsNullOrEmpty(model.trade_no) || string.IsNullOrEmpty(model.trade_status)) { model.UserOrder_Paytool = UserOrder_PaytoolEnum.WXPAY.ToString(); model.UsreOrder_Buyeremail = notifyData.GetValue("openid").ToString(); model.trade_no = notifyData.GetValue("transaction_id").ToString(); model.trade_status = notifyData.GetValue("return_code").ToString(); model.UserOrder_Status = (int)UOrderStatus.完成; model.UserOrder_FinishTime = DateTime.Now; bool executeFlag = false; if (new BLL_UserBuyResources().GetRecordCount(string.Format("UserId='{0}' and Book_id='{1}' ", model.UserId, model.Book_Id)) == 0) { #region 用户购买资源表 Model_UserBuyResources buyModel = new Model_UserBuyResources(); buyModel.UserBuyResources_ID = Guid.NewGuid().ToString(); buyModel.UserId = model.UserId; buyModel.Book_id = model.Book_Id; buyModel.BookPrice = model.Book_Price; buyModel.BuyType = UserOrder_PaytoolEnum.WXPAY.ToString(); buyModel.CreateTime = DateTime.Now; buyModel.CreateUser = "******"; #endregion executeFlag = bll.UpdateAndAddUserBuyResources(model, buyModel); } else { executeFlag = bll.Update(model); } if (executeFlag) { new Rc.Cloud.BLL.BLL_clsAuth().AddLogFromBS(page.Request.Url.ToString(), string.Format("微信回调。购买资源成功,购买人:{0},资源标识:{1}" , model.UserId, model.Book_Id)); } } #endregion WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); page.Response.Write(res.ToXml()); page.Response.End(); } }