C# 当指向我的证书文件时,Paypal API会崩溃
我正在尝试使用Paypal API记录一些付款,在代码行中将CertificateFile属性设置为证书文件的位置时,我遇到了一个致命的异常 相关代码如下:C# 当指向我的证书文件时,Paypal API会崩溃,c#,paypal,C#,Paypal,我正在尝试使用Paypal API记录一些付款,在代码行中将CertificateFile属性设置为证书文件的位置时,我遇到了一个致命的异常 相关代码如下: using com.paypal.sdk.profiles; using com.paypal.sdk.services; using com.paypal.sdk.util; IAPIProfile profile = ProfileFactory.createSignatureAPIProfile(); profile.Certifi
using com.paypal.sdk.profiles;
using com.paypal.sdk.services;
using com.paypal.sdk.util;
IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
profile.CertificateFile = @"~\MyTestCertificate.txt";
深入到异常细节并没有给我更多的信息,它或多或少只是确认确实抛出了一个致命的异常
像这样省略波浪线和反斜杠会引发相同的错误:
profile.CertificateFile = @"MyTestCertificate.txt";
profile.CertificateFile = new StreamReader(@"MyTestCertificate.txt").ReadToEnd().ToString();
我想我可能需要文件的内容,而不是位置,所以我尝试了以下方法,但得到了相同的错误:
profile.CertificateFile = @"MyTestCertificate.txt";
profile.CertificateFile = new StreamReader(@"MyTestCertificate.txt").ReadToEnd().ToString();
似乎无论您将CertificateFile属性设置为什么,都会得到一个致命的异常
有几个问题:
CertificateFile
属性的文档MyTestCertificate.txt
被添加到我的解决方案中,并且Copy to Output Directory
被设置为Copy Always
例外案文如下:
{“引发了类型为'com.paypal.sdk.exceptions.FatalException'的异常。”}
StackTrace如下所示:
at com.paypal.sdk.profiles.SignatureAPIProfile.set_CertificateFile(String value)
at MyProject_Payment_Processing.Paypal.DoCaptureCode(String authorization_id, String amount) in C:\Users\JMK\documents\visual studio 2010\Projects\MyProject Payment Processing\MyProject Payment Processing\Paypal.cs:line 16
at MyProject_Payment_Processing.Program.Main(String[] args) in C:\Users\JMK\documents\visual studio 2010\Projects\MyProject Payment Processing\MyProject Payment Processing\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Paypal API使用Log4Net记录错误,如下所示:
2012年7月20日12:39:11致命[脂肪异常]
com.paypal.sdk.exceptions.FatalException:引发了类型为“com.paypal.sdk.exceptions.FatalException”的异常
谢谢您必须在Microsoft system store中安装您的证书。SDK中的自述文件解释了如何使用WinHttpCertCfg工具进行注册。事实证明aydiv是正确的,我必须使用
WinHttpCertCfg
注册证书。Martin还说得对,我使用的是签名配置文件,而不是证书配置文件
我必须做的第一件事是使用OpenSSL加密我的证书,使用以下命令。我必须在这里输入一个密码,这是我后来使用的。这创建了一个名为paypal\u cert.p12
的加密证书文件:
openssl pkcs12-导出-输入MyTestCertificate.txt-输入MyTestCertificate.txt-输出paypal_cert.p12
然后,我安装了WinHttpCertCfg
,并使用以下命令注册我的证书,用PFXPassword
替换我先前输入的密码:
winhttpcertcfg-i PFXFile-c LOCAL_MACHINE\My-a JMK-p PFXPassword
另外,我以前使用的是NVP DLL文件,我需要使用来自的SOAP DLL。这意味着我必须将代码中的NVPCallerServices
替换为Callerservices
,以及其他一些东西
下面是我在C#.Net中执行Paypal DoCapture的最后一段代码,希望这能帮助将来遇到这个问题的人
class Paypal
{
public string DoCaptureCode(string authorization_id, string amount)
{
CallerServices caller = new CallerServices();
IAPIProfile profile = ProfileFactory.createSSLAPIProfile();
profile.APIUsername = "JMK";
profile.APIPassword = "FooBar";
profile.CertificateFile = @"~\MyTestCertificate.txt";
profile.Environment = "sandbox";
caller.APIProfile = profile;
DoCaptureRequestType pp_request = new DoCaptureRequestType();
pp_request.Version = "51.0";
pp_request.AuthorizationID = authorization_id;
pp_request.Amount = new BasicAmountType();
pp_request.Amount.Value = amount;
pp_request.Amount.currencyID = CurrencyCodeType.GBP;
pp_request.CompleteType = CompleteCodeType.Complete;
DoCaptureResponseType pp_response = new DoCaptureResponseType();
pp_response = (DoCaptureResponseType)caller.Call("DoCapture", pp_request);
return pp_response.Ack.ToString();
}
}
什么是异常+跟踪用异常+更新问题trace@Rafal没有,InnerException属性为Null您是否验证了您拥有的证书1)有效且2)允许您连接到服务器?我的意思是你注册时得到的PayPal生成的证书。我直接从PayPal网站获得证书文件,我没有编辑它或更改它的名称,所以我看不出它是如何无效的。它包含一个RSA私钥和一个证书。在这两行的开头都有一行
--BEGIN\END XXX--
。是否可能需要从证书中删除元素以使其有效?这似乎不太可能!