这篇文章主要为大家详细介绍了C#支付宝新版支付请求接口调用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了C#支付宝新版支付请求接口调用的具体代码,供大家参考,具体内容如下
因为支付宝已经集成了完整的SDK,所以可以使用SDK直接调用API,这里获取SDK源码。
首先我们需要引用支付宝SDK集成 AopSdk.dll。
添加相关引用:
using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
需要用到商户私钥,支付宝公钥,请求地址等公共参数,所以可以新建一个config文件:
public class newalipayconfig
{
public newalipayconfig()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
// 应用ID,您的APPID
public static string app_id = "";
// 支付宝网关
public static string gatewayUrl = "https://openapi.alipay.com/gateway.do";
// 支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
public static string alipay_public_key = "";
// 商户私钥,您的原始格式RSA私钥
public static string private_key = "";
// 签名方式
public static string sign_type = "RSA2";
// 编码格式
public static string charset = "UTF-8";
}
支付请求处理页面:
DefaultAopClient client = new DefaultAopClient(newalipayconfig.gatewayUrl, newalipayconfig.app_id, newalipayconfig.private_key, "json", version, newalipayconfig.sign_type, newalipayconfig.alipay_public_key, newalipayconfig.charset, false);
if (order != null)
{
// 支付中途退出返回商户网站地址
string quit_url = "www.alipay.com";
// 组装业务参数model
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.Body = body; //商品描述
model.Subject = subject; //商品名称
model.TotalAmount = total_amount; ////订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]
model.OutTradeNo = out_trade_no; //商户网站唯一订单号
model.ProductCode = "QUICK_WAP_WAY";//销售产品码,商家和支付宝签约的产品码。
model.QuitUrl = quit_url;
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
// 设置支付完成同步回调地址
request.SetReturnUrl(AlipayConfig.Call_back_url);
// 设置支付完成异步通知接收地址
request.SetNotifyUrl(AlipayConfig.Notify_url);
// 将业务model载入到request
request.SetBizModel(model);
AlipayTradeWapPayResponse response = null;
try
{
response = client.pageExecute(request, null, "post");
Response.Write(response.Body);
}
catch (Exception exp)
{
throw exp;
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:C#支付宝新版支付请求接口调用


猜你喜欢
- c# 模拟线性回归的示例 2023-03-14
- user32.dll 函数说明小结 2022-12-26
- Unity Shader实现模糊效果 2023-04-27
- Oracle中for循环的使用方法 2023-07-04
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- Unity3D实现渐变颜色效果 2023-01-16
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- .NET CORE DI 依赖注入 2023-09-27
- 如何使用C# 捕获进程输出 2023-03-10