protected void Page_Load(object sender, EventArgs e) { #region 订单信息 string tmpOrderId = Request.QueryString["OrderId"]; Eyousoft_yhq.BLL.Order OrderInfo = new Eyousoft_yhq.BLL.Order(); Eyousoft_yhq.Model.Order OrderModel = null; if (!string.IsNullOrEmpty(tmpOrderId)) { OrderModel = OrderInfo.GetModel(tmpOrderId); if (OrderModel != null) { if (OrderModel.OrderPrice <= 0) { Response.Write("支付金额必须大于0才能支付!"); Response.End(); } else if (OrderModel.OrderState != Eyousoft_yhq.Model.OrderState.待付款) { Response.Write("订单状态不符合请稍候支付"); Response.End(); } else if (OrderModel.PayState != Eyousoft_yhq.Model.PaymentState.未支付) { Response.Write("订单已支付"); Response.End(); } } } else { Response.Write("订单错误"); Response.End(); } #endregion #region 手机支付宝 支付 //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //req_data详细信息 //服务器异步通知页面路径 string notify_url = AlipayLibrary.Config.GetConfigString("Alipay", "app_notify_url");// "http://www.xxx.com/Alipay/notify_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 string call_back_url = AlipayLibrary.Config.GetConfigString("Alipay", "app_callback_url");// "http://127.0.0.1:64704/Alipay/call_back_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //操作中断返回地址 string merchant_url = AlipayLibrary.Config.GetConfigString("Alipay", "app_return_url"); //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 #region 订单信息|卖家帐号 //卖家支付宝帐户 string seller_email = AlipayLibrary.Config.GetConfigString("appSettings", "AlipayAccount"); //必填 //商户订单号 string out_trade_no = OrderModel.OrderID; //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = "产品名称:" + OrderModel.ProductName; //必填 //付款金额 string total_fee = OrderModel.OrderPrice.ToString(); //必填 #endregion //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); Response.Write(sHtmlText); #endregion }
public string GetPayRequest(Hashtable hash) { //================================================================================== //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //商户号 string partner = hash["alipay_key"].ToString(); //密钥 string key = hash["alipay_secret"].ToString(); AlipayMobileConfig.Partner = partner; AlipayMobileConfig.Key = key; float product_fee = (float)hash["order_fee"]; //商品费用 float transport_fee = float.Parse(hash["order_exp_fee"].ToString()); //物流费用 //当前时间 yyyyMMdd string date = DateTime.Now.ToString("yyyyMMdd"); //req_data详细信息 //服务器异步通知页面路径 //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 string notify_url = hash.Contains("notify_url") ? hash["notify_url"].ToString() : PayUtil.GetNotifyUrl(PayMethods.Alipay, PayApiType.Direct); //需http://格式的完整路径,不能加?id=123这类自定义参数 //页面跳转同步通知页面路径 string return_url = hash.Contains("return_url") ? hash["return_url"].ToString() : PayUtil.GetReturnUrl(PayMethods.Alipay, PayApiType.Direct); //操作中断返回地址 string merchant_url = return_url; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //卖家支付宝帐户 string seller_email = hash["seller_account"] as string; //必填 //订单号,此处用时间和随机数生成,商户根据自己调整,保证唯一 string out_trade_no = hash["order_no"].ToString(); string host = hash["usr_host"] as string; string showUrl = hash["order_showurl"] as string; //商户网站订单系统中唯一订单号,必填 //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里 string subject = hash["order_subject"].ToString(); //parma.desc ?? "支付订单"; //必填 //订单总金额,显示在支付宝收银台里的“应付总额”里 string total_fee = Convert.ToString(product_fee + transport_fee); //必填 //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + return_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", AlipayMobileConfig.Partner); sParaTempToken.Add("_input_charset", AlipayMobileConfig.Input_charset.ToLower()); sParaTempToken.Add("sec_id", AlipayMobileConfig.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 System.Text.Encoding code = System.Text.Encoding.GetEncoding(AlipayMobileConfig.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", AlipayMobileConfig.Partner); sParaTemp.Add("_input_charset", AlipayMobileConfig.Input_charset.ToLower()); sParaTemp.Add("sec_id", AlipayMobileConfig.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); return(sHtmlText); }
public string GetRequestUrl(string returnUrl, string notifyUrl, string orderId, decimal totalFee, string productInfo, string openId = null) { if (string.IsNullOrEmpty(productInfo)) { throw new PluginConfigException("商品信息不能为空!"); } if (string.IsNullOrEmpty(orderId)) { throw new PluginConfigException("订单号不能为空!"); } if (string.IsNullOrEmpty(returnUrl)) { throw new PluginConfigException("返回URL不能为空!"); } if (_config == null) { _config = Utility <Config> .GetConfig(WorkDirectory); } string strResult = string.Empty; Dictionary <string, string> dicPara = new Dictionary <string, string>(); dicPara.Add("service", _config.GetTokenService); //取令牌接口 dicPara.Add("format", "xml"); //固定参数 dicPara.Add("v", "2.0"); //固定参数 dicPara.Add("partner", _config.Partner); //合作者ID,支付宝提供 dicPara.Add("req_id", System.DateTime.Now.ToString("yyyyMMddHHmmss")); dicPara.Add("sec_id", _config.Sign_type); //签名方式,暂时使用MD5 dicPara.Add("_input_charset", "utf-8"); //************************** #region 整理请求数据 StringBuilder reqdata = new StringBuilder(); reqdata.Append("<direct_trade_create_req>"); reqdata.Append("<notify_url>"); reqdata.Append(notifyUrl); reqdata.Append("</notify_url>"); //用户购买的商品名称 reqdata.Append("<subject>"); reqdata.Append(productInfo); reqdata.Append("</subject>"); //支付宝合作商户网站唯一订单号 reqdata.Append("<out_trade_no>"); reqdata.Append(orderId); reqdata.Append("</out_trade_no>"); //该笔订单的资金总额,单位为RMB-Yuan。取值范围为[0.01,100000000.00],精确到小数点后两位 reqdata.Append("<total_fee>"); reqdata.Append(totalFee); reqdata.Append("</total_fee>"); //卖家的支付宝账号 reqdata.Append("<seller_account_name>"); reqdata.Append(_config.Seller_email); reqdata.Append("</seller_account_name>"); //支付成功后的跳转页面链接 reqdata.Append("<call_back_url>"); reqdata.Append(returnUrl); reqdata.Append("</call_back_url>"); //支付宝服务器主动通知商户网站里指定的页面http路径 reqdata.Append("<notify_url>"); reqdata.Append(notifyUrl); reqdata.Append("</notify_url>"); //买家在商户系统的唯一标识。当该买家支付成功一次后,再次支付金额在30元内时,不需要再次输入密码 reqdata.Append("<out_user>"); reqdata.Append(string.Empty); reqdata.Append("</out_user>"); //用户付款中途退出返回商户的地址 reqdata.Append("<merchant_url>"); reqdata.Append(string.Empty); reqdata.Append("</merchant_url>"); //交易自动关闭时间,单位为分钟。默认值21600(即15天)agent_id reqdata.Append("<pay_expire>"); reqdata.Append("30"); reqdata.Append("</pay_expire>"); //代理人ID reqdata.Append("<agent_id>"); reqdata.Append(string.Empty); reqdata.Append("</agent_id>"); reqdata.Append("</direct_trade_create_req>"); #endregion //************************** dicPara.Add("req_data", reqdata.ToString()); string strToken = Submit.BuildRequest(dicPara, _config);//调用接口取令牌 Dictionary <string, string> dicResult = new Dictionary <string, string>(); //Log.Debug("strToken=" + strToken); dicResult = Submit.ParseResponse(strToken, _config); if (dicResult["request_token"] != null) { dicPara = new Dictionary <string, string>(); dicPara.Add("service", _config.GetDataService); //支付接口 dicPara.Add("format", "xml"); //固定参数 dicPara.Add("v", "2.0"); //固定参数 dicPara.Add("partner", _config.Partner); //合作者ID,支付宝提供 dicPara.Add("sec_id", _config.Sign_type); //签名方式,暂时使用MD5 dicPara.Add("_input_charset", "utf-8"); //固定参数 reqdata = new StringBuilder(); reqdata.Append("<auth_and_execute_req>"); reqdata.Append("<request_token>"); reqdata.Append(dicResult["request_token"].ToString()); reqdata.Append("</request_token>"); reqdata.Append("</auth_and_execute_req>"); dicPara.Add("req_data", reqdata.ToString()); strResult = Submit.BuildRequestUrl(dicPara, _config);//生成支付请求地址 } else if (dicResult["res_error"] != null) { throw new PluginConfigException("调用支付接口返回异常:" + dicResult["res_error"].ToString()); } return(strResult); }
protected void Page_Load(object sender, EventArgs e) { //读取站点配置信息 Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(); //=============================获得订单信息================================ string order_no = DTRequest.GetFormString("pay_order_no").ToUpper(); decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0); string user_name = DTRequest.GetFormString("pay_user_name"); string subject = DTRequest.GetFormString("pay_subject"); //检查参数是否正确 if (string.IsNullOrEmpty(order_no) || order_amount == 0) { Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您提交的参数有误!"))); return; } //===============================判断订单================================== if (order_no.StartsWith("R")) //R开头为在线充值订单 { Model.user_recharge model = new BLL.user_recharge().GetModel(order_no); if (model == null) { Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您充值的订单号不存在或已删除!"))); return; } if (model.amount != order_amount) { Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您充值的订单金额与实际金额不一致!"))); return; } } else //B开头为商品订单 { Model.orders model = new BLL.orders().GetModel(order_no); if (model == null) { Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您支付的订单号不存在或已删除!"))); return; } if (model.order_amount != order_amount) { Response.Redirect(new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,您支付的订单金额与实际金额不一致!"))); return; } } if (user_name != "") { user_name = "支付会员:" + user_name; } else { user_name = "匿名用户"; } //===============================建立请求================================== string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; //支付宝网关地址 string format = "xml"; //返回格式,必填,不需要修改 string v = "2.0"; //必填,不需要修改 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //请求业务参数详细,必填 string req_dataToken = "<direct_trade_create_req><notify_url>" + Config.Notify_url + "</notify_url><call_back_url>" + Config.Return_url + "</call_back_url><seller_account_name>" + Config.Seller_email + "</seller_account_name><out_trade_no>" + order_no + "</out_trade_no><subject>" + siteConfig.webname + "-" + subject + "</subject><total_fee>" + order_amount.ToString() + "</total_fee><merchant_url></merchant_url></direct_trade_create_req>"; //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 System.Text.Encoding code = System.Text.Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; //业务详细,必填 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); Response.Write(sHtmlText); }
protected void Page_Load(object sender, EventArgs e) { int orderid = Request["out_trade_no"].ConvertTo <int>(0); //根据订单id得到订单信息 B2bOrderData dataorder = new B2bOrderData(); B2b_order modelb2border = dataorder.GetOrderById(orderid); //根据产品id得到产品信息 B2bComProData datapro = new B2bComProData(); B2b_com_pro modelcompro = datapro.GetProById(modelb2border.Pro_id.ToString()); if (modelb2border != null) { //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //req_data详细信息 //服务器异步通知页面路径 //string notify_url = ""; string notify_url = "http://" + RequestUrl + "/h5/pay_by/notify_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 //string call_back_url = "http://127.0.0.1:64704/WS_WAP_PAYWAP-CSHARP-UTF-8/call_back_url.aspx"; string call_back_url = "http://" + RequestUrl + "/h5/pay_by/call_back_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //操作中断返回地址 //string merchant_url = "http://v.etown.cn"; string merchant_url = "http://" + RequestUrl + "/h5/Orderlist.aspx"; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //卖家支付宝帐户 string seller_email = "*****@*****.**"; //必填 //商户订单号 string out_trade_no = modelb2border.Id.ToString(); //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = ""; if (modelb2border.Order_type == 1) { subject = modelcompro.Pro_name; } if (modelb2border.Order_type == 2) { if (modelb2border.serverid == "") { subject = "预付款充值"; } else { subject = "购买服务于押金"; } } //必填 //付款金额 string total_fee = (modelb2border.Pay_price * modelb2border.U_num + modelb2border.Express - modelb2border.Integral1 - modelb2border.Imprest1).ToString(); //必填 if (modelb2border.Child_u_num > 0)//如果是旅游包含儿童的 { total_fee = (Decimal.Parse(total_fee) + modelb2border.Child_u_num * (modelb2border.Pay_price - modelcompro.Childreduce)).ToString(); } //如果是购物车订单重新写金额 if (modelb2border.Shopcartid != 0) { total_fee = dataorder.GetCartOrderMoneyById(orderid).ToString("0.00");; } //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //写入支付数据库,先判定是否有此订单支付 //根据订单id得到订单信息 B2bPayData datapay = new B2bPayData(); B2b_pay modelb2pay = datapay.GetPayByoId(orderid); if (modelb2pay == null) { B2b_pay eticket = new B2b_pay() { Id = 0, Oid = orderid, Pay_com = "malipay", Pay_name = modelb2border.U_name, Pay_phone = modelb2border.U_phone, Total_fee = decimal.Parse(total_fee), Trade_no = "", Trade_status = "trade_pendpay", Uip = "", comid = 106 }; int payid = datapay.InsertOrUpdate(eticket); } else { //对已完成支付的,再次提交支付,跳转到订单也或显示此订单已支付 if (modelb2pay.Trade_status != "TRADE_SUCCESS") { //防止金额有所改动 modelb2pay.comid = 106; modelb2pay.Pay_com = "malipay"; modelb2pay.Total_fee = decimal.Parse(total_fee); datapay.InsertOrUpdate(modelb2pay); } } //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); Response.Write(sHtmlText); } }
public string Payment() { int state; DateTime dt_now = DateTime.Now; Recharge rechargeInfo = new Recharge(); TryUpdateModel(rechargeInfo); if (!ModelState.IsValid) { return("输入错误!"); } rechargeInfo = (Recharge)Session["rechargeInfo"]; if (null == rechargeInfo) { return("输入错误!"); } SqlConnection sqlCnt = DBHelper.getConnection(); SqlCommand cmd = null; SqlTransaction sqlTransaction = null; //---------------------------------手机Wap //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = dt_now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //req_data详细信息 //服务器异步通知页面路径 string notify_url = "http://122.226.141.18:28810/Alipay/Notify"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 string call_back_url = "http://122.226.141.18:28810/Alipay/Success"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //操作中断返回地址 string merchant_url = "http://122.226.141.18:28810/Alipay/Error"; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //商户订单号 string out_trade_no = rechargeInfo.flowid; //Request.Form["flowid"];//"testID00008";// WIDout_trade_no.Text.Trim(); //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = "预交款:流水号:[" + rechargeInfo.desc + "],mrn:{" + rechargeInfo.mrn + "}"; //Request.Form["desc"]; //"testItem0000008";// //WIDsubject.Text.Trim(); //必填 //付款金额 string total_fee = rechargeInfo.fee.ToString("f2"); //Request.Form["fee"]; //"0.01";//WIDtotal_fee.Text.Trim(); //必填 //订单超时时间 string pay_expir = "1"; // 1 min //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + Config.Seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url><pay_expire>" + pay_expir + "</pay_expire></direct_trade_create_req>"; //必填 Guid guid = new Guid(); try { guid = new Guid(out_trade_no); } catch (Exception e) { //取不到支付宝预交款订单信息 return("输入错误的订单号。" + e.Message); } //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); //写html //Response.Write(sHtmlText); //======================================================================================= //本地记录xml try { sqlCnt.Open(); cmd = sqlCnt.CreateCommand(); //创建SqlCommand对象 cmd.CommandType = CommandType.Text; //cmd.CommandText = "select COUNT(*) from BankMsgSwitch where GUID =@GUID"; //sql语句 cmd.Parameters.Add("@GUID", SqlDbType.UniqueIdentifier); cmd.Parameters["@GUID"].Value = guid; cmd.Parameters.Add("@HospSerial", SqlDbType.NChar); cmd.Parameters["@HospSerial"].Value = rechargeInfo.desc; cmd.Parameters.Add("@TMsg_xml", SqlDbType.Xml); cmd.Parameters["@TMsg_xml"].Value = req_dataToken; cmd.Parameters.Add("@TMsg_txt", SqlDbType.Text); cmd.Parameters["@TMsg_txt"].Value = req_dataToken; cmd.Parameters.Add("@Tdatetime", SqlDbType.DateTime); cmd.Parameters["@TDatetime"].Value = dt_now; sqlTransaction = sqlCnt.BeginTransaction(); cmd.Transaction = sqlTransaction; cmd.CommandText = "insert into BankMsgSwitch (GUID,TransType,HospSerialNo,BankID,TMsg,TMsgText,TDateTime) values (@GUID,'I-paPref',@HospSerial,'100040',@TMsg_xml,@TMsg_txt,GETDATE())"; //sql语句 try { cmd.ExecuteNonQuery(); sqlTransaction.Commit(); state = 1; } catch (Exception e) { sqlTransaction.Rollback(); state = -1; log4netHelper.error("转支付宝失败", "--2--前端发起支付宝交易失败:[GUID]" + guid + "__[ERROR]" + e.Message.ToString()); } } catch (Exception e) { state = -3; log4netHelper.error("转支付宝失败", "--1--前端获取订单信息失败:[GUID]" + guid + "__[ERROR]" + e.Message.ToString()); } finally { if (null != sqlTransaction) { sqlTransaction.Dispose(); sqlTransaction = null; } if (null != cmd) { cmd.Dispose(); cmd = null; } sqlCnt.Close(); } switch (state) { case 1: return(sHtmlText); break; case -1: return("失败"); default: return("失败"); } }
public string Index() { //调用log4net // //调用1 //LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Error("logtest"); //调用2 //logger.Error("111111111111"); //调用3 //log4netHelper.error(this.GetType(), "321"); // Recharge rechargeInfo = new Recharge(); TryUpdateModel(rechargeInfo); if (!ModelState.IsValid) { return("失败"); } //---------------------------------手机Wap //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //req_data详细信息 //服务器异步通知页面路径 string notify_url = "http://localhost:3056/alipay/success02"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 string call_back_url = "http://localhost:3056/alipay/success01"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //操作中断返回地址 string merchant_url = "http://localhost:3056/WS_WAP_PAYWAP-CSHARP-UTF-8/xxxxx.aspx"; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //商户订单号 string out_trade_no = rechargeInfo.flowid; //Request.Form["flowid"];//"testID00008";// WIDout_trade_no.Text.Trim(); //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = rechargeInfo.desc; //Request.Form["desc"]; //"testItem0000008";// //WIDsubject.Text.Trim(); //必填 //付款金额 string total_fee = rechargeInfo.fee.ToString(); //Request.Form["fee"]; //"0.01";//WIDtotal_fee.Text.Trim(); //必填 //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + Config.Seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); //写html //Response.Write(sHtmlText); return(sHtmlText); }
protected void Page_Load(object sender, EventArgs e) { try { if (Request["oid"] == null) { Response.Write("订单无效"); Response.End(); } int OrderId; if (!int.TryParse(Request["oid"], out OrderId)) { Response.Write("订单无效"); Response.End(); } Order = bllMall.GetOrderInfo(Request["oid"]); if (Order == null) { Response.Write("订单无效"); Response.End(); } if (!Order.PaymentStatus.Equals(0)) { Response.Write("订单不是未付款状态"); Response.End(); } if (!Order.PaymentType.Equals(1)) { Response.Write("订单不属于支付宝支付"); Response.End(); } if (string.IsNullOrEmpty(Order.PaymentTypeAutoId)) { Response.Write("无效支付方式"); Response.End(); } WXMallPaymentType paymentType = bllMall.GetPaymentType(int.Parse(Order.PaymentTypeAutoId)); if (paymentType == null) { Response.Write("无效支付方式"); Response.End(); } //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(0, 99999); //必填,须保证每次请求都是唯一 //req_data详细信息 //服务器异步通知页面路径 string notify_url = string.Format("http://{0}/alipay/mallnotifyurl.aspx", Request.Url.Host); //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 string call_back_url = string.Format("http://{0}/alipay/mallcall_back_url.aspx", Request.Url.Host); //需http://格式的完整路径,不允许加?id=123这类自定义参数 //操作中断返回地址 string merchant_url = string.Format("http://{0}/alipay/merchanturl.aspx", Request.Url.Host); //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //卖家支付宝帐户 //string seller_email = "*****@*****.**"; string seller_email = paymentType.AlipaySeller_Account_Name; //必填 //商户订单号 string out_trade_no = Order.OrderID; //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = string.Format("订单{0}", Order.OrderID); //必填 //付款金额 string total_fee = Order.TotalAmount.ToString(); //必填 //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", paymentType.AlipayPartner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequestMall(GATEWAY_NEW, sParaTempToken, paymentType.AlipayPartnerKey); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding("utf-8"); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //using (System.IO.StreamWriter sr = new StreamWriter("D:\\MonitorHandlerException.txt")) //{ // sr.Write(sHtmlTextToken); //} //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", paymentType.AlipayPartner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequestMall(GATEWAY_NEW, sParaTemp, "get", "确认", paymentType.AlipayPartnerKey); Response.Write(sHtmlText); } catch (Exception ex) { Response.Write(ex.Message); Response.End(); } }
/// <summary> /// 支付宝结算 /// </summary> public override void ProcessMessage() { var listpbxx = DBVisitor.ExecuteTable(SqlLoad.GetFormat(SQ.HIS00002, InObject.WIDOUTTRADENO)); LogUnit.Write(listpbxx.Rows.Count.ToString()); if (listpbxx.Rows.Count > 0) { throw new Exception("商户订单号不能重复!"); } #region //手机网页支付 if (InObject.JIESUANLX == "1") { //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 if (string.IsNullOrEmpty(InObject.QINGQIUDH)) { throw new Exception("请求单号不能为空!"); } //请求号 string req_id = InObject.QINGQIUDH; //DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //req_data详细信息 if (string.IsNullOrEmpty(InObject.NOTIFYURL)) { throw new Exception("服务器异步通知页面路径不能为空!"); } //服务器异步通知页面路径 string notify_url = InObject.NOTIFYURL;//"http://商户网关地址/WS_WAP_PAYWAP-CSHARP-UTF-8/notify_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 if (string.IsNullOrEmpty(InObject.CALLBACKURL)) { throw new Exception("页面跳转同步通知页面路径不能为空!"); } //页面跳转同步通知页面路径 string call_back_url = InObject.CALLBACKURL;//"http://127.0.0.1:64704/WS_WAP_PAYWAP-CSHARP-UTF-8/call_back_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 if (string.IsNullOrEmpty(InObject.MERCHANTURL)) { throw new Exception("操作中断返回地址不能为空!"); } //操作中断返回地址 string merchant_url = InObject.MERCHANTURL;// "http://127.0.0.1:64704/WS_WAP_PAYWAP-CSHARP-UTF-8/xxxxx.aspx"; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 if (string.IsNullOrEmpty(InObject.WIDOUTTRADENO)) { throw new Exception("商户订单号不能为空!"); } //商户订单号 string out_trade_no = InObject.WIDOUTTRADENO;// WIDout_trade_no.Text.Trim(); //商户网站订单系统中唯一订单号,必填 if (string.IsNullOrEmpty(InObject.WIDSUBJECT)) { throw new Exception("订单名称不能为空!"); } //订单名称 string subject = InObject.WIDSUBJECT;//WIDsubject.Text.Trim(); //必填 if (string.IsNullOrEmpty(InObject.WIDTOTALFEE)) { throw new Exception("付款金额不能为空!"); } //付款金额 string total_fee = InObject.WIDTOTALFEE; //WIDtotal_fee.Text.Trim(); //必填 //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + Common.Alipay.Config.Seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = System.Web.HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 DBVisitor.ExecuteNonQuery(SqlLoad.GetFormat(SQ.HIS00001, InObject.QINGQIUDH, //请求单号 '1', //结算类型 1手机网页支付 2二维码扫描支付 3商户代扣 InObject.NOTIFYURL, //服务器异步通知页面路径 InObject.CALLBACKURL, //页面跳转同步通知页面路径 InObject.MERCHANTURL, //操作中断返回地址) InObject.WIDOUTTRADENO, //商户订单号 InObject.WIDSUBJECT, //订单名称 InObject.WIDTOTALFEE, //订单金额 InObject.WIDBODY, //订单描述 InObject.OUTTIME, //超时时间取值范围 "", //买家支付宝用户号 "", //买家支付宝帐号 "", //授权号 "", //协议号 "0", //结算状态 0未结算 1结算成功 2结算失败 request_token)); //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); OutObject = new ZHIFUBAOJS_OUT(); OutObject.JIESUANURL = sHtmlText; } #endregion #region 二维码支付 else if (InObject.JIESUANLX == "2") { if (string.IsNullOrEmpty(InObject.BASEINFO.FENYUANDM)) { throw new Exception("医院代码不能为空!"); } if (string.IsNullOrEmpty(InObject.BASEINFO.CAOZUOYDM)) { throw new Exception("操作员代码不能为空!"); } if (string.IsNullOrEmpty(InObject.BASEINFO.CAOZUOYXM)) { throw new Exception("操作员姓名不能为空!"); } if (string.IsNullOrEmpty(InObject.JIUZHENKH)) { throw new Exception("就诊卡号不能为空!"); } DataTable dt = DBVisitor.ExecuteTable(SqlLoad.GetFormat(SQ.HIS00006, InObject.BASEINFO.FENYUANDM)); if (dt.Rows.Count <= 0) { throw new Exception("查询不到医院代码为【" + InObject.BASEINFO.FENYUANDM + "】的医院信息"); } var ddxx = DBVisitor.ExecuteTable(SqlLoad.GetFormat(SQ.HIS00002, InObject.WIDOUTTRADENO)); if (ddxx.Rows.Count > 0) { throw new Exception("已存在相同订单号的结算信息!"); } if (string.IsNullOrEmpty(InObject.NOTIFYURL)) { throw new Exception("异步请求地址不能为空!"); } //服务器异步通知页面路径 string notify_url = ConfigurationManager.AppSettings["FWPTURL"] + "NotifyUrl2.aspx";//InObject.NOTIFYURL; //需http://格式的完整路径,不能加?id=123这类自定义参数 //商户订单号 string out_trade_no = InObject.WIDOUTTRADENO;// WIDout_trade_no.Text.Trim(); //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = InObject.WIDSUBJECT;// WIDsubject.Text.Trim(); //必填 //订单业务类型 string product_code = "QR_CODE_OFFLINE";// WIDproduct_code.Text.Trim(); //目前只支持QR_CODE_OFFLINE(二维码支付),必填 //付款金额 string total_fee = InObject.WIDTOTALFEE;// WIDtotal_fee.Text.Trim(); //必填 //卖家支付宝帐户 string seller_email = dt.Rows[0]["SELLEREMAIL"].ToString(); //WIDseller_email.Text.Trim(); //必填 //订单描述 string body = InObject.WIDBODY; //把请求参数打包成数组 SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("service", "alipay.acquire.precreate"); sParaTemp.Add("notify_url", notify_url); sParaTemp.Add("out_trade_no", out_trade_no); sParaTemp.Add("subject", subject); sParaTemp.Add("product_code", product_code); sParaTemp.Add("total_fee", total_fee); sParaTemp.Add("seller_email", seller_email); sParaTemp.Add("body", body); sParaTemp.Add("it_b_pay", InObject.OUTTIME); sParaTemp.Add("key", "rfk3sw6dlq28k2tijjj54le6lfhw73s4");//取余杭卫生局的key //将请求数据 插入数据库 DBVisitor.ExecuteNonQuery(SqlLoad.GetFormat(SQ.HIS00001, InObject.WIDOUTTRADENO, //商户订单号 '2', //结算类型 1手机网页支付 2二维码扫描支付 3商户代扣 InObject.NOTIFYURL, //服务器异步通知页面路径 "", //页面跳转同步通知页面路径 "", //操作中断返回地址) InObject.WIDSUBJECT, //订单名称 InObject.WIDTOTALFEE, //订单金额 InObject.WIDBODY, //订单描述 InObject.OUTTIME, //超时时间取值范围 InObject.BUYERID, //买家支付宝用户号 InObject.BUYEREMAIL, //买家支付宝帐号 InObject.AUTHNO, //授权号 InObject.AGREENNO, //协议号 "0", //结算状态 0未结算 1结算成功 2结算失败 "", InObject.BASEINFO.FENYUANDM, //分院代码 dt.Rows[0]["SELLEREMAIL"].ToString(), //收款帐号 InObject.BASEINFO.CAOZUOYXM, InObject.BASEINFO.CAOZUOYDM, "", //身份证号 InObject.JIUZHENKH //就诊卡号 )); //建立请求 string sHtmlText = Submit.BuildRequest(sParaTemp); //记录日志 LogUnit.Write("JIESUANLX == 2###" + sHtmlText, "ZHIFUBAOJS"); OutObject = new ZHIFUBAOJS_OUT(); XmlDocument xmlDoc = new XmlDocument(); try { string PicUrl = ""; xmlDoc.LoadXml(sHtmlText); XmlNodeList nodeList = xmlDoc.SelectSingleNode("alipay").ChildNodes; foreach (XmlNode xn in nodeList) { //判断是否异常,如果返回异常 则抛出 //if (xn.Name == "is_success" && xn.InnerText == "F") //{ // throw new Exception("支付宝请求生成二维码失败!"); //} if (xn.Name == "error") { throw new Exception(xn.InnerText); } if (xn.Name == "response") { XmlElement xe = (XmlElement)xn; XmlNodeList subList = xe.ChildNodes; foreach (XmlNode xmlNode in subList) { if (xmlNode.Name == "alipay") { XmlElement xemx = (XmlElement)xmlNode; XmlNodeList submxList = xemx.ChildNodes; foreach (XmlNode mxnode in submxList) { if (mxnode.Name == "detail_error_code") { OutObject.ERRORCODE = mxnode.InnerText; } if (mxnode.Name == "detail_error_des") { OutObject.ERRORDES = mxnode.InnerText; } if (mxnode.Name == "big_pic_url") { // OutObject.PICURL = mxnode.InnerText; PicUrl = mxnode.InnerText; } if (mxnode.Name == "out_trade_no") { OutObject.WIDOUTTRADENO = mxnode.InnerText; } if (mxnode.Name == "qr_code") { OutObject.QRCODE = mxnode.InnerText; } } try {//将二维码图片下载到服务平台本地 var path = HostingEnvironment.ApplicationPhysicalPath + "ZFBImg\\"; DeletePic(path); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.DownloadFile(PicUrl, path + OutObject.WIDOUTTRADENO + ".jpg"); OutObject.PICLOCAL = OutObject.WIDOUTTRADENO + ".jpg"; } catch { } } } } } } catch (Exception exp) { throw new Exception(exp.Message.ToString()); } } #endregion #region 签约账户支付 商户代扣 else if (InObject.JIESUANLX == "3") { if (string.IsNullOrEmpty(InObject.BASEINFO.FENYUANDM)) { throw new Exception("医院代码不能为空!"); } if (string.IsNullOrEmpty(InObject.BASEINFO.CAOZUOYDM)) { throw new Exception("操作员代码不能为空!"); } if (string.IsNullOrEmpty(InObject.BASEINFO.CAOZUOYXM)) { throw new Exception("操作员姓名不能为空!"); } if (string.IsNullOrEmpty(InObject.JIUZHENKH)) { throw new Exception("就诊卡号不能为空!"); } DataTable dt = DBVisitor.ExecuteTable(SqlLoad.GetFormat(SQ.HIS00006, InObject.BASEINFO.FENYUANDM)); if (dt.Rows.Count <= 0) { throw new Exception("查询不到医院代码为【" + InObject.BASEINFO.FENYUANDM + "】的医院信息"); } var ddxx = DBVisitor.ExecuteTable(SqlLoad.GetFormat(SQ.HIS00002, InObject.WIDOUTTRADENO)); if (ddxx.Rows.Count > 0) { throw new Exception("已存在相同订单号的结算信息!"); } SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("service", "alipay.acquire.createandpay"); sParaTemp.Add("notify_url", InObject.NOTIFYURL); sParaTemp.Add("seller_email", dt.Rows[0]["SELLEREMAIL"].ToString()); //Config.Seller_email); //sParaTemp.Add("seller_id", "2088121042783039"); sParaTemp.Add("out_trade_no", InObject.WIDOUTTRADENO); //InObject.WIDOUTTRADENO sParaTemp.Add("subject", InObject.WIDSUBJECT); sParaTemp.Add("product_code", "GENERAL_WITHHOLDING"); sParaTemp.Add("total_fee", InObject.WIDTOTALFEE); sParaTemp.Add("agreement_info", "{\"agreement_no\":\"" + InObject.AGREENNO + "\"}"); //协议号 必传 签约后传回 sParaTemp.Add("key", "rfk3sw6dlq28k2tijjj54le6lfhw73s4"); //取余杭卫生局的key // sParaTemp.Add("royalty_type", "ROYALTY"); // sParaTemp.Add("buyer_id", InObject.BUYERID); // sParaTemp.Add("buyer_email", InObject.BUYEREMAIL); // sParaTemp.Add("body", InObject.WIDBODY); //sParaTemp.Add("it_b_pay", InObject.OUTTIME); //sParaTemp.Add("dynamic_id_type", "bar_code");//动态ID类型 //sParaTemp.Add("dynamic_id", "kff3hjwqzxrbvrrkd0");//动态ID // sParaTemp.Add("auth_no", InObject.AUTHNO); string sfzh = ""; DataTable qyxx = DBVisitor.ExecuteTable(SqlLoad.GetFormat(SQ.HIS00021, InObject.AGREENNO)); if (qyxx.Rows.Count >= 0) { sfzh = qyxx.Rows[0]["SHENFENZH"].ToString(); } //将请求数据 插入数据库 DBVisitor.ExecuteNonQuery(SqlLoad.GetFormat(SQ.HIS00001, InObject.WIDOUTTRADENO, //商户订单号 '3', //结算类型 1手机网页支付 2二维码扫描支付 3商户代扣 "", //服务器异步通知页面路径 "", //页面跳转同步通知页面路径 "", //操作中断返回地址) InObject.WIDSUBJECT, //订单名称 InObject.WIDTOTALFEE, //订单金额 InObject.WIDBODY, //订单描述 InObject.OUTTIME, //超时时间取值范围 InObject.BUYERID, //买家支付宝用户号 InObject.BUYEREMAIL, //买家支付宝帐号 InObject.AUTHNO, //授权号 InObject.AGREENNO, //协议号 "0", //结算状态 0未结算 1结算成功 2结算失败 "", InObject.BASEINFO.FENYUANDM, //分院代码 dt.Rows[0]["SELLEREMAIL"].ToString(), //收款帐号 InObject.BASEINFO.CAOZUOYXM, InObject.BASEINFO.CAOZUOYDM, sfzh, InObject.JIUZHENKH )); LogUnit.Write("开始请求支付宝!"); //建立请求 string sHtmlText = Submit.BuildRequest(sParaTemp); //记录日志 LogUnit.Write("JIESUANLX == 3###" + sHtmlText, "ZHIFUBAOJS"); OutObject = new ZHIFUBAOJS_OUT(); XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml(sHtmlText); XmlNodeList nodeList = xmlDoc.SelectSingleNode("alipay").ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.Name == "error") { DBVisitor.ExecuteNonQuery(string.Format("update JR_ZHIFUBAOJSXX set FAILERR='{0}',JIESUANZT='-1' where IOUTTRADENO='{1}' ", xn.InnerText, InObject.WIDOUTTRADENO)); throw new Exception(xn.InnerText); } if (xn.Name == "response") { XmlElement xe = (XmlElement)xn; XmlNodeList subList = xe.ChildNodes; foreach (XmlNode xmlNode in subList) { if (xmlNode.Name == "alipay") { XmlElement xemx = (XmlElement)xmlNode; XmlNodeList submxList = xemx.ChildNodes; foreach (XmlNode mxnode in submxList) { if (mxnode.Name == "detail_error_code") { OutObject.ERRORCODE = mxnode.InnerText; } if (mxnode.Name == "detail_error_des") { OutObject.ERRORDES = mxnode.InnerText; throw new Exception(mxnode.InnerText); } if (mxnode.Name == "result_code") { OutObject.RESULTCODE = mxnode.InnerText; } if (mxnode.Name == "trade_no") { OutObject.TRADENO = mxnode.InnerText; } if (mxnode.Name == "out_trade_no") { OutObject.WIDOUTTRADENO = mxnode.InnerText; } if (mxnode.Name == "buyer_user_id") { OutObject.BUYERID = mxnode.InnerText; } if (mxnode.Name == "buyer_logon_id") { OutObject.BUYEREMAIL = mxnode.InnerText; } if (mxnode.Name == "total_fee") { OutObject.TOTALFREE = mxnode.InnerText; } if (mxnode.Name == "gmt_payment") { OutObject.PAYMENTTIME = mxnode.InnerText; } if (mxnode.Name == "extend_info") { OutObject.EXTENDINFO = mxnode.InnerText; } if (mxnode.Name == "fund_bill_list") { OutObject.FUNDBILLLIST = mxnode.InnerText; } } } } } } if (OutObject.RESULTCODE.ToUpper() == "ORDER_SUCCESS_PAY_SUCCESS") { DBVisitor.ExecuteNonQuery(string.Format("update JR_ZHIFUBAOJSXX set TRADENO='{0}',JIESUANZT='1',JIESUANSJ= sysdate,IBUYERID='{1}',IBUYEREMAIL='{2}' where IOUTTRADENO='{3}' ", OutObject.TRADENO, OutObject.BUYERID, OutObject.BUYEREMAIL, InObject.WIDOUTTRADENO)); } else { DBVisitor.ExecuteNonQuery(string.Format("update JR_ZHIFUBAOJSXX set FAILERR='{0}',JIESUANZT='-1',IBUYERID='{1}',IBUYEREMAIL='{2}' where IOUTTRADENO='{3}' ", OutObject.ERRORDES, OutObject.BUYERID, OutObject.BUYEREMAIL, InObject.WIDOUTTRADENO)); } } catch (Exception ep) { LogUnit.Write(ep.Message); throw new Exception(ep.Message); } } #endregion else { throw new Exception("支付类型不正确!"); } }
protected void BtnAlipay_Click(object sender, EventArgs e) { //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //req_data详细信息 //服务器异步通知页面路径 string notify_url = "http://商户网关地址/WS_WAP_PAYWAP-CSHARP-UTF-8/notify_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //页面跳转同步通知页面路径 string call_back_url = "http://127.0.0.1:64704/WS_WAP_PAYWAP-CSHARP-UTF-8/call_back_url.aspx"; //需http://格式的完整路径,不允许加?id=123这类自定义参数 //操作中断返回地址 string merchant_url = "http://127.0.0.1:64704/WS_WAP_PAYWAP-CSHARP-UTF-8/xxxxx.aspx"; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //商户订单号 string out_trade_no = WIDout_trade_no.Text.Trim(); //商户网站订单系统中唯一订单号,必填 //订单名称 string subject = WIDsubject.Text.Trim(); //必填 //付款金额 string total_fee = WIDtotal_fee.Text.Trim(); //必填 //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + Config.Seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); Response.Write(sHtmlText); }
public ActionResult AliPay(string id) { var order = psv.GetOrderByOrderNo(id); if (order != null && order.TradeStatus == TradeStatus.NotPay && order.CustomerId.Equals(CurrentMember.MemberId.ToString())) { #region 支付宝 ////////////////////////////////////////////请求参数//////////////////////////////////////////// //返回格式 string format = "xml"; //必填,不需要修改 //返回格式 string v = "2.0"; //必填,不需要修改 //请求号 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //必填,须保证每次请求都是唯一 //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; //订单号 string out_trade_no = order.No; //订单名称 string subject = "蛋糕"; //付款金额 string total_fee = (order.TotalPrice - (order.CouponPay + order.GiftCardPay + order.IntegralPay)) + ""; //订单描述 // string body = string.Join("\r\n", order.OrderDetails.Select(a => a.Name + ":" + a.Num + "张" + a.AllPrice + "元")); //商品展示地址 string show_url = ""; //防钓鱼时间戳 string anti_phishing_key = Submit.Query_timestamp(); //操作中断返回地址 string merchant_url = Url.Action("Index", "Home"); //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //请求业务参数详细 string req_dataToken = "<direct_trade_create_req><notify_url>" + ConfigurationManager.AppSettings["alipay_notify"] + "</notify_url><call_back_url>" + ConfigurationManager.AppSettings["alipay_return"] + "</call_back_url><seller_account_name>" + Config.Seller_Email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute//////////////////////////////////////////// //业务详细 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); ViewBag.html = sHtmlText; return(View()); #endregion } return(Redirect("/")); }
/// <summary> /// 发起一个支付宝的请求(包括授权接口和交易接口) /// </summary> /// <param name="tradeno">订单号</param> /// <param name="totalfee">付款金额</param> /// <param name="merchanturl"></param> /// <param name="notifyurl">异步回调地址</param> /// <param name="callbackurl">同步回调地址</param> /// <param name="cussubject">订单名称</param> public void AlipayRequest(string tradeno, string totalfee, string notifyurl, string callbackurl, string merchanturl, string cussubject) { //支付宝网关地址 var GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token//////////////////////////////////////////// var format = "xml"; var v = "2.0"; //请求号 var req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //req_data详细信息 var notify_url = notifyurl; //需http://格式的完整路径,不允许加?id=123这类自定义参数 var call_back_url = callbackurl; //需http://格式的完整路径,不允许加?id=123这类自定义参数 var merchant_url = merchanturl; //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 //商户订单号 var out_trade_no = tradeno; var subject = cussubject; //付款金额 var total_fee = totalfee; //请求业务参数详细 var req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + Config.Seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //把请求参数打包成数组 var sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 var sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 var code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 var dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token if (!dicHtmlTextToken.ContainsKey("request_token")) { Response.Write("获取request_token失败" + JsonConvert.SerializeObject(dicHtmlTextToken)); return; } var request_token = dicHtmlTextToken["request_token"]; LogHelper.CreateLog(string.Format("获取request_token:{0}", request_token), tradeno); #region 根据授权码token调用交易接口alipay.wap.auth.authAndExecute //业务详细 var req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //必填 //把请求参数打包成数组 var sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 var sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); LogHelper.CreateLog(string.Format("成功获取支付页面"), tradeno); Response.Write(sHtmlText); #endregion 根据授权码token调用交易接口alipay.wap.auth.authAndExecute }
public void Index() { ErrorMessage errorMessage = ErrorMessage.失败; string url = StringHelper.GetHost(); if (string.IsNullOrEmpty(url)) { errorMessage = ErrorMessage.订单初始化失败; return; } int payType = 0; string orderId = ""; int money = 0; int userType = 0; if (PayContext.VerifyPayOrderInfo(1, out errorMessage, out payType, out orderId, out money, out userType)) { //支付宝网关地址 string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?"; #region //返回格式, 必填,不需要修改 string format = "xml"; //返回格式, 必填,不需要修改 string v = "2.0"; //请求号, 必填,须保证每次请求都是唯一 string req_id = DateTime.Now.ToString("yyyyMMddHHmmss"); //req_data详细信息 //服务器异步通知页面路径 ,需http://格式的完整路径,不允许加?id=123这类自定义参数 string notify_url = string.Format("http://{0}/alipay/notify", url); //页面跳转同步通知页面路径, 需http://格式的完整路径,不允许加?id=123这类自定义参数 string call_back_url = string.Format("http://{0}/alipay/result", url); //操作中断返回地址, 用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数 string merchant_url = string.Format("http://{0}/order/recharge", url); //卖家支付宝帐户 string seller_email = Config.SellerEmail; //商户网站订单系统中唯一订单号,必填 //订单名称 必填 string subject = GetName(money); //付款金额(单位:元) 必填 string total_fee = GetFee(money); //请求业务参数详细 必填 string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + orderId + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>"; //把请求参数打包成数组 Dictionary <string, string> sParaTempToken = new Dictionary <string, string>(); sParaTempToken.Add("partner", Config.Partner); sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper()); sParaTempToken.Add("service", "alipay.wap.trade.create.direct"); sParaTempToken.Add("format", format); sParaTempToken.Add("v", v); sParaTempToken.Add("req_id", req_id); sParaTempToken.Add("req_data", req_dataToken); //建立请求 string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 Encoding code = Encoding.GetEncoding(Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken); //获取token string request_token = dicHtmlTextToken["request_token"]; #endregion //业务详细 必填 string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>"; //把请求参数打包成数组 Dictionary <string, string> sParaTemp = new Dictionary <string, string>(); sParaTemp.Add("partner", Config.Partner); sParaTemp.Add("_input_charset", Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Config.Sign_type.ToUpper()); sParaTemp.Add("service", "alipay.wap.auth.authAndExecute"); sParaTemp.Add("format", format); sParaTemp.Add("v", v); sParaTemp.Add("req_data", req_data); //建立请求 string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); Response.Write(sHtmlText); } }