/// <summary>
        /// 刷还系统通知
        /// </summary>
        public void Notice()
        {
            string Resp    = Request.Form["resp"];
            string Sign    = Request.Form["sign"];
            string SignStr = Resp;

            Resp = LokFuEncode.Base64Decode(Resp, "utf-8");
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Resp);
            }
            catch (Exception Ex)
            {
                Response.Write(Ex.ToString());
                return;
            }
            if (json == null)
            {
                Response.Write("Json Null");
                return;
            }
            string resultcode = json["resultcode"].ToString(); //交易结果码
            string resultmsg  = json["resultmsg"].ToString();  //交易结果信息
            string queryid    = json["queryid"].ToString();    //交易流水号
            string txnamt     = json["txnamt"].ToString();     //交易金额\
            string merid      = json["merid"].ToString();      //交易金额
            string orderid    = json["orderid"].ToString();    //交易金额

            JobItem JobItem = this.Entity.JobItem.FirstOrDefault(o => o.RunNum == orderid);

            if (JobItem == null)
            {
                Response.Write("E1");
                return;
            }
            if (JobItem.State != 2)
            {
                Response.Write("S1");
                return;
            }
            if (JobItem.RunState != 0 && JobItem.RunState != 2)
            {
                Response.Write("S2");
                return;
            }
            JobUserPay JobUserPay = Entity.JobUserPay.FirstOrDefault(n => n.PayWay == JobItem.PayWay && n.UId == JobItem.UId);

            if (JobUserPay == null)
            {
                Response.Write("E2");
                return;
            }
            string MD5Str = SignStr + JobUserPay.MerKey;
            string sign   = MD5Str.GetMD5();
            //================================================
            //这里记录日志
            JobLog JobLog = new JobLog();

            JobLog.PayWay  = JobItem.PayWay;
            JobLog.ReqNo   = JobItem.RunNum;
            JobLog.TNum    = JobItem.TNum;
            JobLog.Trade   = "";
            JobLog.Amount  = JobItem.RunMoney;
            JobLog.Way     = "Notice";
            JobLog.AddTime = DateTime.Now;
            JobLog.Data    = Request.Form.ToString();
            JobLog.State   = 1;
            Entity.JobLog.AddObject(JobLog);
            Entity.SaveChanges();
            //================================================
            if (Sign != sign)
            {
                Response.Write("E2");
                return;
            }
            if (JobUserPay.MerId != merid)
            {
                Response.Write("E1");
                return;
            }
            if (resultcode == "0000")
            {
                JobItem = JobItem.PaySuccess(Entity);
            }
            if (resultcode == "1004")
            {
                JobItem = JobItem.PayFail(Entity);
            }
            Response.Write("0000");
        }
Пример #2
0
        public void Notice()
        {
            #region 接收与验签
            Dictionary <string, string> resData = new Dictionary <string, string>();
            NameValueCollection         coll    = Request.Form;
            string[] requestItem = coll.AllKeys;
            for (int i = 0; i < requestItem.Length; i++)
            {
                string formvalue = Request.Form[requestItem[i]];
                if (formvalue.IndexOf("%") != -1)
                {
                    formvalue = HttpUtility.UrlDecode(formvalue, Encoding.UTF8);
                }
                resData.Add(requestItem[i], formvalue);
            }
            if (resData["sign"] == null || resData["rt5_orderId"] == null || resData["rt6_serialNumber"] == null || resData["rt8_orderAmount"] == null || resData["rt9_orderStatus"] == null)
            {
                Response.Write("NULL");
                return;
            }
            string  rt5_orderId = resData["rt5_orderId"]; //返回状态
            JobItem JobItem     = this.Entity.JobItem.FirstOrDefault(o => o.RunNum == rt5_orderId);
            if (JobItem == null)
            {
                Response.Write("E1");
                return;
            }
            if (JobItem.State != 2)
            {
                Response.Write("S1");
                return;
            }
            if (JobItem.RunState != 0 && JobItem.RunState != 2)
            {
                Response.Write("S2");
                return;
            }
            JobPayWay JobPayWay = Entity.JobPayWay.FirstOrDefault(n => n.Id == JobItem.PayWay);
            if (JobPayWay == null)
            {
                Response.Write("E2");
                return;
            }
            string[] JobPayWayArr = JobPayWay.QueryArray.Split(',');
            string   MerId        = JobPayWayArr[0];
            string   MerKey       = JobPayWayArr[1];
            #endregion
            string  rt6_serialNumber = resData["rt6_serialNumber"];
            string  rt8_orderAmount  = resData["rt8_orderAmount"];
            decimal Amount           = decimal.Parse(rt8_orderAmount) / 100;
            //================================================
            //这里记录日志
            JobLog JobLog = new JobLog();
            JobLog.PayWay  = JobItem.PayWay;
            JobLog.ReqNo   = JobItem.RunNum;
            JobLog.TNum    = JobItem.TNum;
            JobLog.Trade   = "";
            JobLog.Amount  = JobItem.RunMoney;
            JobLog.Way     = "Notice";
            JobLog.AddTime = DateTime.Now;
            JobLog.Data    = Request.Form.ToString();
            JobLog.State   = 1;
            Entity.JobLog.AddObject(JobLog);
            Entity.SaveChanges();
            //================================================
            //验签
            //Dictionary<string, string> map = Utils.FilterPara(resData);
            string data = Utils.CreateLinkString(resData);
            if (!veritySign(data, MerKey))
            {
                Response.Write("E0");
            }

            string status = resData["rt9_orderStatus"]; //返回状态
            string sign   = resData["sign"];
            if (status != "SUCCESS")
            {
                Response.Write("E3");
                return;
            }
            else
            {
                if (Amount == JobItem.RunMoney)
                {
                    JobItem.PaySuccess(Entity);
                    Response.Write("success");
                }
                else
                {
                    Response.Write("E99");
                }
            }
        }