支付宝当面付AopSdk,兼容.net core 附源码

实现Helper

using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Alipay
{
    /// <summary>
    /// 支付宝支付类
    /// </summary>
    public class AliPay
    {
        private static readonly string AppId = MyConfigs.GetConfig("AppId");
        private static readonly string AppPrivateKey = MyConfigs.GetConfig("PrivateKey");
        private static readonly string AliPublicKey = MyConfigs.GetConfig("AliPublicKey");
        private static readonly string NotifyUrl = MyConfigs.GetConfig("NotifyUrl");

        public const string Gateway = "https://openapi.alipay.com/gateway.do";
        public const string Format = "json";
        public const string Version = "1.0";
        public const string SignType = "RSA2";
        public const string Charset = "utf-8";
        public const string ProductCode = "QUICK_MSECURITY_PAY";
        
        static IAopClient aopClient = new DefaultAopClient(Gateway, AppId, AppPrivateKey, Format, Version, SignType, AliPublicKey, Charset, false);


        /// <summary>
        /// 获取扫码支付的二维码图片链接
        /// </summary>
        /// <param name="orderNo">商户订单号,64个字符以内、只能包含字母、数字、下划线;需保证在商户端不重复</param>
        /// <param name="amount">订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000] 如果同时传入了【打折金额】,【不可打折金额】,【订单总金额】三者,则必须满足如下条件:【订单总金额】=【打折金额】+【不可打折金额】</param>
        /// <param name="subject">订单标题</param>
        /// <param name="body">商品描述信息</param>
        /// <param name="storeId">商户门店编号</param>
        /// <returns></returns>
        public string GetQrCodeUrl(string orderNo, decimal amount, string subject, string body, string storeId)
        {
            string link = string.Empty;

            //组装业务参数
            var model = new AlipayTradePrecreateModel()
            {
                Body = body,
                Subject = subject,
                TotalAmount = amount.ToString(),
                OutTradeNo = orderNo,
                StoreId = storeId //商户门店编号
            };

            var request = new AlipayTradePrecreateRequest();
            request.SetBizModel(model);
            request.SetNotifyUrl(NotifyUrl);

            AlipayTradePrecreateResponse response = aopClient.Execute(request);
            if (response != null && response.Code == "10000")
            {
                link = response.QrCode;
            }
            return link;
        }

        /// <summary>
        /// 申请退款
        /// </summary>
        public bool ApplyRefund(string orderNo, decimal refundAmount, string refundNo = null, string reason = null, string tradeNo = null)
        {
            bool success = false;

            //组装业务参数
            var model = new AlipayTradeRefundModel()
            {
                OutTradeNo = orderNo,
                TradeNo = tradeNo,
                RefundAmount = refundAmount.ToString(),
                OutRequestNo = refundNo, //退款单号,同一笔多次退款需要保证唯一,部分退款该参数必填。
                RefundReason = reason
            };

            var request = new AlipayTradeRefundRequest();
            request.SetBizModel(model);
            AlipayTradeRefundResponse response = aopClient.Execute(request);
            if (response != null && response.Code == "10000")
            {
                success = true;
            }
            return success;
        }
    }
}

 

源码地址:https://github.com/BigMaJx/OOPDemo/blob/master/Common/Alipay/AliPay.cs

aopSdk源码地址:https://opendocs.alipay.com/open/54/104506

Alipay SDK for .NET Git: https://github.com/alipay/alipay-sdk-net-all

实际上就是把支付宝的源码拿下来,然后改了一下 rsa。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值