您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍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#如何实现支付宝新版支付请求接口调用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。