姓名:尤學(xué)強(qiáng) 學(xué)號:17101223374
轉(zhuǎn)載自:http://mp.weixin.qq.com/s/qcee0hztkBMSdROPrHY4dQ
【嵌牛導(dǎo)讀】:支付軟件
【嵌牛鼻子】:支付軟件
【嵌牛提問】:支付軟件怎樣能更廣泛?
【嵌牛正文】:
ICanPay是一個支持多商戶多種支付方式的跨平臺網(wǎng)關(guān)處理類庫宰僧,使用ICanPay可以簡化訂單的創(chuàng)建亿扁、查詢勾邦、退款和接收網(wǎng)關(guān)返回的支付通知等操作序六。
目前支持的支付網(wǎng)關(guān)有:支付寶(Alipay)糕非、微信支付(Wechatpay)跃须、銀聯(lián)支付(Unionpay)
下面以支付寶為例站叼,其余兩種支付,請參考Wiki(https://github.com/Varorbc/ICanPay/wiki)
一回怜、配置商戶數(shù)據(jù)
1大年、在Startup中添加商戶數(shù)據(jù)
services.AddICanPay(a =>
{
var gateways = new Gateways();
var merchant = new Merchant
{
AppId = "",
NotifyUrl = "",
ReturnUrl = "",
AlipayPublicKey = "",
Privatekey = ""
};
gateways.Add(new AlipayGateway(merchant));
return gateways;
});
2换薄、在Startup中使用ICanPay
app.UseICanPay();
以上就簡單的完成了對ICanPay的配置操作
二、支付
ICanPay支持多種支付方式翔试,下面就來講解如何使用
1轻要、獲取支付網(wǎng)關(guān)
private readonly IGateways gateways;
public YourController(IGateways gateways)
{
this.gateways = gateways;
}
2、創(chuàng)建訂單
var order = new Order()
{
Amount = 0.01,
OutTradeNo = "訂單號",
Subject = "測試",
};
3垦缅、設(shè)置支付方式
var gateway = gateways.Get(GatewayTradeType.Web);
4冲泥、支付
gateway.Payment(order);
特殊說明:GatewayTradeType.Barcode支付方式,需要再實現(xiàn)PaymentSucceed和PaymentFailed事件
三壁涎、異步通知
1凡恍、獲取支付網(wǎng)關(guān)
private readonly IGateways gateways;
public NotifyController(IGateways gateways)
{
this.gateways = gateways;
}
2、實現(xiàn)支付通知事件
PaymentNotify notify = new PaymentNotify(gateways);
notify.PaymentSucceed += Notify_PaymentSucceed;
notify.PaymentFailed += Notify_PaymentFailed;
notify.UnknownGateway += Notify_UnknownGateway;
private void Notify_PaymentSucceed(object sender, PaymentSucceedEventArgs e)
{
// 支付成功時時的處理代碼
/* 建議添加以下校驗怔球。
* 1嚼酝、需要驗證該通知數(shù)據(jù)中的OutTradeNo是否為商戶系統(tǒng)中創(chuàng)建的訂單號,
* 2竟坛、判斷Amount是否確實為該訂單的實際金額(即商戶訂單創(chuàng)建時的金額)闽巩,
*/
if (e.GatewayType == typeof(AlipayGateway))
{
var notify = (Notify)e.Notify;
}
}
private void Notify_PaymentFailed(object sender, PaymentFailedEventArgs e)
{
// 支付失敗時的處理代碼
}
private void Notify_UnknownGateway(object sender, UnknownGatewayEventArgs e)
{
// 無法識別支付網(wǎng)關(guān)時的處理代碼
}
3、接收支付通知
await notify.ReceivedAsync();
四担汤、輔助接口
1涎跨、查詢
var notify = (Notify)gateway.Query(new Auxiliary
{
OutTradeNo = "訂單號"
});
2、撤銷
var notify = (Notify)gateway.Cancel(new Auxiliary
{
OutTradeNo = "訂單號"
});
3崭歧、關(guān)閉
var notify = (Notify)gateway.Close(new Auxiliary
{
OutTradeNo = "訂單號"
});
4隅很、退款
var notify = (Notify)gateway.Refund(new Auxiliary
{
OutTradeNo = "訂單號",
RefundAmount = 123,
OutRefundNo = "退款單號"
});
5率碾、退款查詢
var notify = (Notify)gateway.RefundQuery(new Auxiliary
{
OutTradeNo = "訂單號"叔营,
OutRefundNo = "退款單號"
});
6、對賬單下載
gateway.BillDownload(new Auxiliary
{
BillType = "trade",
BillDate = "2017-10-31"
});
以上就簡單的講解了如何使用ICanPay,如果有什么問題播掷,也可以在Github上提問审编。
項目地址:ICanPay(https://github.com/Varorbc/ICanPay)
來源:Varorbc
cnblogs.com/varorbc/p/7890331.html
經(jīng)過6年多的發(fā)展,LSGO軟件技術(shù)團(tuán)隊在地理信息系統(tǒng)歧匈、數(shù)據(jù)統(tǒng)計分析垒酬、計算機(jī)視覺領(lǐng)域積累了豐富的研發(fā)經(jīng)驗,也建立了人才培養(yǎng)的完備體系件炉。
歡迎對算法設(shè)計與實現(xiàn)感興趣的同學(xué)加入勘究,與我們共同成長進(jìn)步。
本微信公眾平臺長期系統(tǒng)化提供有關(guān)機(jī)器學(xué)習(xí)斟冕、軟件研發(fā)口糕、教育及學(xué)習(xí)方法、數(shù)學(xué)建模的知識磕蛇,并將以上知識轉(zhuǎn)化為實踐景描。拒絕知識碎片化十办、耐心打磨技能、解決實際問題是我們的宗旨和追求超棺。