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



猜你喜欢

转载自blog.csdn.net/lwpoor123/article/details/79019427
今日推荐