public string GetRequestUrl(string returnUrl, string notifyUrl, string orderId, decimal totalFee, string productInfo, string openId = null) { Config config = _Config; //支付类型,必填,不能修改 string paymentType = "1"; //服务器异步通知页面路径 notifyUrl = string.Format(notifyUrl); //页面跳转同步通知页面路径 returnUrl = string.Format(returnUrl); //收款支付宝帐户 string sellerEmail = config.AlipayAccount; //合作者身份ID string partner = config.Partner; //交易安全检验码 string key = config.Key; //商户订单号 string outTradeNo = orderId.ToString(); //订单名称 string subject = productInfo; //订单描述 string body = ""; //防钓鱼时间戳 string anti_phishing_key = ""; //客户端的IP地址,非局域网的外网IP地址 string exter_invoke_ip = _httpContextAccessor.HttpContext.Features.Get <IHttpConnectionFeature>().RemoteIpAddress.ToString(); //把请求参数打包成数组 Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("partner", partner); parameters.Add("return_url", returnUrl); parameters.Add("seller_email", sellerEmail); parameters.Add("out_trade_no", outTradeNo); parameters.Add("_input_charset", config.Input_charset); parameters.Add("service", "create_direct_pay_by_user"); // parameters.Add("service", "trade_create_by_buyer"); parameters.Add("payment_type", paymentType); parameters.Add("notify_url", notifyUrl); parameters.Add("subject", subject); parameters.Add("total_fee", totalFee.ToString("F2")); parameters.Add("body", body); parameters.Add("anti_phishing_key", anti_phishing_key); parameters.Add("exter_invoke_ip", exter_invoke_ip); parameters.Add("it_b_pay", "30m"); return(Submit.BuildRequestUrl(parameters, config)); }
public string ChargeByAliPay(string productName, decimal amount, string orderNo, string returnUrl) { var config = ConfigInfo; if (!config.IsAliPay) { return(null); } if (config.AliPayIsMApi) { // 合作身份者ID,签约账号,以2088开头由16位纯数字组成的字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm Config.partner = config.AliPayPid; // 收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号 Config.seller_id = Config.partner; // MD5密钥,安全检验码,由数字和字母组成的32位字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm Config.key = config.AliPayMd5; // 服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 Config.notify_url = string.Empty; // 页面跳转同步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 Config.return_url = returnUrl; // 字符编码格式 目前支持 gbk 或 utf-8 Config.input_charset = "utf-8"; // 支付类型 ,无需修改 Config.payment_type = "1"; // 调用的接口名,无需修改 Config.service = "create_direct_pay_by_user"; //////////////////////////////////////////////////////////////////////////////////////////////// //把请求参数打包成数组 var sParaTemp = new SortedDictionary <string, string> { { "service", Config.service }, { "partner", Config.partner }, { "seller_id", Config.seller_id }, { "_input_charset", Config.input_charset.ToLower() }, { "payment_type", Config.payment_type }, { "notify_url", Config.notify_url }, { "return_url", Config.return_url }, { "anti_phishing_key", Config.anti_phishing_key }, { "exter_invoke_ip", Config.exter_invoke_ip }, { "out_trade_no", orderNo }, { "subject", productName }, { "total_fee", amount.ToString("N2") }, { "body", string.Empty } }; //商户订单号,商户网站订单系统中唯一订单号,必填 //其他业务参数根据在线开发文档,添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1 //如sParaTemp.Add("参数名","参数值"); //建立请求 return(Submit.BuildRequestUrl(sParaTemp)); } var client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", config.AliPayAppId, config.AliPayPrivateKey, "JSON", "1.0", "RSA2", config.AliPayPublicKey, "utf-8", false); // 组装业务参数model var model = new AlipayTradePagePayModel { Body = string.Empty, Subject = productName, TotalAmount = amount.ToString("N2"), OutTradeNo = orderNo, TimeoutExpress = "90m", ProductCode = "FAST_INSTANT_TRADE_PAY" }; // 付款金额 // 外部订单号,商户网站订单系统中唯一的订单号 var request = new AlipayTradePagePayRequest(); // 设置同步回调地址 request.SetReturnUrl(returnUrl); // 设置异步通知接收地址 request.SetNotifyUrl(string.Empty); // 将业务model载入到request request.SetBizModel(model); var response = client.pageExecute(request, null, "GET"); return(response.Body); }
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); }
public PayValue OrderPay(PayValue payValue) { PayValue returnValue = new PayValue(); PayOrderModel payOrderModel = (PayOrderModel)payValue.ReturnObject; //备注 byte[] bytes = System.Text.Encoding.Default.GetBytes(payOrderModel.Note); string base64_memo = Convert.ToBase64String(bytes); StringBuilder sb = new StringBuilder(); sb.Append("user_id="); sb.Append(payOrderModel.Userid); sb.Append("&user_name="); sb.Append(payOrderModel.Receiver); sb.Append("&user_cert_type="); if (payOrderModel.PassPortType == 1) { sb.Append("00"); } else if (payOrderModel.PassPortType == 2) { sb.Append("02"); } else { sb.Append("99"); } sb.Append("&user_cert_no="); sb.Append(payOrderModel.PassPortNum); sb.Append("&user_mobile="); sb.Append(payOrderModel.Phone); byte[] userInfobytes = System.Text.Encoding.Default.GetBytes(sb.ToString()); String userInfoBase64 = Convert.ToBase64String(userInfobytes); //设置支付请求参数 SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>(); sParaTemp.Add("out_trade_no", payOrderModel.OrderId); //商家订单号 sParaTemp.Add("total_fee", payOrderModel.Totalfee.ToString("f2")); //商品金额,以元为单位 sParaTemp.Add("return_url", ConfigHelper.EReturnUrl); //交易完成后跳转的URL sParaTemp.Add("notify_url", ConfigHelper.ENotifyUrl); //接收后台通知的URL sParaTemp.Add("currency_type", payOrderModel.PayCurrencys.ToString()); //货币种类 sParaTemp.Add("order_create_ip", payOrderModel.Createip); //创建订单的客户端IP(消费者电脑公网IP,用于防钓鱼支付) sParaTemp.Add("sign_type", ConfigHelper.ESignType); //签名算法(暂时只支持SHA256) sParaTemp.Add("store_oi_type", StringUtils.ToInt(payOrderModel.Storeoitype, 1).ToString()); sParaTemp.Add("goods_amount", payOrderModel.OrderGoodsAmount.ToString("f2")); //支付货款 sParaTemp.Add("goods_amount_curr", payOrderModel.PayCurrencys.ToString()); //货币种类 sParaTemp.Add("tax_amount", payOrderModel.OrderTaxAmount.ToString("f2")); //支付税款 sParaTemp.Add("tax_amount_curr", payOrderModel.PayCurrencys.ToString()); //货币种类 sParaTemp.Add("freight", payOrderModel.OrderFreight.ToString("f2")); //支付运费 sParaTemp.Add("freight_curr", payOrderModel.PayCurrencys.ToString()); //货币种类 sParaTemp.Add("submission_type", "01"); sParaTemp.Add("base64_user_info", userInfoBase64); //用户信息 sParaTemp.Add("pay_id", payOrderModel.PayId); //可选参数 sParaTemp.Add("base64_memo", base64_memo); //订单备注的BASE64编码 //建立请求 string sHtmlText = Submit.BuildRequestUrl(sParaTemp); returnValue.HasError = false; returnValue.ReturnString = sHtmlText; return(returnValue); }