/// <summary> /// 跳转至支付宝支付 /// </summary> /// <param name="out_trade_no">商户订单号(商户网站订单系统中唯一订单号,必填)</param> /// <param name="subject">订单名称(必填)</param> /// <param name="total_fee">付款金额(必填)</param> /// <param name="notify_url">服务器异步通知页面路径</param> /// <param name="return_url">页面跳转同步通知页面路径</param> /// <param name="show_url">商品展示地址</param> /// <param name="body">订单描述</param> /// <returns></returns> public ActionResult RedirectToAlipay(string out_trade_no, string subject, string total_fee, string notify_url, string return_url, string show_url, string body) { AlipaySetting setting = AlipaySetting.getInstance(); Alipay.Direct.Config.Partner = setting.Direct_Partner; Alipay.Direct.Config.Key = setting.Direct_Key; string seller_email = setting.Direct_Seller_Email; ////////////////////////////////////////////请求参数//////////////////////////////////////////// //支付类型 string payment_type = "1"; string anti_phishing_key = ""; //若要使用请调用类文件submit中的query_timestamp函数 //客户端的IP地址 string exter_invoke_ip = ""; //非局域网的外网IP地址,如:221.0.0.1 //////////////////////////////////////////////////////////////////////////////////////////////// //把请求参数打包成数组 SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>(); sParaTemp.Add("partner", Alipay.Direct.Config.Partner); sParaTemp.Add("_input_charset", Alipay.Direct.Config.Input_charset.ToLower()); sParaTemp.Add("service", "create_direct_pay_by_user"); sParaTemp.Add("payment_type", payment_type); sParaTemp.Add("notify_url", notify_url); sParaTemp.Add("return_url", return_url); sParaTemp.Add("seller_email", seller_email); sParaTemp.Add("out_trade_no", out_trade_no); sParaTemp.Add("subject", subject); sParaTemp.Add("total_fee", total_fee); sParaTemp.Add("body", body); sParaTemp.Add("show_url", show_url); sParaTemp.Add("anti_phishing_key", anti_phishing_key); sParaTemp.Add("exter_invoke_ip", exter_invoke_ip); //建立请求 string sHtmlText = Alipay.Direct.Submit.BuildRequest(sParaTemp, "get", "确认"); return(Content(sHtmlText)); }
/// <summary> /// 跳转至支付宝支付 /// </summary> /// <param name="seller_email">卖家支付宝帐户(必填)</param> /// <param name="out_trade_no">商户订单号(商户网站订单系统中唯一订单号,必填)</param> /// <param name="subject">订单名称(必填)</param> /// <param name="total_fee">付款金额(必填)</param> /// <param name="notify_url">服务器异步通知页面路径</param> /// <param name="call_back_url">页面跳转同步通知页面路径</param> /// <param name="merchant_url">操作中断返回地址</param> /// <returns></returns> public ActionResult RedirectToAlipay(string seller_email, string out_trade_no, string subject, string total_fee, string notify_url, string call_back_url, string merchant_url) { AlipaySetting setting = AlipaySetting.getInstance(); Alipay.WAP.Config.Partner = setting.WAP_Partner; Alipay.WAP.Config.Private_key = setting.WAP_Private_key; Alipay.WAP.Config.Public_key = setting.WAP_Public_key; //支付宝网关地址 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("yyyyMMddHHmmssffff"); //必填,须保证每次请求都是唯一 //请求业务参数详细 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", Alipay.WAP.Config.Partner); sParaTempToken.Add("_input_charset", Alipay.WAP.Config.Input_charset.ToLower()); sParaTempToken.Add("sec_id", Alipay.WAP.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 = Alipay.WAP.Submit.BuildRequest(GATEWAY_NEW, sParaTempToken); //URLDECODE返回的信息 System.Text.Encoding code = System.Text.Encoding.GetEncoding(Alipay.WAP.Config.Input_charset); sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code); //解析远程模拟提交后返回的信息 Dictionary <string, string> dicHtmlTextToken = Alipay.WAP.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", Alipay.WAP.Config.Partner); sParaTemp.Add("_input_charset", Alipay.WAP.Config.Input_charset.ToLower()); sParaTemp.Add("sec_id", Alipay.WAP.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 = Alipay.WAP.Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认"); return(Content(sHtmlText)); }