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;
            }
        }



  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YuanlongWang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值