Esempio n. 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] == null)
            {
                Response.Redirect(MojoCube.Web.Site.Cache.GetUrlExtension("Order", strLanguage));
            }

            ViewState["pk_Order"] = MojoCube.Api.Text.Security.DecryptString(Request.QueryString["id"]);

            MojoCube.Web.Order.List order = new MojoCube.Web.Order.List();
            order.GetData(int.Parse(ViewState["pk_Order"].ToString()));

            if (order.pk_Order == 0 || order.StatusID > 0 || order.fk_Member.ToString() != Session["Member_UserID"].ToString())
            {
                Response.Redirect(MojoCube.Web.Site.Cache.GetUrlExtension("Order", strLanguage));
            }

            string siteUrl = MojoCube.Web.Site.Cache.GetDomain(strLanguage);  //获取网站的域名

            MojoCube.Web.Payment.List payment = new MojoCube.Web.Payment.List();
            payment.GetDataByType(1);

            strUrl         = payment.Gateway;
            ordersn        = order.OrderNumber;
            item_name      = HttpUtility.UrlEncode(order.Description, System.Text.Encoding.UTF8);
            amount         = (double)order.Amount * double.Parse(payment.Rate.ToString());
            amount         = double.Parse(amount.ToString("0.00"));
            currency_code  = "USD";
            username       = HttpUtility.UrlEncode(order.CustomerName, System.Text.Encoding.UTF8);
            business       = payment.Account;
            notify_url     = siteUrl + MojoCube.Web.Site.Cache.GetUrlExtension("Paypal_NotifyUrl", strLanguage);
            cancel_return  = siteUrl + MojoCube.Web.Site.Cache.GetUrlExtension("Paypal_Cancel", strLanguage) + "?username="******"&ordersn=" + ordersn;
            success_return = siteUrl + MojoCube.Web.Site.Cache.GetUrlExtension("Paypal_Success", strLanguage) + "?username="******"&ordersn=" + ordersn;
        }
    }
Esempio n. 2
0
    private void WxPayJS()
    {
        string siteUrl = MojoCube.Web.Site.Cache.GetDomain(strLanguage);  //获取网站的域名

        MojoCube.Web.Payment.List payment = new MojoCube.Web.Payment.List();
        payment.GetDataByType(2);

        MojoCube.Web.Order.List order = new MojoCube.Web.Order.List();
        order.GetData(int.Parse(ViewState["pk_Order"].ToString()));

        if (order.pk_Order == 0 || order.StatusID > 0 || order.fk_Member.ToString() != Session["Member_UserID"].ToString())
        {
            Response.Redirect(MojoCube.Web.Site.Cache.GetUrlExtension("Order", strLanguage));
        }

        appId = payment.AppID;
        string partnerId = payment.PartnerID;
        string key       = payment.KeyCode;
        string secret    = payment.Secret;
        int    price     = (int)(order.Amount * 100);
        string body      = order.Description;

        if (body.Length > 20)
        {
            body = body.Substring(0, 20);
        }

        //调用【网页授权获取用户信息】接口获取用户的openid和access_token
        GetOpenidAndAccessToken(appId, secret);

        UnifiedOrder order1 = new UnifiedOrder();

        order1.appid            = appId;
        order1.mch_id           = partnerId;
        order1.nonce_str        = TenpayUtil.getNoncestr();
        order1.body             = body;
        order1.out_trade_no     = order.OrderNumber;
        order1.total_fee        = price;
        order1.spbill_create_ip = Page.Request.UserHostAddress;
        order1.notify_url       = siteUrl + MojoCube.Web.Site.Cache.GetUrlExtension("WxPay_Notify", strLanguage);
        order1.trade_type       = "JSAPI";
        if (ViewState["OpenID"] != null)
        {
            order1.openid = ViewState["OpenID"].ToString();  //JSAPI必须传入openid
        }

        TenpayUtil tu = new TenpayUtil();

        prepayId  = tu.getPrepay_id(order1, key);
        nonceStr  = order1.nonce_str;
        timeStamp = TenpayUtil.getTimestamp();

        SortedDictionary <string, string> sParams = new SortedDictionary <string, string>();

        sParams.Add("appId", appId);
        sParams.Add("nonceStr", nonceStr);
        sParams.Add("package", "prepay_id=" + prepayId);
        sParams.Add("signType", "MD5");
        sParams.Add("timeStamp", timeStamp);
        sign = tu.getsign(sParams, key);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ///当不知道https的时候,请使用http
        //string alipayNotifyURL = "https://www.alipay.com/cooperate/gateway.do?";
        string alipayNotifyURL = "http://notify.alipay.com/trade/notify_query.do?";

        MojoCube.Web.Payment.List payment = new MojoCube.Web.Payment.List();
        payment.GetDataByType(0);

        string partner = payment.PartnerID; //partner
        string key     = payment.KeyCode;   //安全校验码

        //alipayNotifyURL = alipayNotifyURL + "service=notify_verify" + "&partner=" + partner + "&notify_id=" + Request.QueryString["notify_id"];
        alipayNotifyURL = alipayNotifyURL + "partner=" + partner + "&notify_id=" + Request.QueryString["notify_id"];

        string responseTxt = Get_Http(alipayNotifyURL, 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 = BubbleSort(requestarr);

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

        StringBuilder prestr = new StringBuilder();

        for (i = 0; i < Sortedstr.Length; i++)
        {
            if (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]] + "&");
                }
            }
        }
        prestr.Append(key);

        string mysign    = GetMD5(prestr.ToString());               //生成MD5摘要
        string sign      = Request.Form["sign"];                    //签名
        string business  = Request.Form["seller_email"].ToString(); //收款方帐号ok
        string item_name = Request.Form["subject"].ToString();      //商品名ok
        string ordersn   = Request.Form["out_trade_no"].ToString(); //订单号ok
        string username  = Request.Form["receive_name"].ToString();
        string ppPrice   = Request.Form["price"].ToString();        //金额ok

        MojoCube.Web.Order.List order = new MojoCube.Web.Order.List();
        order.GetData(ordersn);

        if (order.pk_Order > 0)
        {
            if (mysign != sign)
            {
                return;
            }

            if (!MojoCube.Web.Sql.IsExist("Order_Log", "fk_Order", order.pk_Order, "TransStatus='" + responseTxt + "'"))
            {
                bool isSuccess = false;

                if (responseTxt == "true")
                {
                    isSuccess = true;
                }

                MojoCube.Web.Order.Log log = new MojoCube.Web.Order.Log();
                log.Number      = MojoCube.Api.Text.Function.DateTimeString(true);
                log.OrderNumber = order.OrderNumber;
                log.fk_Order    = order.pk_Order;
                log.fk_Member   = order.fk_Member;
                log.TypeID      = 0;
                log.StatusID    = 0;
                log.Title       = string.Empty;
                log.Description = order.Description;
                log.Amount      = order.Amount;
                log.AppID       = string.Empty;
                log.TransStatus = responseTxt;
                if (isSuccess)
                {
                    log.TransName   = "支付成功";
                    log.ResponseMsg = "交易成功";
                }
                else
                {
                    log.TransName   = "支付失败";
                    log.ResponseMsg = "交易失败";
                }
                log.ChannelType    = "支付宝";
                log.ResponseCode   = responseTxt;
                log.OrderStartTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                log.OrderAmt       = ppPrice;
                log.OrderTimeOut   = "0";
                log.OrderType      = "普通消费";
                log.DeviceType     = "Web";
                log.ResponseTime   = log.OrderStartTime;
                log.CurrencyType   = "RMB";
                log.Result         = sign + "|" + business + "|" + item_name + "|" + ordersn + "|" + username + "|" + ppPrice;
                log.CreateDate     = DateTime.Now.ToString();
                log.InsertData();

                //支付成功
                if (isSuccess)
                {
                    //修改订单状态
                    order.StatusID    = 1;
                    order.fk_Payment  = 1;
                    order.PaymentDate = DateTime.Now.ToString();
                    order.UpdateData(order.pk_Order);

                    Response.Write("支付成功!");     //返回给支付宝消息,成功
                    Response.Write("<br>------------------" + Request.Form["body"]);
                }
                else
                {
                    Response.Write("支付失败,请与商家联系!");
                    Response.Write("<br>------------------" + Request.Form["body"]);
                }
            }
        }
    }
Esempio n. 4
0
    private string GetPostUrl()
    {
        string siteUrl = MojoCube.Web.Site.Cache.GetDomain(strLanguage);  //获取网站的域名

        MojoCube.Web.Payment.List payment = new MojoCube.Web.Payment.List();
        payment.GetDataByType(0);

        MojoCube.Web.Order.List order = new MojoCube.Web.Order.List();
        order.GetData(int.Parse(ViewState["pk_Order"].ToString()));

        if (order.pk_Order == 0 || order.StatusID > 0 || order.fk_Member.ToString() != Session["Member_UserID"].ToString())
        {
            Response.Redirect(MojoCube.Web.Site.Cache.GetUrlExtension("Order", strLanguage));
        }

        ///////////////////////以下参数是需要设置的相关配置参数,设置后不会更改的///////////////////////////
        string service       = payment.Service;                                                                 //服务类型:create_partner_trade_by_buyer(支付宝中介担保交易)或者trade_create_by_buyer(即时到账)
        string partner       = payment.PartnerID;                                                               //合作身份者ID
        string key           = payment.KeyCode;                                                                 //安全检验码
        string seller_email  = payment.Account;                                                                 //签约支付宝账号或卖家支付宝帐户
        string input_charset = payment.InputCharset;                                                            //字符编码格式 目前支持 gb2312 或 utf-8
        string notify_url    = siteUrl + MojoCube.Web.Site.Cache.GetUrlExtension("Alipay_Notify", strLanguage); //交易过程中服务器通知的页面 要用 http://格式的完整路径,不允许加?id=123这类自定义参数
        string return_url    = siteUrl + MojoCube.Web.Site.Cache.GetUrlExtension("Alipay_Return", strLanguage); //付完款后跳转的页面 要用 http://格式的完整路径,不允许加?id=123这类自定义参数
        string show_url      = siteUrl;                                                                         //网站商品的展示地址,不允许加?id=123这类自定义参数
        string sign_type     = payment.SignType;                                                                //加密方式 不需修改

        ////////////////////////////////////////////////////////////////////////////////////////////////////

        ///////////////////////以下参数是需要通过下单时的订单数据传入进来获得////////////////////////////////
        //必填参数
        string out_trade_no = order.OrderNumber;             //请与贵网站订单系统中的唯一订单号匹配
        string subject      = order.Description;             //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。
        string body         = "订单描述:" + order.Description;   //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里
        string price        = order.Amount.ToString("0.00"); //订单总金额,显示在支付宝收银台里的“商品单价”里

        string logistics_fee     = "0.00";                   //物流费用,即运费。
        string logistics_type    = "EXPRESS";                //物流类型,三个值可选:EXPRESS(快递)、POST(平邮)、EMS(EMS)
        string logistics_payment = "SELLER_PAY";             //物流支付方式,两个值可选:SELLER_PAY(卖家承担运费)、BUYER_PAY(买家承担运费)

        string quantity = "1";                               //商品数量,建议默认为1,不改变值,把一次交易看成是一次下订单而非购买一件商品。

        //扩展参数——买家收货信息(推荐作为必填)
        //该功能作用在于买家已经在商户网站的下单流程中填过一次收货信息,而不需要买家在支付宝的付款流程中再次填写收货信息。
        //若要使用该功能,请至少保证receive_name、receive_address有值
        string receive_name    = order.CustomerName;                            //收货人姓名,如:张三
        string receive_address = order.CustomerAddress;                         //收货人地址,如:XX省XXX市XXX区XXX路XXX小区XXX栋XXX单元XXX号
        string receive_zip     = order.CustomerZip;                             //收货人邮编,如:123456
        string receive_phone   = order.CustomerPhone1;                          //收货人电话号码,如:0571-81234567
        string receive_mobile  = order.CustomerPhone1;                          //收货人手机号码,如:13312341234

        //扩展参数——第二组物流方式
        //物流方式是三个为一组成组出现。若要使用,三个参数都需要填上数据;若不使用,三个参数都需要为空
        //有了第一组物流方式,才能有第二组物流方式,且不能与第一个物流方式中的物流类型相同,
        //即logistics_type="EXPRESS",那么logistics_type_1就必须在剩下的两个值(POST、EMS)中选择
        string logistics_fee_1     = "";                                                //物流费用,即运费。
        string logistics_type_1    = "";                                                //物流类型,三个值可选:EXPRESS(快递)、POST(平邮)、EMS(EMS)
        string logistics_payment_1 = "";                                                //物流支付方式,两个值可选:SELLER_PAY(卖家承担运费)、BUYER_PAY(买家承担运费)

        //扩展参数——第三组物流方式
        //物流方式是三个为一组成组出现。若要使用,三个参数都需要填上数据;若不使用,三个参数都需要为空
        //有了第一组物流方式和第二组物流方式,才能有第三组物流方式,且不能与第一组物流方式和第二组物流方式中的物流类型相同,
        //即logistics_type="EXPRESS"、logistics_type_1="EMS",那么logistics_type_2就只能选择"POST"
        string logistics_fee_2     = "";                                                //物流费用,即运费。
        string logistics_type_2    = "";                                                //物流类型,三个值可选:EXPRESS(快递)、POST(平邮)、EMS(EMS)
        string logistics_payment_2 = "";                                                //物流支付方式,两个值可选:SELLER_PAY(卖家承担运费)、BUYER_PAY(买家承担运费)

        //扩展功能参数——其他
        string buyer_email = "";                                                        //默认买家支付宝账号
        string discount    = "";                                                        //折扣,是具体的金额,而不是百分比。若要使用打折,请使用负数,并保证小数点最多两位数

        /////////////////////////////////////////////////////////////////////////////////////////////////////

        //构造请求函数
        MojoCube.Web.Payment.Alipay.Service aliService = new MojoCube.Web.Payment.Alipay.Service(
            partner,
            seller_email,
            return_url,
            notify_url,
            show_url,
            out_trade_no,
            subject,
            body,
            price,
            logistics_fee,
            logistics_type,
            logistics_payment,
            quantity,
            receive_name,
            receive_address,
            receive_zip,
            receive_phone,
            receive_mobile,
            logistics_fee_1,
            logistics_type_1,
            logistics_payment_1,
            logistics_fee_2,
            logistics_type_2,
            logistics_payment_2,
            buyer_email,
            discount,
            key,
            input_charset,
            sign_type,
            service);

        //GET方式传递
        return(aliService.Create_url());
    }
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        MojoCube.Web.Payment.List payment = new MojoCube.Web.Payment.List();
        payment.GetDataByType(1);

        string         strUrl = payment.Gateway;
        HttpWebRequest req    = (HttpWebRequest)WebRequest.Create(strUrl);

        // Set values for the request back
        req.Method      = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        byte[] param      = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);

        strRequest       += "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
        //req.Proxy = proxy;

        //Send the request to PayPal and get the response
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);

        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn    = new StreamReader(req.GetResponse().GetResponseStream());
        string       responseTxt = streamIn.ReadToEnd();

        streamIn.Close();

        string business  = GetString("business");                  //收款方帐号ok
        string item_name = GetString("item_name");                 //商品名ok
        string ordersn   = GetString("item_number");               //订单号ok
        string username  = GetString("username");
        string txnid     = GetString("txn_id").ToString();         //ok
        string ppStatus  = GetString("payment_status").ToString(); //状态 ok//成功返回:Completed
        string ppDate    = GetString("payment_date").ToString();   //paypal服务器支付时间ok
        string ppPrice   = GetString("mc_gross").ToString();       //金额ok

        MojoCube.Web.Order.List order = new MojoCube.Web.Order.List();
        order.GetData(ordersn);

        if (order.pk_Order > 0)
        {
            if (responseTxt != "VERIFIED")
            {
                return;
            }

            if (!MojoCube.Web.Sql.IsExist("Order_Log", "fk_Order", order.pk_Order, "TransStatus='" + ppStatus + "'"))
            {
                bool isSuccess = false;

                if (ppStatus == "Completed")
                {
                    isSuccess = true;
                }

                MojoCube.Web.Order.Log log = new MojoCube.Web.Order.Log();
                log.Number      = MojoCube.Api.Text.Function.DateTimeString(true);
                log.OrderNumber = order.OrderNumber;
                log.fk_Order    = order.pk_Order;
                log.fk_Member   = order.fk_Member;
                log.TypeID      = 0;
                log.StatusID    = 0;
                log.Title       = string.Empty;
                log.Description = order.Description;
                log.Amount      = order.Amount;
                log.AppID       = string.Empty;
                log.TransStatus = ppStatus;
                if (isSuccess)
                {
                    log.TransName   = "支付成功";
                    log.ResponseMsg = "交易成功";
                }
                else
                {
                    log.TransName   = "支付失败";
                    log.ResponseMsg = "交易失败";
                }
                log.ChannelType    = "Paypal";
                log.ResponseCode   = responseTxt;
                log.OrderStartTime = ppDate;
                log.OrderAmt       = ppPrice;
                log.OrderTimeOut   = "0";
                log.OrderType      = "普通消费";
                log.DeviceType     = "Web";
                log.ResponseTime   = log.OrderStartTime;
                log.CurrencyType   = "RMB";
                log.Result         = business + "|" + item_name + "|" + ordersn + "|" + username + "|" + txnid + "|" + ppStatus + "|" + ppDate + "|" + ppPrice;
                log.CreateDate     = DateTime.Now.ToString();
                log.InsertData();

                //支付成功
                if (isSuccess)
                {
                    //修改订单状态
                    order.StatusID    = 1;
                    order.fk_Payment  = 2;
                    order.PaymentDate = DateTime.Now.ToString();
                    order.UpdateData(order.pk_Order);
                }
            }
        }
    }