public ActionResult QueryOrderStatus(string orderno)
        {
            string  sql = "SELECT paytime FROM order_pay WHERE orderno='" + orderno + "'";
            SQLBase s   = new SQLBase();
            List <List <string> > result = s.ExecuteQuery(sql);

            if (result.Count > 0)
            {
                return(Content(result[0][0]));
            }

            return(Content(""));
        }
Exemplo n.º 2
0
        //
        // GET: /Line/1209
        public ActionResult Index(int id)
        {
            string regid    = "";
            string htid     = "";
            string cpcode   = "";
            string username = "";

            htid             = id.ToString();
            ViewData["htid"] = htid;
            //htid = "9421";
            try
            {
                string regid1 = Session["regid"].ToString();
                //string regid1 = "77426";
                if (string.IsNullOrEmpty(regid1))
                {
                    Response.Redirect("http://www.youxuewang.com.cn");
                }
                else
                {
                    regid = Session["regid"].ToString();
                }
                username = Session["username"].ToString();
                LogService.Debug("用户id和用户账户:", regid + "," + username);
            }
            catch (Exception)
            {
            }

            Ht_version        ht   = new Ht_version();
            List <Ht_version> list = ht.Select("where id='" + htid + "'");

            if (list.Count > 0)
            {
                ViewBag.Version = list;
                if (!string.IsNullOrEmpty(list[0].cpno))
                {
                    cpcode = list[0].cpno;
                }
            }

            #region 处理特殊情况下的支付
            //Ht_version ht1 = new Ht_version();
            //List<Ht_version> list1 = ht1.Select("where id='" + htid + "'");
            //if(list1.Count>0)
            //{
            //    ViewBag.Chengren = list1[0].adultprice;
            //    ViewBag.Student = list1[0].studentprice;
            //}


            //ht_bmzf bmzf = new ht_bmzf();
            //List<ht_bmzf> listzf = bmzf.Select("where regid='"+regid+"'");
            //if(listzf.Count>0)
            //{
            //    if (listzf[0].flag == 0)
            //    {
            //        ViewData["flag"] = "(余款)";
            //    }
            //    else
            //    {
            //        ViewData["flag"] = "(全款)";
            //    }
            //}
            #endregion

            SQLBase sb    = new SQLBase();
            string  sqlad = "select * from Ht_version v left join ht_bd_map h on v.id=h.hetong_id left join Baodan b on h.baodan_id=b.id where b.regid='" + regid + "' and v.id='" + htid + "' and ischild=1";
            List <List <string> > listbd = sb.ExecuteQuery(sqlad);

            string sqlstu = "select * from Ht_version v left join ht_bd_map h on v.id=h.hetong_id left join Baodan b on h.baodan_id=b.id where b.regid='" + regid + "' and v.id='" + htid + "' and ischild=0";
            List <List <string> > listbd1 = sb.ExecuteQuery(sqlstu);

            int count  = listbd.Count;
            int count1 = listbd1.Count;
            //int count = 1;
            //int count1 = 0;
            if (listbd1.Count > 0)
            {
                ViewBag.Baodan1 = count1;
            }
            if (listbd.Count > 0)
            {
                ViewBag.Baodan = count;
            }

            //支付信息确认
            SQLBase sqlbase  = new SQLBase();
            string  sqlquery = "select r.truename,o.name from RegisterPresonal r left join org o on r.orgid=o.id where r.id='" + regid + "'";
            List <List <string> > listreg = sqlbase.ExecuteQuery(sqlquery);
            if (listreg.Count > 0)
            {
                ViewData["username"]  = listreg[0][0];
                ViewData["classname"] = listreg[0][1];
            }

            return(View(""));
        }
        public ActionResult Notify(FormCollection coll)
        {
            LogService.LOG_LEVENL = 3;
            LogService.Error(this.GetType().ToString(), "notify parameter count:" + coll.Count);

            string alipayNotifyURL = "https://www.alipay.com/cooperate/gateway.do?service=notify_verify";
            //string alipayNotifyURL = "http://notify.alipay.com/trade/notify_query.do?";//此路径是在上面链接地址无法起作用时替换使用。
            string partner        = aliPayService.Alipay_pid; //partner合作伙伴id(必须填写)
            string key            = aliPayService.Alipay_key; //partner 的对应交易安全校验码(必须填写)
            string _input_charset = "utf-8";                  //编码类型,完全根据客户自身的项目的编码格式而定,千万不要填错。否则极其容易造成MD5加密错误。

            LogService.Error(this.GetType().ToString(), "notify_id=" + coll["notify_id"]);
            alipayNotifyURL = alipayNotifyURL + "&partner=" + partner + "&notify_id=" + coll["notify_id"];

            //获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的
            string responseTxt = aliPayService.Get_Http(alipayNotifyURL, 120000);

            //*******加密签名程序开始*******
            int i;

            //Load Form variables into NameValueCollection variable.

            // Get names of all forms into a string array.
            String[] requestarr = coll.AllKeys;

            //进行排序;
            string[] Sortedstr = aliPayService.BubbleSort(requestarr);


            //构造待md5摘要字符串 ;
            StringBuilder prestr = new StringBuilder();

            for (i = 0; i < Sortedstr.Length; i++)
            {
                if (Request.Form[Sortedstr[i]] != "" && Sortedstr[i] != "sign" && Sortedstr[i] != "sign_type")
                {
                    if (i == Sortedstr.Length - 1)
                    {
                        prestr.Append(Sortedstr[i] + "=" + Request.Form[Sortedstr[i]]);
                    }
                    else
                    {
                        prestr.Append(Sortedstr[i] + "=" + Request.Form[Sortedstr[i]] + "&");
                    }
                }
            }

            prestr.Append(key);

            string mysign = aliPayService.GetMD5(prestr.ToString(), _input_charset);
            //*******加密签名程序结束*******

            string sign = Request.Form["sign"];

            LogService.Debug(this.GetType().ToString(), "responseTxt=" + responseTxt);

            if (mysign == sign && responseTxt == "true")   //验证支付发过来的消息,签名是否正确,只要成功进如这个判断里,则表示该页面已被支付宝服务器成功调用
            //但判断内出现自身编写的程序相关错误导致通知给支付宝并不是发送success的消息或没有更新客户自身的数据库的情况,请自身程序编写好应对措施,否则查明原因时困难之极
            {
                LogService.LOG_LEVENL = 3;

                if (Request.Form["trade_status"] == "WAIT_BUYER_PAY")//   判断支付状态_等待买家付款(文档中有枚举表可以参考)
                {
                    //更新自己数据库的订单语句,请自己填写一下
                    string strOrderNO = Request.Form["out_trade_no"]; //订单号
                    string strPrice   = Request.Form["total_fee"];    //金额    如果你申请了商家购物卷功能,在返回信息里面请不要做金额的判断,否则会校验通过不了。

                    LogService.LOG_LEVENL = 3;

                    LogService.Debug(this.GetType().ToString(), "支付宝返回提示等待买家付款。订单号:" + strOrderNO + ";支付金额:" + strPrice);
                }
                else if (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")//   判断支付状态_交易成功结束(文档中有枚举表可以参考)
                {
                    //更新自己数据库的订单语句,请自己填写一下
                    string  strOrderNO = Request.Form["out_trade_no"]; //订单号
                    string  strPrice   = Request.Form["total_fee"];    //金额
                    SQLBase s          = new SQLBase();

                    string sql = "update order_pay set paytime='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',cash_fee='" + strPrice + "', paytype='支付宝', transaction_id='" + Request.Form["trade_no"] + "'  WHERE orderno='" + strOrderNO + "'";
                    LogService.LOG_LEVENL = 3;
                    LogService.Error(this.GetType().ToString(), sql);
                    s.ExecuteNonQuery(sql);

                    string sql1 = "select htid,regid from order_pay WHERE orderno='" + strOrderNO + "'";
                    List <List <string> > listord = s.ExecuteQuery(sql1);
                    if (listord.Count > 0)
                    {
                        //string slq2 = "select baodan_id from ht_bd_map where hetong_id='" + listord[0][0] + "'";
                        //List<List<string>> listht = s.ExecuteQuery(slq2);
                        //if(listht.Count>0)
                        //{
                        //    string sqlbd = "update baodan set state=5 where id='"+listht[0][0]+"' and regid='"+listord[0][1]+"'";
                        //    s.ExecuteNonQuery(sqlbd);
                        //}
                    }
                }
                else
                {
                    //更新自己数据库的订单语句,请自己填写一下
                }

                Response.Write("success");     //返回给支付宝消息,成功,请不要改写这个success
                //success与fail及其他字符的区别在于,支付宝的服务器若遇到success时,则不再发送请求通知(即不再调用该页面,让该页面再次运行起来),
                //若不是success,则支付宝默认没有收到成功的信息,则会反复不停地调用该页面直到失效,有效调用时间是24小时以内。

                //最好写TXT文件,以记录下是否异步返回记录。

                ////写文本,纪录支付宝返回消息,比对md5计算结果(如网站不支持写txt文件,可改成写数据库)
                string TOEXCELLR = "支付宝回调MD5结果:mysign=" + mysign + ",sign=" + sign + ",responseTxt=" + responseTxt;
                LogService.LOG_LEVENL = 3;
                LogService.Debug(this.GetType().ToString(), TOEXCELLR);
            }
            else
            {
                Response.Write("fail");

                //最好写TXT文件,以记录下是否异步返回记录。

                //写文本,纪录支付宝返回消息,比对md5计算结果(如网站不支持写txt文件,可改成写数据库)
                LogService.LOG_LEVENL = 3;
                string TOEXCELLR = "支付宝回调MD5结果:mysign=" + mysign + ",sign=" + sign + ",responseTxt=" + responseTxt;
                LogService.Debug(this.GetType().ToString(), TOEXCELLR);
            }
            return(View());
        }
        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", "支付结果中微信订单号不存在");
                LogService.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml());
            }

            string transaction_id = notifyData.GetValue("transaction_id") + "";

            LogService.Debug(this.GetType().ToString(), "transaction_id:" + transaction_id);
            //查询订单,判断订单真实性
            if (!QueryOrder(transaction_id))
            {
                //若订单查询失败,则立即返回结果给微信支付后台
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "FAIL");
                res.SetValue("return_msg", "订单查询失败");
                LogService.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml());
            }
            //查询订单成功
            else
            {
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "SUCCESS");
                res.SetValue("return_msg", "OK");
                LogService.Info(this.GetType().ToString(), "order query success : " + res.ToXml());
                LogService.Info(this.GetType().ToString(), "回调信息【out_trade_no】: " + notifyData.GetValue("out_trade_no") + "; time_end:" + notifyData.GetValue("time_end") + "; cash_fee:" + notifyData.GetValue("cash_fee"));
                SQLBase s = new SQLBase();

                float fee = 0;
                try
                {
                    fee = float.Parse(notifyData.GetValue("cash_fee").ToString()) / 100.0F;
                }
                catch (Exception)
                {
                    throw;
                }
                string sql = "update order_pay set paytime='" + notifyData.GetValue("time_end") + "',cash_fee=" + fee + ",transaction_id='" + notifyData.GetValue("transaction_id") + "' WHERE orderno='" + notifyData.GetValue("out_trade_no") + "'";
                LogService.Error(this.GetType().ToString(), sql);
                s.ExecuteNonQuery(sql);

                string sql1 = "select htid,regid from order_pay WHERE orderno='" + notifyData.GetValue("out_trade_no") + "'";
                List <List <string> > listord = s.ExecuteQuery(sql1);
                if (listord.Count > 0)
                {
                    //string slq2 = "select baodan_id from ht_bd_map where hetong_id='" + listord[0][0] + "'";
                    //List<List<string>> listht = s.ExecuteQuery(slq2);
                    //if (listht.Count > 0)
                    //{
                    //    string sqlbd = "update baodan set state=5 where id='" + listht[0][0] + "' and regid='" + listord[0][1] + "'";
                    //    s.ExecuteNonQuery(sqlbd);
                    //}
                }
            }
        }