-
Notifications
You must be signed in to change notification settings - Fork 265
/
AlipayGatewayTest.cs
245 lines (209 loc) · 8.89 KB
/
AlipayGatewayTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using System;
using PaySharp.Alipay;
using PaySharp.Alipay.Domain;
using PaySharp.Alipay.Request;
using PaySharp.Core.Response;
using PaySharp.Core.Utils;
using Xunit;
using Xunit.Abstractions;
namespace PaySharp.UnitTest
{
public class AlipayGatewayTest
{
private readonly ITestOutputHelper _output;
private readonly AlipayGateway _alipayGateway;
private readonly Merchant _merchant;
private string _outTradeNo => DateTime.Now.ToString("yyyyMMddhhmmss");
private string _outRefundNo => DateTime.Now.ToString("yyyyMMddhhmmss");
public AlipayGatewayTest(ITestOutputHelper output)
{
_output = output;
_merchant = new Merchant
{
AppId = "2016081600256163",
NotifyUrl = "http://localhost:61337/Notify",
ReturnUrl = "http://localhost:61337/Return",
AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsW6+mN2E3Oji2DPjSKuYgRzK6MlH9q6W0iM0Yk3R0qbp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isbXoGoyMK6XaSypBMRKe2y8yRv4c+w00rcKHtGfRjzSJ5NQO0Tv+q8vKY+cd6BuJ6OUQw82ICLANIfHJZNxtvtTCmmqBwSJDpcQJQXmKXTECgYEA2SQCSBWZZONkvhdJ15K+4IHP2HRbYWi+C1OvKzUiK5bdJm77zia4yJEJo5Y/sY3mV3OK0Bgb7IAaxL3i0oH+WNTwbNoGpMlYHKuj4x1453ITyjOwPNj6g27FG1YSIDzhB6ZC4dBlkehi/7gIlIiQt1wkIZ+ltOqgI5IqIdXoSHECgYB3zCiHYt4oC1+UW7e/hCrVNUbHDRkaAygSGkEB5/9QvU5tK0QUsrmJcPihj/RUK9YW5UK7b0qbwWWsr/dFpLEUi8GWvdkSKuLprQxbrDN44O96Q5Z96Vld9WV4DtJkhs4bdWNsMQFzf4I7D9PuKeJfcvqRjaztz6nNFFSqcrqkkQKBgQCJKlUCohpG/9notp9fvQQ0n+viyQXcj6TVVOSnf6X5MRC8MYmBHTbHA8+59bSAfanO/l7muwQQro+6TlUVMyaviLvjlwpxV/sACXC6jCiO06IqreIbXdlJ41RBw2op0Ss5gM5pBRLUS58V+HP7GBWKrnrofofXtAq6zZ8txok4EQKBgQCXrTeGMs7ECfehLz64qZtPkiQbNwupg938Z40Qru/G1GR9u0kmN7ibTyYauI6NNVHGEZa373EBEkacfN+kkkLQMs1tj5Zrlw+iITm+ad/irpXQZS/NHCcrg6h82vu0LcgiKnHKlmW6K5ne0w4LqmsmRCm7JdJjt9WlapAs0ticiw=="
};
_alipayGateway = new AlipayGateway(_merchant)
{
GatewayUrl = "https://openapi.alipaydev.com"
};
}
[Fact]
public void TestWebPay()
{
var request = new WebPayRequest();
request.AddGatewayData(new WebPayModel()
{
TotalAmount = 1,
Subject = "支付宝电脑网站支付测试",
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
_output.WriteLine(response.Html);
Assert.NotNull(response.Html);
}
[Fact]
public void TestWapPay()
{
var request = new WapPayRequest();
request.AddGatewayData(new WapPayModel()
{
TotalAmount = 1,
Subject = "支付宝手机网站支付测试",
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
_output.WriteLine(response.Url);
var result = HttpUtil.Get(response.Url);
Assert.Contains("支付宝", result);
}
[Fact]
public void TestAppPay()
{
var request = new AppPayRequest();
request.AddGatewayData(new AppPayModel()
{
TotalAmount = 1,
Subject = "支付宝手机APP支付测试",
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
_output.WriteLine(response.OrderInfo);
Assert.NotNull(response.OrderInfo);
}
[Fact]
public void TestBarcodePay()
{
var request = new BarcodePayRequest();
request.AddGatewayData(new BarcodePayModel()
{
TotalAmount = 1,
Subject = "支付宝条码支付测试",
OutTradeNo = _outTradeNo,
AuthCode = "123"
});
request.PaySucceed += BarcodePay_PaySucceed;
request.PayFailed += BarcodePay_PayFaild;
var response = _alipayGateway.Execute(request);
Assert.Equal("40004", response.Code);
}
private void BarcodePay_PaySucceed(IResponse response, string message)
{
}
private void BarcodePay_PayFaild(IResponse response, string message)
{
}
[Fact]
public void TestScanPay()
{
var request = new ScanPayRequest();
request.AddGatewayData(new ScanPayModel()
{
TotalAmount = 1,
Subject = "支付宝扫码支付测试",
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
_output.WriteLine(response.QrCode);
Assert.NotNull(response.QrCode);
}
[Fact]
public void TestQuery()
{
var request = new QueryRequest();
request.AddGatewayData(new QueryModel()
{
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
Assert.Equal("40004", response.Code);
}
[Fact]
public void TestCancel()
{
var request = new CancelRequest();
request.AddGatewayData(new CancelModel()
{
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
Assert.Equal("10000", response.Code);
}
[Fact]
public void TestClose()
{
var request = new CloseRequest();
request.AddGatewayData(new CloseModel()
{
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
Assert.Equal("40004", response.Code);
}
[Fact]
public void TestRefund()
{
var request = new RefundRequest();
request.AddGatewayData(new RefundModel()
{
OutTradeNo = _outTradeNo,
RefundAmount = 1,
OutRefundNo = _outRefundNo
});
var response = _alipayGateway.Execute(request);
Assert.Equal("40004", response.Code);
}
[Fact]
public void TestRefundQuery()
{
var request = new RefundQueryRequest();
request.AddGatewayData(new RefundQueryModel()
{
OutTradeNo = _outTradeNo,
OutRefundNo = _outRefundNo
});
var response = _alipayGateway.Execute(request);
Assert.Equal("40004", response.Code);
}
[Fact]
public void TestTransfer()
{
var request = new TransferRequest();
request.AddGatewayData(new TransferModel()
{
OutTradeNo = _outTradeNo,
PayeeAccount = "[email protected]",
Amount = 1,
PayeeType = "ALIPAY_LOGONID"
});
var response = _alipayGateway.Execute(request);
Assert.Equal("10000", response.Code);
}
[Fact]
public void TestTransferQuery()
{
var request = new TransferQueryRequest();
request.AddGatewayData(new TransferQueryModel()
{
OutTradeNo = _outTradeNo
});
var response = _alipayGateway.Execute(request);
Assert.Equal("40004", response.Code);
}
[Fact]
public void TestBillDownload()
{
var request = new BillDownloadRequest();
request.AddGatewayData(new BillDownloadModel()
{
BillDate = "2018-04-09",
BillType = "trade"
});
var response = _alipayGateway.Execute(request);
Assert.True(response.GetBillFile().Length > 0);
}
}
}