1.先到沙箱支付宝上注册一个沙箱支付宝账号(网上有很多教程我就不写啦~)
2.进入下载demo 链接:/open/270/106291
3.上面两个过程完成后我们开始玩一个小小的案例
先进入VS新建一个项目,建好后导入下好的Demo文件进去(解决方案--右键--添加现有项目)
4.添加完后做一个简单的前台页面
<body>
<form id="form1" runat="server">
<div>
<h2>支付宝支付</h2>
<label>订单:</label><asp:TextBox ID="TxtN" runat="server"></asp:TextBox>
<br />
<label>金额:</label><asp:TextBox ID="TxtP" runat="server"></asp:TextBox>
<br />
<label>描述:</label><asp:TextBox ID="TxtM" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="付款" OnClick="DJ" />
</div>
</form>
</body>
</html>
5.然后我们打开我们下载的Demo在里面找到config.cs这个类把它拖入到项目中(直接拖到项目中就行)
6.然后我们点击config.cs类进入
7.填写我们注册的id,私钥,密钥在沙箱支付宝官网的沙箱应用中可以看到(一定要填写自己的,自己的,自己的重要的事说三遍)
8.修改完后我们点击按钮进入后台(代码在下载的Demo文件里也有,在pagepay--pagepay页面的后台代码)
using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DJ(object sender, EventArgs e)
{
DefaultAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", config.sign_type, config.alipay_public_key, config.charset, false);
string WIDout_trade_no = "1";//待会要测试的订单编号,一次只能一个编号
// 外部订单号,商户网站订单系统中唯一的订单号
string out_trade_no = WIDout_trade_no.Trim();
// 名称
string subject = TxtN.Text.Trim();
// 金额
string total_amount = TxtP.Text.Trim();
// 商品描述
string body = TxtM.Text.Trim();
// 组装业务参数model
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
model.Body = body;
model.Subject = subject;
model.TotalAmount = total_amount;
model.OutTradeNo = out_trade_no;
model.ProductCode = "FAST_INSTANT_TRADE_PAY";
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
// 设置同步回调地址
request.SetReturnUrl("");
// 设置异步通知接收地址
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;
}
}
}
}
代码就是 protected void DJ(object sender, EventArgs e)这一段,如果显示有未能引用的命名空间反向引用就OK了接下来就是代码测试了(建议使用谷歌和火狐运行项目)