/// <summary> /// 商家充值回调方法 /// 窦海超 /// 2015年5月29日 15:17:07 /// </summary> /// <returns></returns> public dynamic BusinessRechargeNotify() { try { #region 参数绑定 var request = System.Web.HttpContext.Current.Request; AlipayNotifyData notify = new AlipayNotifyData(); notify.buyer_email = request["buyer_email"]; notify.trade_status = request["trade_status"]; notify.out_trade_no = request["out_trade_no"]; notify.trade_no = request["trade_no"]; notify.total_fee = ParseHelper.ToDecimal(request["total_fee"], 0); notify.out_biz_no = ParseHelper.ToInt(request["body"], 0);//businessid #endregion //如果状态为空或状态不等于同步成功和异步成功就认为是错误 if (string.IsNullOrEmpty(notify.trade_status) || notify.total_fee <= 0) { string fail = string.Concat("商家充值状态是空或金额<=0"); LogHelper.LogWriter(fail); return("fail"); } #region 回调完成状态 if (notify.trade_status == "TRADE_SUCCESS" || notify.trade_status == "TRADE_FINISHED") { if (new BusinessRechargeDao().Check(notify.trade_no)) { //如果存在就退出,这里写的很扯,因为支付宝要的是success不带双引号. //但WEBAPI直接返回时带引号,所以现在要去库里查一次。 //回头找到原因一定要改 return("success"); } string orderNo = notify.out_trade_no; if (string.IsNullOrEmpty(orderNo) || notify.out_biz_no <= 0) { string fail = string.Concat("商家充值错误啦orderNo:", orderNo, ",商家ID为:", notify.out_biz_no); LogHelper.LogWriter(fail); return("fail"); } Ets.Model.DataModel.Business.BusinessRechargeModel businessRechargeModel = new Ets.Model.DataModel.Business.BusinessRechargeModel() { BusinessId = notify.out_biz_no, OrderNo = orderNo, OriginalOrderNo = notify.trade_no,//第三方的订单号 PayAmount = notify.total_fee, PayBy = notify.buyer_email, PayStatus = 1, PayType = 1 }; BusinessRechargeSusess(businessRechargeModel); } #endregion } catch (Exception ex) { LogHelper.LogWriter(ex, "Alipay自动返回异常"); return("fail"); } return("fail"); }
/// <summary> /// 订单回调 /// 窦海超 /// 2015年5月12日 14:36:48 /// </summary> /// <returns></returns> public dynamic Notify() { try { #region 参数绑定 var request = System.Web.HttpContext.Current.Request; string sign = request["sign"]; string sign_type = request["sign_type"]; string notify_data = request["notify_data"]; AlipayNotifyData notify = new AlipayNotifyData(); if (!string.IsNullOrEmpty(notify_data)) { //如果是二维码支付 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(notify_data); notify.buyer_email = xmlDoc.SelectSingleNode("notify/buyer_email").InnerText; notify.trade_status = xmlDoc.SelectSingleNode("notify/trade_status").InnerText; notify.out_trade_no = xmlDoc.SelectSingleNode("notify/out_trade_no").InnerText; notify.trade_no = xmlDoc.SelectSingleNode("notify/trade_no").InnerText; } else { //否则是骑士代付 notify.buyer_email = request["buyer_email"]; notify.trade_status = request["trade_status"]; notify.out_trade_no = request["out_trade_no"]; notify.trade_no = request["trade_no"]; } #endregion //如果状态为空或状态不等于同步成功和异步成功就认为是错误 if (string.IsNullOrEmpty(notify.trade_status)) { string fail = string.Concat("错误啦trade_status:", notify.trade_status, "。sign:", sign, "。notify_data:", notify_data); LogHelper.LogWriter(fail); return("fail"); } #region 回调完成状态 if (notify.trade_status == "TRADE_SUCCESS" || notify.trade_status == "TRADE_FINISHED") { string orderNo = notify.out_trade_no; if (string.IsNullOrEmpty(orderNo) || !orderNo.Contains("_")) { string fail = string.Concat("错误啦orderNo:", orderNo); LogHelper.LogWriter(fail); return("fail"); } int productId = ParseHelper.ToInt(orderNo.Split('_')[0]); //产品编号 int orderId = ParseHelper.ToInt(orderNo.Split('_')[1]); //主订单号 int orderChildId = ParseHelper.ToInt(orderNo.Split('_')[2]); //子订单号 int payStyle = ParseHelper.ToInt(orderNo.Split('_')[3]); //支付方式(1 用户支付 2 骑士代付) if (orderId <= 0 || orderChildId <= 0) { string fail = string.Concat("错误啦orderId:", orderId, ",orderChildId:", orderChildId); LogHelper.LogWriter(fail); return("fail"); } OrderChildFinishModel model = new OrderChildFinishModel() { orderChildId = orderChildId, orderId = orderId, payBy = notify.buyer_email, payStyle = payStyle, payType = PayTypeEnum.ZhiFuBao.GetHashCode(), originalOrderNo = notify.trade_no, }; if (orderChildDao.FinishPayStatus(model)) { //jpush //Ets.Service.Provider.MyPush.Push.PushMessage(1, "订单提醒", "有订单被抢了!", "有超人抢了订单!", myorder.businessId.ToString(), string.Empty); FinishOrderPushMessage(model);//完成后发送jpush消息 string success = string.Concat("成功,当前订单OrderId:", orderId, ",OrderChild:", orderChildId); LogHelper.LogWriter(success); return("success"); } } #endregion } catch (Exception ex) { LogHelper.LogWriter(ex, "Alipay自动返回异常"); return("fail"); } return("fail"); }