Пример #1
0
        /// <summary>
        /// 交易结束时 返回交易结果
        /// </summary>
        /// <param name="alipayServer"></param>
        /// <param name="result"></param>
        private void PostResult(AlipayWapTradeResponseBLL alipayServer, string result, string out_trade_no)
        {
            List <EqualsCondition> lstWhereCondition = new List <EqualsCondition>();

            lstWhereCondition.Add(new EqualsCondition()
            {
                FieldName = "out_trade_no", Value = out_trade_no
            });
            var alipays = alipayServer.Query(lstWhereCondition.ToArray(), null);

            if (alipays != null && alipays.Length > 0)
            {
                var alipay = alipays.FirstOrDefault();

                string uriString = alipay.CallBackUrl;
                // 创建一个新的 WebClient 实例.
                WebClient myWebClient = new WebClient();
                string    postData    = "order_id=" + alipay.OrderID + "&result=" + result + "&out_trade_no=" + Request["out_trade_no"];

                BaseService.WriteLog("交易结束时,返回交易结果。");
                BaseService.WriteLog("CallBackUrl: " + uriString);
                BaseService.WriteLog("postData: " + postData);

                // 注意这种拼字符串的ContentType
                myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                // 转化成二进制数组
                byte[] byteArray = Encoding.ASCII.GetBytes(postData);
                // 上传数据
                myWebClient.UploadData(uriString, "POST", byteArray);
            }
        }
Пример #2
0
        /// <summary>
        /// 交易成功,更新支付宝交易状态
        /// </summary>
        /// <param name="xmlDoc"></param>
        private void UpdateAlipayWapTrade(XmlDocument xmlDoc, string status)
        {
            var alipayEntity = new AlipayWapTradeResponseEntity()
            {
                OutTradeNo       = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText,
                Subject          = xmlDoc.SelectSingleNode("/notify/subject").InnerText,
                TotalFee         = xmlDoc.SelectSingleNode("/notify/total_fee").InnerText,
                PaymentType      = xmlDoc.SelectSingleNode("/notify/payment_type").InnerText,
                TradeNo          = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText,
                BuyerEmail       = xmlDoc.SelectSingleNode("/notify/buyer_email").InnerText,
                GmtCreate        = xmlDoc.SelectSingleNode("/notify/gmt_create").InnerText,
                NotifyType       = xmlDoc.SelectSingleNode("/notify/notify_type").InnerText,
                Quantity         = xmlDoc.SelectSingleNode("/notify/quantity").InnerText,
                NotifyTime       = xmlDoc.SelectSingleNode("/notify/notify_time").InnerText,
                SellerID         = xmlDoc.SelectSingleNode("/notify/seller_id").InnerText,
                TradeStatus      = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText,
                IsTotalFeeAdjust = xmlDoc.SelectSingleNode("/notify/is_total_fee_adjust").InnerText,
                GmtPayment       = xmlDoc.SelectSingleNode("/notify/gmt_payment").InnerText,
                SellerEmail      = xmlDoc.SelectSingleNode("/notify/seller_email").InnerText,
                //GmtClose = xmlDoc.SelectSingleNode("/notify/gmt_close").InnerText,
                Price     = xmlDoc.SelectSingleNode("/notify/price").InnerText,
                BuyerID   = xmlDoc.SelectSingleNode("/notify/buyer_id").InnerText,
                NotifyID  = xmlDoc.SelectSingleNode("/notify/notify_id").InnerText,
                UseCoupon = xmlDoc.SelectSingleNode("/notify/use_coupon").InnerText,
                Status    = status
            };

            BaseService.WriteLog("交易成功,更新支付宝交易状态");

            AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());

            alipayServer.UpdateAlipayWapTrade(alipayEntity);
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BaseService.WriteLog("服务器异步通知页面-----------------------Notify.aspx");

            //前台页面别忘记加这句指令,否则会报特殊字符的异常 ValidateRequest="false"

            //获取加密的notify_data数据
            string notify_data = Request.Form["notify_data"];

            BaseService.WriteLog("加密的notify_data数据: " + notify_data);

            //通过商户私钥进行解密
            notify_data = Function.Decrypt(notify_data, Config.PrivateKey, Config.Input_charset_UTF8);
            BaseService.WriteLog("解密后的notify_data数据: " + notify_data);

            //获取签名
            string sign = Request.Form["sign"];

            BaseService.WriteLog("sign签名: " + sign);

            //创建待签名数组,注意Notify这里数组不需要进行排序,请保持以下顺序
            Dictionary <string, string> sArrary = new Dictionary <string, string>();

            //组装验签数组
            sArrary.Add("service", Request.Form["service"]);
            sArrary.Add("v", Request.Form["v"]);
            sArrary.Add("sec_id", Request.Form["sec_id"]);
            sArrary.Add("notify_data", notify_data);

            //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
            string content = Function.CreateLinkString(sArrary);

            BaseService.WriteLog("开始验证签名");
            //验证签名
            bool vailSign = Function.Verify(content, sign, Config.Alipaypublick, Config.Input_charset_UTF8);

            BaseService.WriteLog("结束验证签名");
            BaseService.WriteLog("验证签名结果: " + vailSign);

            if (!vailSign)
            {
                Response.Write("fail");
                return;
            }

            BaseService.WriteLog("开始获取交易状态");
            //获取交易状态
            string trade_status = Function.GetStrForXmlDoc(notify_data, "notify/trade_status");

            BaseService.WriteLog("结束获取交易状态");
            BaseService.WriteLog("交易状态trade_status: " + trade_status);

            if (!trade_status.Equals("TRADE_FINISHED"))
            {
                Response.Write("fail");
            }
            else
            {
                ///////////////////////////////处理数据/////////////////////////////////
                // 用户这里可以写自己的商业逻辑
                // 例如:修改数据库订单状态
                // 以下数据仅仅进行演示如何调取
                // 参数对照请详细查阅开发文档
                // 里面有详细说明

                var alipayEntity = new AlipayWapTradeResponseEntity()
                {
                    OutTradeNo       = Function.GetStrForXmlDoc(notify_data, "notify/out_trade_no"),
                    Subject          = Function.GetStrForXmlDoc(notify_data, "notify/subject"),
                    TotalFee         = Function.GetStrForXmlDoc(notify_data, "notify/total_fee"),
                    PaymentType      = Function.GetStrForXmlDoc(notify_data, "notify/payment_type"),
                    TradeNo          = Function.GetStrForXmlDoc(notify_data, "notify/trade_no"),
                    BuyerEmail       = Function.GetStrForXmlDoc(notify_data, "notify/buyer_email"),
                    GmtCreate        = Function.GetStrForXmlDoc(notify_data, "notify/gmt_create"),
                    NotifyType       = Function.GetStrForXmlDoc(notify_data, "notify/notify_type"),
                    Quantity         = Function.GetStrForXmlDoc(notify_data, "notify/quantity"),
                    NotifyTime       = Function.GetStrForXmlDoc(notify_data, "notify/notify_time"),
                    SellerID         = Function.GetStrForXmlDoc(notify_data, "notify/seller_id"),
                    TradeStatus      = Function.GetStrForXmlDoc(notify_data, "notify/trade_status"),
                    IsTotalFeeAdjust = Function.GetStrForXmlDoc(notify_data, "notify/is_total_fee_adjust"),
                    GmtPayment       = Function.GetStrForXmlDoc(notify_data, "notify/gmt_payment"),
                    SellerEmail      = Function.GetStrForXmlDoc(notify_data, "notify/seller_email"),
                    GmtClose         = Function.GetStrForXmlDoc(notify_data, "notify/gmt_close"),
                    Price            = Function.GetStrForXmlDoc(notify_data, "notify/price"),
                    BuyerID          = Function.GetStrForXmlDoc(notify_data, "notify/buyer_id"),
                    NotifyID         = Function.GetStrForXmlDoc(notify_data, "notify/notify_id"),
                    UseCoupon        = Function.GetStrForXmlDoc(notify_data, "notify/use_coupon"),
                    Status           = "2"
                };

                BaseService.WriteLog("交易成功,更新支付宝交易状态");

                AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());
                alipayServer.UpdateAlipayWapTrade(alipayEntity);
                ////////////////////////////////////////////////////////////////////////////

                Response.Write("success");
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BaseService.WriteLog("服务器异步通知页面-----------------------AlipayWapTrade2/Notify.aspx");

            Dictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                BaseService.WriteLog("开始验证");

                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.VerifyNotify(sPara, Request.Form["sign"]);

                if (verifyResult)//验证成功
                {
                    BaseService.WriteLog("验证成功");
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表

                    //解密(如果是RSA签名需要解密,如果是MD5签名则下面一行清注释掉)
                    sPara = aliNotify.Decrypt(sPara);

                    //XML解析notify_data数据
                    try
                    {
                        BaseService.WriteLog("notify_data:" + sPara["notify_data"]);

                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(sPara["notify_data"]);
                        //商户订单号
                        string out_trade_no = xmlDoc.SelectSingleNode("/notify/out_trade_no").InnerText;
                        //支付宝交易号
                        string trade_no = xmlDoc.SelectSingleNode("/notify/trade_no").InnerText;
                        //交易状态
                        string trade_status = xmlDoc.SelectSingleNode("/notify/trade_status").InnerText;

                        //交易成功,更新支付宝交易状态
                        UpdateAlipayWapTrade(xmlDoc, "2");

                        BaseService.WriteLog("交易状态trade_status:" + trade_status);

                        if (trade_status == "TRADE_FINISHED")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序

                            if (!string.IsNullOrEmpty(out_trade_no))
                            {
                                try
                                {
                                    var alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());
                                    BaseService.WriteLog("out_trade_no:" + out_trade_no);
                                    BaseService.WriteLog("交易成功");

                                    //更新交易状态
                                    BaseService.WriteLog("更新交易状态");
                                    alipayServer.UpdateAlipayWapTradeStatus(out_trade_no, "2");

                                    //处理分润业务
                                    BaseService.WriteLog("处理分润业务");
                                    //RoyaltyBusiness(out_trade_no, trade_no);

                                    //推送交易结果集
                                    BaseService.WriteLog("推送交易结果集");
                                    PostResult(alipayServer, "success", out_trade_no);
                                }
                                catch (Exception ex)
                                {
                                    BaseService.WriteLog("异常信息: " + ex.ToString());
                                }
                            }
                            else
                            {
                                BaseService.WriteLog("out_trade_no is null!!!!! ");
                            }

                            //注意:
                            //该种交易状态只在两种情况下出现
                            //1、开通了普通即时到账,买家付款成功后。
                            //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
                            Response.Write("success");  //请不要修改或删除
                        }
                        else if (trade_status == "TRADE_SUCCESS")
                        {
                            //判断该笔订单是否在商户网站中已经做过处理
                            //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                            //如果有做过处理,不执行商户的业务程序

                            if (!string.IsNullOrEmpty(out_trade_no))
                            {
                                try
                                {
                                    var alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());
                                    BaseService.WriteLog("out_trade_no:" + out_trade_no);
                                    BaseService.WriteLog("交易成功");

                                    //更新交易状态
                                    BaseService.WriteLog("更新交易状态");
                                    alipayServer.UpdateAlipayWapTradeStatus(out_trade_no, "2");

                                    //处理分润业务
                                    BaseService.WriteLog("处理分润业务");
                                    RoyaltyBusiness(out_trade_no, trade_no);

                                    //推送交易结果集
                                    BaseService.WriteLog("推送交易结果集");
                                    PostResult(alipayServer, "success", out_trade_no);
                                }
                                catch (Exception ex)
                                {
                                    BaseService.WriteLog("异常信息: " + ex.ToString());
                                }
                            }
                            else
                            {
                                BaseService.WriteLog("out_trade_no is null!!!!! ");
                            }

                            //注意:
                            //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
                            Response.Write("success");  //请不要修改或删除
                        }
                        else
                        {
                            Response.Write(trade_status);
                        }
                    }
                    catch (Exception exc)
                    {
                        BaseService.WriteLog("异常信息:" + exc.ToString());
                        Response.Write(exc.ToString());
                    }
                }
                else//验证失败
                {
                    BaseService.WriteLog("验证失败");
                    Response.Write("fail");
                }
            }
            else
            {
                BaseService.WriteLog("无通知参数");
                Response.Write("无通知参数");
            }
        }
Пример #5
0
        private void Submit()
        {
            BaseService.WriteLog("支付宝交易开始-----------------------AlipayWapTrade2/Trade.aspx");
            BaseService.WriteLog("调用授权接口alipay.wap.trade.create.direct获取授权码token");
            ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token////////////////////////////////////////////

            string order_id      = string.Empty;
            string call_back_url = AlipayConfig.Merchant_url;

            //订单号
            if (!string.IsNullOrEmpty(Request["order_id"]))
            {
                order_id = Request["order_id"].Trim();
                BaseService.WriteLog("order_id:  " + Request["order_id"]);
            }
            else
            {
                BaseService.WriteLog("请求参数order_id is null!!!!!");
            }
            //产品名称
            if (!string.IsNullOrEmpty(Request["prod_name"]))
            {
                AlipayConfig.Subject = Request["prod_name"].Trim();
                BaseService.WriteLog("prod_name:  " + Request["prod_name"]);
            }
            else
            {
                BaseService.WriteLog("请求参数prod_name is null!!!!!");
            }
            //产品价格
            if (!string.IsNullOrEmpty(Request["prod_price"]))
            {
                AlipayConfig.Total_fee = Request["prod_price"].Trim();
                BaseService.WriteLog("prod_price:  " + Request["prod_price"]);
            }
            else
            {
                BaseService.WriteLog("请求参数prod_price is null!!!!!");
            }
            //用户付款中途退出返回URL
            if (!string.IsNullOrEmpty(Request["merchant_url"]))
            {
                AlipayConfig.Merchant_url = Request["merchant_url"].Trim();
                BaseService.WriteLog("merchant_url:  " + Request["merchant_url"]);
            }
            else
            {
                BaseService.WriteLog("请求参数merchant_url is null!!!!!");
            }
            //用户付款成功同步返回URL
            if (!string.IsNullOrEmpty(Request["call_back_url"]))
            {
                call_back_url = Request["call_back_url"].Trim();
                BaseService.WriteLog("call_back_url:  " + Request["call_back_url"]);
            }
            else
            {
                BaseService.WriteLog("请求参数call_back_url is null!!!!!");
            }

            AlipayConfig.Req_id       = System.Guid.NewGuid().ToString().Replace("-", "");
            AlipayConfig.Out_trade_no = System.Guid.NewGuid().ToString().Replace("-", "");

            //分润参数
            if (!string.IsNullOrEmpty(Request["params"]))
            {
                BaseService.WriteLog("params:  " + Request["params"]);

                var entity = new AlipayRoyaltyEntity()
                {
                    RoyaltyID         = System.Guid.NewGuid().ToString().Replace("-", ""),
                    OutTradeNo        = AlipayConfig.Out_trade_no,
                    RoyaltyParameters = Request["params"]
                };

                //保存分润参数到数据库
                var royaltyServer = new AlipayRoyaltyBLL(Default.GetLoggingSession());
                royaltyServer.Create(entity);
            }
            else
            {
                BaseService.WriteLog("请求参数params is null!!!!!");
            }

            //请求业务参数详细
            string req_dataToken = ""
                                   + "<direct_trade_create_req>"
                                   + "<notify_url>" + AlipayConfig.Notify_url + "</notify_url>"
                                   + "<call_back_url>" + AlipayConfig.Call_back_url + "</call_back_url>"
                                   + "<seller_account_name>" + AlipayConfig.Seller_account_name + "</seller_account_name>"
                                   + "<out_trade_no>" + AlipayConfig.Out_trade_no + "</out_trade_no>"
                                   + "<subject>" + AlipayConfig.Subject + "</subject>"
                                   + "<total_fee>" + AlipayConfig.Total_fee + "</total_fee>"
                                   + "</direct_trade_create_req>";

            BaseService.WriteLog("请求业务参数详细: " + req_dataToken);

            //把请求参数打包成数组
            Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();

            sParaTempToken.Add("partner", AlipayConfig.Partner);
            sParaTempToken.Add("_input_charset", AlipayConfig.Input_charset.ToLower());
            sParaTempToken.Add("sec_id", AlipayConfig.Sign_type.ToUpper());
            sParaTempToken.Add("service", AlipayConfig.Service_Create);
            sParaTempToken.Add("format", AlipayConfig.Format);
            sParaTempToken.Add("v", AlipayConfig.V);
            sParaTempToken.Add("req_id", AlipayConfig.Req_id);
            sParaTempToken.Add("req_data", req_dataToken);

            //建立请求
            string sHtmlTextToken = AlipaySubmit.BuildRequest(AlipayConfig.Req_url, sParaTempToken);
            //URLDECODE返回的信息
            Encoding code = Encoding.GetEncoding(AlipayConfig.Input_charset);

            sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code);

            //解析远程模拟提交后返回的信息
            Dictionary <string, string> dicHtmlTextToken = AlipaySubmit.ParseResponse(sHtmlTextToken);

            //获取token
            string request_token = dicHtmlTextToken["request_token"];

            BaseService.WriteLog("根据授权码token调用交易接口alipay.wap.auth.authAndExecute");
            ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute////////////////////////////////////////////

            //业务详细
            string req_data = ""
                              + "<auth_and_execute_req>"
                              + "<request_token>" + request_token + "</request_token>"
                              + "</auth_and_execute_req>";

            BaseService.WriteLog("业务详细: " + req_data);

            //把请求参数打包成数组
            Dictionary <string, string> sParaTemp = new Dictionary <string, string>();

            sParaTemp.Add("partner", AlipayConfig.Partner);
            sParaTemp.Add("_input_charset", AlipayConfig.Input_charset.ToLower());
            sParaTemp.Add("sec_id", AlipayConfig.Sign_type.ToUpper());
            sParaTemp.Add("service", AlipayConfig.Service_Execute);
            sParaTemp.Add("format", AlipayConfig.Format);
            sParaTemp.Add("v", AlipayConfig.V);
            sParaTemp.Add("req_data", req_data);

            BaseService.WriteLog("保存交易记录到数据库");

            var alipayEntity = new AlipayWapTradeResponseEntity()
            {
                ResponseID  = System.Guid.NewGuid().ToString().Replace("-", ""),
                OrderID     = order_id,
                OutTradeNo  = AlipayConfig.Out_trade_no,
                Subject     = AlipayConfig.Subject,
                TotalFee    = AlipayConfig.Total_fee,
                MerchantUrl = AlipayConfig.Merchant_url,
                CallBackUrl = call_back_url,
                Status      = "1"
            };

            //保存交易记录到数据库
            AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());

            alipayServer.Create(alipayEntity);

            //建立请求
            string sHtmlText = AlipaySubmit.BuildRequest(AlipayConfig.Req_url, sParaTemp, "get", "确认");

            Response.Write(sHtmlText);
        }
Пример #6
0
        private void Submit()
        {
            BaseService.WriteLog("支付宝交易开始-----------------------Trade.aspx");
            BaseService.WriteLog("初始化Service");

            //初始化Service
            Service ali           = new Service();
            string  order_id      = string.Empty;
            string  call_back_url = Config.Merchant_url;

            //订单号
            if (Request["order_id"] != null)
            {
                order_id = Request["order_id"].Trim();
                BaseService.WriteLog("order_id:  " + Request["order_id"]);
            }
            else
            {
                BaseService.WriteLog("请求参数order_id is null!!!!!");
            }
            //产品名称
            if (Request["prod_name"] != null)
            {
                Config.Subject = Request["prod_name"].Trim();
                BaseService.WriteLog("prod_name:  " + Request["prod_name"]);
            }
            else
            {
                BaseService.WriteLog("请求参数prod_name is null!!!!!");
            }
            //产品价格
            if (Request["prod_price"] != null)
            {
                Config.Total_fee = Request["prod_price"].Trim();
                BaseService.WriteLog("prod_price:  " + Request["prod_price"]);
            }
            else
            {
                BaseService.WriteLog("请求参数prod_price is null!!!!!");
            }
            //用户付款中途退出返回URL
            if (Request["merchant_url"] != null)
            {
                Config.Merchant_url = Request["merchant_url"].Trim();
                BaseService.WriteLog("merchant_url:  " + Request["merchant_url"]);
            }
            else
            {
                BaseService.WriteLog("请求参数merchant_url is null!!!!!");
            }
            //用户付款成功同步返回URL
            if (Request["call_back_url"] != null)
            {
                call_back_url = Request["call_back_url"].Trim();
                BaseService.WriteLog("call_back_url:  " + Request["call_back_url"]);
            }
            else
            {
                BaseService.WriteLog("请求参数call_back_url is null!!!!!");
            }

            Config.Req_id       = System.Guid.NewGuid().ToString().Replace("-", "");
            Config.Out_trade_no = System.Guid.NewGuid().ToString().Replace("-", "");

            BaseService.WriteLog("创建交易接口");
            //创建交易接口
            string token = ali.alipay_wap_trade_create_direct(
                Config.Req_url,
                Config.Subject,
                Config.Out_trade_no,
                Config.Total_fee,
                Config.Seller_account_name,
                Config.Notify_url,
                Config.Out_user,
                Config.Merchant_url,
                Config.Call_back_url,
                Config.Service_Create,
                Config.Sec_id,
                Config.Partner,
                Config.Req_id,
                Config.Format,
                Config.V,
                Config.Req_url,
                Config.PrivateKey,
                Config.Input_charset_UTF8);

            BaseService.WriteLog("Config.Req_url: " + Config.Req_url);
            BaseService.WriteLog("Config.Subject: " + Config.Subject);
            BaseService.WriteLog("Config.Out_trade_no: " + Config.Out_trade_no);
            BaseService.WriteLog("Config.Total_fee: " + Config.Total_fee);
            BaseService.WriteLog("Config.Seller_account_name: " + Config.Seller_account_name);
            BaseService.WriteLog("Config.Notify_url: " + Config.Notify_url);
            BaseService.WriteLog("Config.Out_user: "******"Config.Merchant_url: " + Config.Merchant_url);
            BaseService.WriteLog("Config.Call_back_url: " + Config.Call_back_url);
            BaseService.WriteLog("Config.Service_Create: " + Config.Service_Create);
            BaseService.WriteLog("Config.Sec_id: " + Config.Sec_id);
            BaseService.WriteLog("Config.Partner: " + Config.Partner);
            BaseService.WriteLog("Config.Req_id: " + Config.Req_id);
            BaseService.WriteLog("Config.Format: " + Config.Format);
            BaseService.WriteLog("Config.V: " + Config.V);
            BaseService.WriteLog("Config.Req_url: " + Config.Req_url);
            BaseService.WriteLog("Config.PrivateKey: " + Config.PrivateKey);
            BaseService.WriteLog("Config.Input_charset_UTF8: " + Config.Input_charset_UTF8);
            BaseService.WriteLog("返回token: " + token);
            BaseService.WriteLog("创建交易接口结束");

            BaseService.WriteLog("构造,重定向URL");
            //构造,重定向URL
            string url = ali.alipay_Wap_Auth_AuthAndExecute(
                Config.Req_url,
                Config.Sec_id,
                Config.Partner,
                Config.Call_back_url,
                Config.Format,
                Config.V,
                Config.Service_Auth,
                token,
                Config.Req_url,
                Config.PrivateKey,
                Config.Input_charset_UTF8);

            BaseService.WriteLog("最终要跳转的URL字符串: " + url);
            BaseService.WriteLog("构造,重定向URL结束");

            var alipayEntity = new AlipayWapTradeResponseEntity()
            {
                ResponseID  = System.Guid.NewGuid().ToString().Replace("-", ""),
                OrderID     = order_id,
                OutTradeNo  = Config.Out_trade_no,
                Subject     = Config.Subject,
                TotalFee    = Config.Total_fee,
                MerchantUrl = Config.Merchant_url,
                CallBackUrl = call_back_url,
                Status      = "1"
            };

            //保存交易记录到数据库
            AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());

            alipayServer.Create(alipayEntity);

            //跳转收银台支付页面
            Response.Redirect(url);
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BaseService.WriteLog("页面跳转同步通知页面-----------------------Call_Back.aspx");
            AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());

            //获取签名
            string sign = Request["sign"];

            BaseService.WriteLog("签名sign:" + sign);

            //获取所有参数
            SortedDictionary <string, string> sArrary = GetRequestGet();

            BaseService.WriteLog("开始验证签名:");
            bool isVerify = Function.Verify(sArrary, sign, Config.Alipaypublick, Config.Input_charset_UTF8);

            BaseService.WriteLog("结束验证签名:");
            BaseService.WriteLog("验签结果:" + isVerify);

            if (!isVerify)
            {
                //验签出错,可能被别人篡改数据
                if (Request["out_trade_no"] != null)
                {
                    alipayServer.UpdateAlipayWapTradeStatus(Request["out_trade_no"], "4");
                    PostResult(alipayServer, "fail");

                    BaseService.WriteLog("验签出错,可能被别人篡改数据。");
                }

                Response.Write("fail");
                return;
            }

            string result = Request["result"];

            BaseService.WriteLog("result:" + result);

            if (!result.Equals("success"))
            {
                //交易失败
                if (Request["out_trade_no"] != null)
                {
                    alipayServer.UpdateAlipayWapTradeStatus(Request["out_trade_no"], "3");
                    PostResult(alipayServer, "fail");

                    BaseService.WriteLog("交易失败,更新支付宝交易状态");
                }

                Response.Write("fail");
                return;
            }
            else //交易成功,请填写自己的业务代码
            {
                if (Request["out_trade_no"] != null)
                {
                    BaseService.WriteLog("out_trade_no:" + Request["out_trade_no"]);
                    BaseService.WriteLog("交易成功");

                    alipayServer.UpdateAlipayWapTradeStatus(Request["out_trade_no"], "2");
                    PostResult(alipayServer, "success");
                }
                else
                {
                    BaseService.WriteLog("out_trade_no is null!!!!! ");
                }

                Response.Redirect(Config.Merchant_url);
            }
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BaseService.WriteLog("页面跳转同步通知页面-----------------------AlipayWapTrade2/Call_Back.aspx");
            AlipayWapTradeResponseBLL alipayServer = new AlipayWapTradeResponseBLL(new Utility.BasicUserInfo());

            Dictionary <string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayNotify aliNotify    = new AlipayNotify();
                bool         verifyResult = aliNotify.VerifyReturn(sPara, Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码


                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表

                    //商户订单号
                    string out_trade_no = Request.QueryString["out_trade_no"];

                    //支付宝交易号
                    string trade_no = Request.QueryString["trade_no"];

                    //交易状态
                    string result = Request.QueryString["result"];

                    //判断是否在商户网站中已经做过了这次通知返回的处理
                    //如果没有做过处理,那么执行商户的业务程序
                    //如果有做过处理,那么不执行商户的业务程序

                    BaseService.WriteLog("result:" + result);

                    if (!result.Equals("success"))
                    {
                        //交易失败
                        if (!string.IsNullOrEmpty(out_trade_no))
                        {
                            alipayServer.UpdateAlipayWapTradeStatus(Request["out_trade_no"], "3");
                            PostResult(alipayServer, "fail");

                            //推送交易结果集
                            BaseService.WriteLog("推送交易结果集");
                            PostResult(alipayServer, "fail");

                            BaseService.WriteLog("交易失败,更新支付宝交易状态");
                        }

                        Response.Write("fail");
                        return;
                    }
                    else //交易成功,请填写自己的业务代码
                    {
                        if (!string.IsNullOrEmpty(out_trade_no))
                        {
                            try
                            {
                                BaseService.WriteLog("out_trade_no:" + out_trade_no);
                                BaseService.WriteLog("交易成功");

                                //更新交易状态
                                BaseService.WriteLog("更新交易状态");
                                alipayServer.UpdateAlipayWapTradeStatus(out_trade_no, "2");

                                //处理分润业务
                                BaseService.WriteLog("处理分润业务");
                                //RoyaltyBusiness(out_trade_no, trade_no);

                                //推送交易结果集
                                BaseService.WriteLog("推送交易结果集");
                                PostResult(alipayServer, "success");
                            }
                            catch (Exception ex)
                            {
                                BaseService.WriteLog("异常信息: " + ex.ToString());
                            }
                        }
                        else
                        {
                            BaseService.WriteLog("out_trade_no is null!!!!! ");
                        }

                        Response.Redirect(AlipayConfig.Merchant_url);
                    }
                }
                else//验证失败
                {
                    if (Request["out_trade_no"] != null)
                    {
                        alipayServer.UpdateAlipayWapTradeStatus(Request["out_trade_no"], "4");
                        PostResult(alipayServer, "fail");

                        BaseService.WriteLog("验签出错,可能被别人篡改数据。");
                    }

                    Response.Write("验证失败");
                }
            }
            else
            {
                Response.Write("无返回参数");
            }
        }