C#支付宝接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using Aop.Api;
using Aop.Api.Response;
using Aop.Api.Request;
using Aop.Api.Domain;

namespace zfb.Controllers
{
public class YYLController : Controller
{

static string URL = ConfigurationManager.AppSettings["url"];//沙箱支付宝网关
static string APP_ID = ConfigurationManager.AppSettings["appid"];//APPID
static string APP_PRIVATE_KEY = ConfigurationManager.AppSettings["APP_PRIVATE_KEY"];//私钥
static string ALIPAY_PUBLIC_KEY = ConfigurationManager.AppSettings["ALIPAY_PUBLIC_KEY"];//公钥
static string AliPayReturn_url = ConfigurationManager.AppSettings["AliPayReturn_url"];//回调
// GET: YYL
public ActionResult Index()
{
aaa();
return View();
}

[HttpPost]
public void aaa()
{
DefaultAopClient client = new DefaultAopClient(URL, APP_ID, APP_PRIVATE_KEY, "json", "1.0", "RSA2", ALIPAY_PUBLIC_KEY, "utf-8", false);

// 外部订单号,商户网站订单系统中唯一的订单号
string out_trade_no = DateTime.Now.ToString("yyyyMMddHHmmss");

// 订单名称
string subject = "我靠";

// 付款金额
string total_amout = "0.01";

// 商品描述
string body = "12321345645";

// 组装业务参数model
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
model.Body = body;
model.Subject = subject;
model.TotalAmount = total_amout;
model.OutTradeNo = out_trade_no;
model.ProductCode = "FAST_INSTANT_TRADE_PAY";

AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
// 设置同步回调地址
request.SetReturnUrl(AliPayReturn_url);
// 设置异步通知接收地址
request.SetNotifyUrl("");
// 将业务model载入到request
request.SetBizModel(model);

AlipayTradePagePayResponse response = null;
try
{
response = client.pageExecute(request, null, "post");
Response.Write(response.Body);
}
catch (Exception exp)
{
throw exp;
}
}///上面的代码可以在sdk源码中的pagepay文件夹下的pagepay.aspx.cs找到
}
}

转载于:https://www.cnblogs.com/luchaobooks/p/10953975.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值