Pay achieve treasure AopSdk in dotnet core of

As the project moved to the next dotnet core, Ali Alipay is also required as the project migration. Before use in the .Net Framework AopSdk and F2FPay two assemblies Ali offered to pay only the official support Framework treasure, though, it provides a download source.

In the idea of ​​non-repetition-create the wheel, first NuGet search the next, there have been numerous realized, carefully compare the next, chose AliPay.AopSdk.Core. The main reason is the open-source git, then there is the use of people will be more.

AliPay.AopSdk.Core project itself is very good, basically exactly the same with Ali official Sdk, mainly to change some of naming non-standard methods. Soon modifications are complete, simple test the next on the last line, but did not want to leave the pit.

On-line soon, all users can not pay. Log server (CentOS 7) reported abnormalities Too many open files in system, amount, check under the first look.

ps -ef | grep dotnet find pid services, here is 14689

cat / proc / 14689 / limits look restriction system

Max open files 4096 saying it has a lot of

lsof -p 14689 | wc -l statistics were open next number, look, Howard, quite a few buses full of

lsof -p 14689 are what look, found a large number of undestroyed TCP link

Compare IP watching familiar, it seems to be Ali, the service domain openapi.alipay.com paid under ping, ah, that's it, so far to locate the problem.

Under the first emergency treatment to restart the service paid for, and then do the next configuration, the Max open files magnified more. Because my service is systemctl management, so only you need to configure xxx.service like.

In the [Service] configuration add a line below

LimitNOFILE = 10240

After restarting the service, to get re-pid, look limits, ah, come into force

Before carrying case, and then to analyze the problem.

Glad that they chose the open source project, it is easy to look at the code.

这两句,作者实现了池,导致的。然后才回头开始看项目的文档,使用说明中用DI注入了一个IAopClient的单例,额,我是每次new出来的,所以xxxxxxxx。

至此似乎解决了,但完全没有。这个项目单例注入,已经固定了支付宝的商户号等参数,但我实际的业务需要多个支付宝账户,每次根据取到商户号来赋值。

处理思路:

本来想做个工厂,自己实现个单例,根据不同的商户号返回不同IAopClient的实现实例。仔细一想以为商户比较多,仍然存在大量的不必要的链接。最后决定,自己拿阿里的源码,改个core的版本吧。还是重复造轮子了。说干就干,先下个最新的源码,我这里是alipay-sdk-net-core-3.2.0,新建个dotnet core的Library,把需要的文件copy进来(主要是去掉了Test目录),编译下,报错。源码中包含了Jayrock,用来处理JSON,git上看了下,好老的项目,已经停止更新了,不知道为什么阿里还在用。不过还好NuGet装下System.Configuration.ConfigurationManager就一切ok了。还有些warning暂时没有理会。本机测试下(windows 10),一切OK。放到测试服务器(CentOS 7)上测试下,额,报错“您使用的私钥格式错误,请检查RSA私钥配置,charset = utf-8“,这是什么鬼。看看源码,不知所踪。这下比较麻烦了,本机没问题,远程测试环境不行,目测肯定是系统的差异了。脑子里蹦出来的办法--远程调试。嗯,没错,就这么弄(具体远程调试另一篇文档)。最后发现,果然是操作系统的差异,RSACryptoServiceProvider这个类,只支持windows系统。找到问题就好办了,替换掉。具体实现嘛懒了懒,直接拿的Alipay.AopSdk.Core项目中的实现。publish一个版本,到测试服务器上,嗯,问题解决。

 

 非常感谢Alipay.AopSdk.Core项目作者,源码提供了很大的帮助。

 

 参考资料:

https://github.com/dotnetcore/Alipay.AopSdk.Core

 

Guess you like

Origin www.cnblogs.com/draweye/p/11080978.html