/// <summary> /// 检查参数 /// </summary> /// <param name="model">参数对象</param> /// <param name="logger">日志对象</param> /// <returns>true:检查成功,false:检查失败</returns> public static bool CheckParams(NotifyDataModel model, ILogger logger) { if (string.IsNullOrEmpty(model.sid) || string.IsNullOrEmpty(model.ste) || string.IsNullOrEmpty(model.cid) || string.IsNullOrEmpty(model.pid) || string.IsNullOrEmpty(model.oid) || string.IsNullOrEmpty(model.pn) || string.IsNullOrEmpty(model.tf) || string.IsNullOrEmpty(model.fm) || string.IsNullOrEmpty(model.sign)) { StringBuilder sb = new StringBuilder(); JavaScriptSerializer json = new JavaScriptSerializer(); json.Serialize(model, sb); logger.Info("通知参数错误:必填参数为空,回调数据【" + sb.ToString() + "】"); return(false); } return(true); }
public void ProcessRequest(HttpContext context) { try { context.Response.ContentType = "text/plain"; logger.Info("------------------Esalse回调开始------------------------"); logger.Info("请求参数:" + context.Request.RawUrl); NotifyDataModel model = new NotifyDataModel(); model.sid = context.Request["sid"]; model.ste = context.Request["ste"]; model.cid = context.Request["cid"]; model.pid = context.Request["pid"]; model.oid = context.Request["oid"]; model.pn = context.Request["pn"]; model.tf = context.Request["tf"]; model.fm = context.Request["fm"]; model.dm = context.Request["dm"]; model.price = context.Request["price"]; model.sign = context.Request["sign"]; if (!ApiHelper.CheckParams(model, logger)) { context.Response.Write("Fail"); return; } logger.Info("-------------------签名校验开始---------------------------"); if (!ApiHelper.EsalseNotifyCheckSign(model, logger)) { context.Response.Write("Fail"); return; } logger.Info("-------------------通知订单结果开始-------------------------"); //获取校验码 string orderStatus = ApiHelper.GetCfgError(model.ste); if (!string.IsNullOrEmpty(orderStatus)) { logger.Info("结果已知:[" + orderStatus + "]"); int? status = ApiHelper.GetRstStatus(model.ste); string msg = status == 1 ? "N|充值成功" : "N|充值失败"; decimal?cost_price = 0; if (!string.IsNullOrEmpty(model.dm)) { cost_price = Convert.ToDecimal(model.fm) * Convert.ToDecimal(model.dm); } bool rst = ApiHelper.SaveNotify(Convert.ToInt64(model.oid), model.sid, Convert.ToDecimal(model.fm), msg, status, cost_price, Convert.ToDecimal(model.price), logger); if (rst) { context.Response.Write("success"); } else { context.Response.Write("Fail"); } return; } else { string rstMsg = string.Format("结果未知:ste={0}", model.ste); logger.Info(rstMsg); context.Response.Write("Fail"); return; } } catch (Exception ex) { logger.Info("异常:" + ex.Message, ex); logger.Fatal("异常:" + ex.Message, ex); context.Response.Write("Fail System Error"); return; } }