Exemplo n.º 1
0
        public string BuildLoginUrl()
        {
            SystemOptions so = new SystemOptions();

            string key            = so["MemberSharing_Alipay_MD5"].ToString("");
            string return_url     = Shove._Web.Utility.GetUrl() + "/MemberSharing/Alipay/Receive.aspx"; //服务器通知返回接口
            string gateway        = so["MemberSharing_Alipay_Gateway"].ToString("");                    //支付接口
            string _input_charset = "utf-8";
            string service        = "user_authentication";
            string sign_type      = "MD5";
            string partner        = so["MemberSharing_Alipay_UserNumber"].ToString("");   //卖家商户号
            string ReturnUrl      = Shove._Web.Utility.GetUrl() + "/MemberSharing/Alipay/Receive.aspx";

            Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();
            string aliay_url       = ap.CreatUrl(
                gateway,
                service,
                partner,
                sign_type,
                key,
                return_url,
                _input_charset,
                ReturnUrl
                );

            return(aliay_url);
        }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //***************************************************************     
            string _input_charset = "utf-8";
            string NotifyService = "notify_verify";
            string SellerEmail = so["OnlinePay_Alipay_UserName"].ToString("");//卖家支付宝名称(邮箱)

            string NotifyID = Request.QueryString["notify_id"];

            int NotifyType = 2;

            Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();

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

            int i;
            NameValueCollection coll;
            //Load Form variables into NameValueCollection variable.
            coll = Request.QueryString;

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

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

            //构造待md5摘要字符串 ;

            StringBuilder prestr = new StringBuilder();

            for (i = 0; i < Sortedstr.Length; i++)
            {
                if (String.IsNullOrEmpty(Sortedstr[i]))
                {
                    continue;
                }

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

                    }
                }
            }

            string mysign = ap.GetMD5(prestr.ToString(), SellerEmail, _input_charset);
            string sign = Request.QueryString["sign"];
            string trade_status = Request.QueryString["trade_status"];
            string trade_no = Request.QueryString["trade_no"];              //支付宝交易号
            string out_trade_no = Request.QueryString["out_trade_no"];      //自己交易号
            string payment_type = Request.QueryString["payment_type"];      //支付类型
            string subject = Request.QueryString["subject"];                //商品名称,用户存放用户ID
            string subject_UnEncrypt = Shove._Security.Encrypt.UnEncryptString(PF.GetCallCert(), subject);
            double total_fee = double.Parse(Request.QueryString["total_fee"].ToString());       //支付金额
            string seller_email = Request.QueryString["seller_email"];      //卖家账号

            if (seller_email != so["OnlinePay_Alipay_UserName"].ToString(""))
            {
                new Log("System").Write("在线支付:收款帐号不匹配!");

                PF.GoError(ErrorNumber.Unknow, "支付用户信息验证失败", this.GetType().BaseType.FullName);

                return;
            }

            if (mysign == sign && responseTxt == "true" && trade_status == "TRADE_FINISHED")   //验证支付发过来的消息,签名是否正确
            {
                Users user;

                if (_User == null)
                {
                    user = new Users(_Site.ID)[_Site.ID, Shove._Convert.StrToLong(subject_UnEncrypt, -1)];
                }
                else
                {
                    user = new Users(_Site.ID)[_Site.ID, _User.ID];
                }

                if (user == null)
                {
                    //PF.GoError(ErrorNumber.Unknow, "异常用户数据", this.GetType().BaseType.FullName);

                    new Log("System").Write("在线支付:异常用户数据!");

                    this.Response.Write("<script language='javascript'>window.top.location.href='" + Shove._Web.Utility.GetUrl() + "/Home/Room/MyIcaile.aspx?SubPage=OnlinePay/Fail.aspx'</script>");

                    return;
                }

                if (_User == null)
                {
                    _User = new Users(_Site.ID)[_Site.ID, user.ID];

                    //string ReturnDescription = "";
                    //_User.LoginDirect(ref ReturnDescription);
                }

                if (WriteUserAccount(_User, out_trade_no.ToString(), total_fee.ToString(), "系统交易号:" + out_trade_no.ToString() + ",支付宝交易号:" + trade_no.ToString()))
                {
                    this.Response.Write("<script language='javascript'>window.top.location.href='http://" + Shove._Web.Utility.GetUrlWithoutHttp() + "/Home/Room/MyIcaile.aspx?SubPage=OnlinePay/OK.aspx'</script>");

                    return;
                }
                else
                {
                    new Log("System").Write("在线支付:写入返回数据出错!");

                    this.Response.Write("<script language='javascript'>window.top.location.href='http://" + Shove._Web.Utility.GetUrlWithoutHttp() + "/Home/Room/MyIcaile.aspx?SubPage=OnlinePay/Fail.aspx'</script>");

                    return;
                }
            }
            else
            {
                new Log("System").Write("在线支付:系统交易号:" + out_trade_no + " 支付宝交易号:" + trade_no + " 校验出错!responseTxt系统要求参数为true/false,实际返回:" + responseTxt.ToString() + " trade_status系统要求返回TRADE_FINISHED,实际返回: " + trade_status.ToString() + " 生成校验码:" + mysign.ToString() + "返回校验码:" + sign.ToString());
                this.Response.Write("<script language='javascript'>window.top.location.href='http://" + Shove._Web.Utility.GetUrlWithoutHttp() + "/Home/Room/MyIcaile.aspx?SubPage=OnlinePay/Fail.aspx'</script>");

                return;
            }
        }
        catch (Exception Ex)
        {
            new Log("System").Write("在线支付:" + Ex.Message + " -- 接收数据异常!");

            this.Response.Write("<script language='javascript'>window.top.location.href='http://" + Shove._Web.Utility.GetUrlWithoutHttp() + "/Home/Room/MyIcaile.aspx?SubPage=OnlinePay/Fail.aspx'</script>");

            return;
        }
    }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //***************************************************************     
            string _input_charset = "utf-8";
            string NotifyService = "notify_verify";
            string SellerEmail = so["OnlinePay_Alipay_UserName"].ToString("");//卖家支付宝名称(邮箱)

            string NotifyID = Request.Form["notify_id"];

            int NotifyType = 2;

            Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();

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

            int i;
            NameValueCollection coll;
            //Load Form variables into NameValueCollection variable.
            coll = Request.Form;

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

            //进行排序;
            string[] Sortedstr = Alipay.Gateway.Utility.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]] + "&");

                    }
                }
            }

            string mysign = ap.GetMD5(prestr.ToString(), SellerEmail, _input_charset);

            string sign = Request.Form["sign"];
            string trade_status = Request.Form["trade_status"];
            string trade_no = Request.Form["trade_no"];              //支付宝交易号
            string out_trade_no = Request.Form["out_trade_no"];      //自己交易号
            //string payment_type = Request.Form["payment_type"];      //支付类型
            string subject = Request.Form["subject"];                //商品名称,用户存放用户ID
            string subject_UnEncrypt = Shove._Security.Encrypt.UnEncryptString(PF.GetCallCert(), subject);
            //double total_fee = double.Parse(Request.Form["total_fee"].ToString());       //支付金额
            double total_fee = Shove._Convert.StrToDouble(Request.Form["total_fee"].ToString(), 0);  //支付金额
            string seller_email = Request.Form["seller_email"];      //卖家账号

            if (seller_email != so["OnlinePay_Alipay_UserName"].ToString(""))
            {
                new Log("System").Write("在线支付:支付用户信息验证失败!(Notify)");

                Response.Write("fail");     //返回给支付宝消息,失败
                Response.End();

                return;
            }

            if (mysign == sign && responseTxt == "true" && trade_status == "TRADE_FINISHED")   //验证支付发过来的消息,签名是否正确
            {
                if (_User == null)
                {
                    _User = new Users(_Site.ID)[_Site.ID, Shove._Convert.StrToLong(subject_UnEncrypt, -1)];

                    if (_User == null)
                    {
                        new Log("System").Write("在线支付:用户信息校验错误(Notify)");

                        Response.Write("fail");     //返回给支付宝消息,失败
                        Response.End();

                        return;
                    }
                }

                if (WriteUserAccount(_User, out_trade_no.ToString(), total_fee.ToString(), "系统交易号:" + out_trade_no.ToString() + ",支付宝交易号:" + trade_no.ToString()))
                {
                    Response.Write("success");     //返回给支付宝消息,成功

                    return;
                }
                else
                {
                    new Log("System").Write("在线支付:写入返回数据出错!(Notify)");
                    Response.Write("fail");
                    Response.End();

                    return;
                }
            }
            else
            {
                new Log("System").Write("在线支付:(Notify)系统交易号:" + out_trade_no + " 支付宝交易号:" + trade_no + " 校验出错!responseTxt系统要求参数为true/false,实际返回:" + responseTxt.ToString() + " trade_status系统要求返回TRADE_FINISHED,实际返回: " + trade_status.ToString() + " 生成校验码:" + mysign.ToString() + "返回校验码:" + sign.ToString());
                Response.Write("fail");
                Response.End();

                return;
            }
        }
        catch (Exception Ex)
        {
            new Log("System").Write(Ex.Message);
            Response.Write("fail");
            Response.End();

            return;
        }
    }
Exemplo n.º 4
0
    protected void AlipayPay()
    {
        Shove.Alipay.Alipay ap = new Shove.Alipay.Alipay();

        string aliay_url = ap.CreatUrl(
            gateway,
            service,
            partner,
            return_url,
            notify_url,
            out_trade_no,
            subject,
            payment_type,
            total_fee,
            seller_email,
            key,
            _input_charset,
            sign_type,
            "body",
            body,
            "show_url",
            show_url,
            "paymethod",
            paymethod
            );

        if (aliay_url == "")
        {
            Shove._Web.JavaScript.Alert(this.Page, "地址构建出现错误");

            return;
        }

        this.Response.Write("<script language='javascript'>window.top.location.href='" + aliay_url + "'</script>");
    }