GithubHelp home page GithubHelp logo

dotnetcore / alipay.aopsdk.core Goto Github PK

View Code? Open in Web Editor NEW
782.0 60.0 224.0 4.36 MB

支付宝(Alipay)服务端SDK,采用.NET Standard 2.0,支持.NET Core >=2.0,与官方SDK接口完全相同。完全可以按照官方文档进行开发。除了支持支付以外,官方SDK支持的功能本SDK全部支持,比如生活号、服务窗、行业合作等,且用法几乎一样,代码都可参考官方文档代码。

License: MIT License

C# 100.00% Batchfile 0.01%
alipay alipay-sdk alipay-dotnetcore aopsdk

alipay.aopsdk.core's Introduction

Member project of .NET Core Community

说明:Alipay.AopSdk.Core 源起于 .NET Core 1.1 时期,当时的社区生态还不完善,很多组件都还没有迁移到 .NET Core ,当时有整好碰巧对接支付宝支付,所以基于支付宝官方的 Framework 的源码进行改造,进而诞生了 Alipay.AopSdk.Core,但随着时间的推移,支付宝业务的新增和变更,Alipay.AopSdk.Core 的更新速度远远比不上,而且官方也重构了 .NET SDK ,且配合官方文档以及代码生成器,现在使用十分方便,Alipay.AopSdk.Core 是时候退出舞台了。2020.9.16

Alipay.AopSdk.Core

一.各个组件说明

组件名 说明 版本号
Alipay.AopSdk.Core ASP.NET 项目可以单独安装此组件。服务端SDK,封装了支付宝开放平台的所有API Latest version
Alipay.AopSdk.AspnetCore ASP.NET Core 项目可以单独安装此组件。服务端SDK的ASP.NET Core组件,为了能更好配合ASP.NET Core 使用 Latest version

Alipay.AopSdk.F2FPay.AspnetCore、Alipay.AopSdk.F2FPay 在2.3版本已被合并。

支付宝(Alipay)服务端SDK,采用.NET Standard 2.0,支持.NET Core >= 2.0,与官方SDK接口完全相同。完全可以按照官方文档进行开发。除了支持支付以外,官方SDK支持的功能本SDK全部支持,且用法几乎一样,代码都可参考官方文档代码。。由于精力有限,所以只做了几个Demo,但是其他功能可以参照官方的Demo来使用。可以使用官方文档中的示例代码。如有问题请加QQ群4656606。

本项目代码基于官方.NET Framework 代码重构而来以及加入了ASP.NET Core的扩展支持。

二.ASP.NET Core 使用

1.安装程序包

Install-Package Install-Package Alipay.AopSdk.AspnetCore

2.添加配置

public void ConfigureServices(IServiceCollection services)
{
    services.AddAlipay(options =>
	        {
		        options.AlipayPublicKey = "支付宝公钥";
		        options.AppId = "应用ID";
		        options.CharSet = "密钥编码";
		        options.Gatewayurl = "支付网关";
		        options.PrivateKey = "商家私钥";
		        options.SignType = "签名方式 RSA/RSA2";
		        options.Uid = "商户ID";
	        });
}

3.在Controller中使用

//通过di注入
private readonly AlipayService  _alipayService;

public xxxController(AlipayService alipayService)
{
	_alipayService = alipayService;

}

_alipayService.Execute();

三.使用当面付(条码支付/扫描支付)

private readonly AlipayF2FService _alipayF2FService;

public xxxController(AlipayF2FService alipayF2FService)
{
	_alipayF2FService = alipayF2FService;

}

_alipayF2FService.Execute();

四.配置

1.快捷添加配置的方法

appsettings.json里添加如下信息

 "Alipay": {
    "AlipayPublicKey": "",
    "AppId": "",
    "CharSet": "UTF-8",
    "Gatewayurl": "https://openapi.alipaydev.com/gateway.do",
    "PrivateKey": "",
    "SignType": "RSA2",
    "Uid": ""
  }

添加配置代码可改为如下:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAlipay(Configuration.GetSection("Alipay"));
    
}

2.密钥生成的方法

解压tool文件夹下keygen.zip压缩包,运行start.bat即可在keys目录下生成公钥和私钥,长度为2048。

这里生成的公钥和私钥,只需将私钥配置到配置文件文件中,公钥需要设置到支付宝后台。然后设置SignTypeRSA2。配置文件中的公钥配置,不是我们自己生成的这个,需要到支付宝后台获取,这里需要注意一下。

1526457521967

五.文档信息

官方文档:

1.演示Demo

实现支付、支付同步回调、支付异步通知、订单查询、退款、退款查询、订单关闭、扫码支付功能

2.教程

3.使用问题集锦

常见问题解答

alipay.aopsdk.core's People

Contributors

alexinea avatar gaojunhuang avatar icebeans avatar kinosang avatar miyamuramiyako avatar stulzq avatar xland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alipay.aopsdk.core's Issues

Alipay.AopSdk.Core.Util.WebUtils throw an exception

at Alipay.AopSdk.Core.Util.WebUtils.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Alipay.AopSdk.Core.DefaultAopClient.d__621.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Alipay.AopSdk.Core.DefaultAopClient.<>c__DisplayClass61_01.<b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task1 task) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException[TResult](Task1 task) at Nito.AsyncEx.AsyncContext.Run[TResult](Func1 action) at

签名验证不通过

参考官方文档写的net framework的,签名验证正常。
最近有个新项目尝试使用net core ,在使用时用到支付,也是参考官方文档写的,签名不通过。
代码拷到老项目里(使用官方的sdk),却能运行。

验签不通过

请问RSA2加密方式验证签名使用的是AlipaySignature.RSACheckV2这个方法吗?我用的是“Alipay.AopSdk.AspnetCore" Version="2.4.2” 但是提示不通过,请问有Demo可以参考下吗?

更新到2.5.1之后,当面付不显示二维码了

AlipayTradePrecreateResponse,之前一直用这个,往IAopClient接口传和接收QrCode,之前一直好好的,昨天更新了2.5.1之后,突然二维码获取失败了,调试发现QrCode为NULL,值都在Body里,
{"alipay_trade_precreate_response":{"code":"10000","msg":"Success","out_trade_no":"15774603888461368xxxxxxxx","qr_code":"https:\/\/qr.alipay.com\/bax096xxxxxxxxxxxxxxx"},"sign":"LOLDxxxxxxxxxxxxxxxxxx=="}
大概是这样的一个返回结果,都在response.Body里,response.QrCode为空。可能是序列化失败了吧。
我们可以自己再单独序列化,但感觉像是升级的bug,之前一直好好的,退回2.5.0就可以了。

.Net core 3.1

希望排查一下问题,谢谢

Question: Does this SDK supports alipay on mobile browsers?

Question: Does this SDK supports alipay on mobile browsers?

Hi, it seems that there was another way to page on the web page except paying on PC. It was named 'Pay on mobile browsers'. The official document is here.

So I have a question: does this amazing SDK supports 'Pay on mobile browsers? Thanks!


问:此SDK是否支持移动浏览器上的支付宝?

嗨,似乎除了在PC上付款外,还有另一种方法可以在网页上进行寻呼。 它被命名为“在移动浏览器上付费”。 官方文件是这里

所以我有一个问题:这个美妙的SDK是否支持'在移动浏览器上付费? 谢谢!

手机网站支付(WapPay)以Get方式获取地址出现Json解析异常

var client = new DefaultAopClient( ... );
var request = new AlipayTradeWapPayRequest();
var response = client.PageExecute(request, null, "GET"); 默认POST表单提交的方式没问题

当走到 AopJsonParser.Parse(body, charset); 里进行解析时,body 的内容是 https://openapi.alipay.com/gateway.do?app_id=xxx... ,接下来
if (!body.StartsWith("<form"))
{
json=JsonConvert.DeserializeObject(body); 这一句会报错
}

将判断条件改为 !body.StartsWith("<form") && !body.StartsWith("http") 就可以了

如何根据需要动态切换支付宝商户号而不是在配置中固定死一个商户号

  • 有些不同的业务分别开设了一个支付宝商户号,程序需要根据支付时的业务切换用户面向支付的商户,最终才发起用户支付。这个多商户号切换需求,可以满足按业务区分的资金管理。
  • 再有就是统一支付平台类型的项目,需要根据其他各个接入应用,分别采用对于的支付商户号来发起支付,或者完成其他资金业务。统一支付平台其中也分微信支付、其他银联支付,但在支付宝支付中,也要进行支付宝不太商户号的动态切换。

总的来说,动态切换支付宝商户号,这个功能还是需求挺大的,而且这个切换功能挺有意思。

在centos 服务器下 httpclient 会有ssl问题

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation

在WebUtilsHttpConnectionPool 修改方法 public HttpClient GetClient()
{
if (_clients.TryPop(out var client))
{
return client;
}
//解决Linux 下ssl 异常问题
//System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation
var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true
};

        var newClient = new HttpClient(httpClientHandler)

            { BaseAddress = new Uri(_url), Timeout = TimeSpan.FromMilliseconds(_timeout) };
        newClient.DefaultRequestHeaders.Add("User-Agent", "Aop4Net");
        newClient.DefaultRequestHeaders.Add("Connection", "keep-alive");
            
        return newClient;
    }

Options 的动态实例化问题

https://github.com/stulzq/Alipay.AopSdk.Core/blob/d13ea9c3a63d820f3cb2f7ba0a8de356490bcb93/Alipay.AopSdk.AspnetCore/AlipayService.cs#L19

使用的时候,按如下配置:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAlipay(options =>
	        {
		        options.AlipayPublicKey = "支付宝公钥";
		        options.AppId = "应用ID";
		        options.CharSet = "密钥编码";
		        options.Gatewayurl = "支付网关";
		        options.PrivateKey = "商家私钥";
		        options.SignType = "签名方式 RSA/RSA2";
		        options.Uid = "商户ID";
	        }).AddAlipayF2F();
}

但这样的话,在实例化AlipayService的时候,Options只会实例化一次,如何可以动态实例化这个Option?
如果修改代码的话,可以按如下修改

IOptions<AlipayOptions> 改为 IOptionsSnapshot<AlipayOptions>

是否可以提供别的方式呢?

配置参数读数据库的问题

负载均衡的场景下,参数读配置文件的话,修改起来就比较麻烦,需要修改多处,希望能够提供参数读数据库的功能和使用示例,谢谢,感谢开源

web api 并发中调用aliapy的接口,20线程压测 导致 IIS崩溃,原因是底层使用的HttpWebRequest

在framework中,大量并发 HttpWebRequest 需要设置一个最大连接数,但是在.net core中却无效,因为core不使用 ServicePointManager 管理连接数,在core中只有使用HttpClient,HttpCilentFactory来管理HttpClient,如果在core中使用 ServicePointManager 不但不起作用,并且大量并发使用 HttpWebRequest 会导致 IIS 直接假死,希望把SDK 源码中 WebUtils 这个工具类改为 HttpCilent + HttpCilentFactory 的模式,不然并发有很大问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.