12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Threading.Tasks;
- using Alipay.AopSdk.Core;
- using Alipay.AopSdk.Core.Domain;
- using Alipay.AopSdk.Core.Request;
- using Newtonsoft.Json;
- namespace GxPress.Common.AliPay
- {
- public class PcPay
- {
- /// 发起支付请求
- /// </summary>
- /// <param name="tradeno">外部订单号,商户网站订单系统中唯一的订单号</param>
- /// <param name="subject">订单名称</param>
- /// <param name="totalAmout">付款金额</param>
- /// <param name="itemBody">商品描述</param>
- /// <param name="notifyUrl">设置异步通知接收地址</param>
- /// <returns></returns>
- public string PayRequest(string tradeno, string subject, string totalAmout, string itemBody, string notifyUrl)
- {
- DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
- Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);
- // 组装业务参数model
- AlipayTradePagePayModel model = new AlipayTradePagePayModel();
- model.Body = itemBody;
- model.Subject = subject;
- model.TotalAmount = totalAmout;
- model.OutTradeNo = tradeno;
- model.ProductCode = "FAST_INSTANT_TRADE_PAY";
- AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
- // 设置同步回调地址
- request.SetReturnUrl(notifyUrl);
- // 设置异步通知接收地址
- //request.SetNotifyUrl("http://payzzz.top/api/web/alipay/notify");
- request.SetNotifyUrl("https://apk.tederen.com/service/api/web/alipay/notify");
- // 将业务model载入到request
- request.SetBizModel(model);
- var response = client.SdkExecute(request);
- // Console.WriteLine($"订单支付发起成功,订单号:{tradeno}");
- //跳转支付宝支付
- return (Config.Gatewayurl + "?" + response.Body);
- }
- /// <summary>
- /// 订单退款
- /// </summary>
- /// <param name="tradeno">商户订单号</param>
- /// <param name="alipayTradeNo">支付宝交易号</param>
- /// <param name="refundAmount">退款金额</param>
- /// <param name="refundReason">退款原因</param>
- /// <param name="refundNo">退款单号</param>
- /// <returns></returns>
- public async Task<bool> Refund(string tradeno, string alipayTradeNo, string refundAmount, string refundReason, string refundNo)
- {
- DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
- Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);
- AlipayTradeRefundModel model = new AlipayTradeRefundModel();
- model.OutTradeNo = tradeno;
- model.TradeNo = alipayTradeNo;
- model.RefundAmount = refundAmount;
- model.RefundReason = refundReason;
- model.OutRequestNo = refundNo;
- AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
- request.SetBizModel(model);
- var response = await client.ExecuteAsync(request);
- var jsonModel = JsonConvert.DeserializeObject<dynamic>(response.Body);
- return true;
- }
- /// <summary>
- /// 关闭订单
- /// </summary>
- /// <param name="tradeno">商户订单号</param>
- /// <param name="alipayTradeNo">支付宝交易号</param>
- /// <returns></returns>
- public async Task<bool> OrderClose(string tradeno, string alipayTradeNo)
- {
- DefaultAopClient client = new DefaultAopClient(Config.Gatewayurl, Config.AppId, Config.PrivateKey, "json", "2.0",
- Config.SignType, Config.AlipayPublicKey, Config.CharSet, false);
- AlipayTradeCloseModel model = new AlipayTradeCloseModel();
- model.OutTradeNo = tradeno;
- model.TradeNo = alipayTradeNo;
- AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
- request.SetBizModel(model);
- var response = await client.ExecuteAsync(request);
- var jsonModel = JsonConvert.DeserializeObject<dynamic>(response.Body);
- return true;
- }
- }
- }
|