我想在php中将xero api集成到公共应用程序中.我坚持使用oauth应用程序授权我从github下载代码 https://github.com/XeroAPI/XeroOAuth-PHP(在公共应用程序的xero api代码示例中找到)
我正在使用以下代码:
require('/../lib/XeroOAuth.php');
require('/../_config.php');
$useragent = "Xero-OAuth-PHP Public";
$signatures = array (
'consumer_key' => 'app_consumre_key',
'shared_secret' => 'app_secret_key',
'core_version' => '2.0'
);
$XeroOAuth = new XeroOAuth ( array_merge ( array (
'application_type' => XRO_APP_TYPE,
'oauth_callback' => OAUTH_CALLBACK,
'user_agent' => $useragent
), $signatures ) );
include 'tests.php';
Run Code Online (Sandbox Code Playgroud)
我正在传递以下xml数据:
$xml = "<Invoices>
<Invoice>
<Type>ACCREC</Type>
<Contact>
<Name>Martin Hudson</Name>
</Contact>
<Date>2013-05-13T00:00:00</Date>
<DueDate>2013-05-20T00:00:00</DueDate>
<LineAmountTypes>Exclusive</LineAmountTypes>
<LineItems>
<LineItem>
<Description>Monthly rental for property at 56a Wilkins Avenue</Description>
<Quantity>4.3400</Quantity>
<UnitAmount>395.00</UnitAmount>
<AccountCode>200</AccountCode>
</LineItem>
</LineItems>
</Invoice>
</Invoices>"; …
Run Code Online (Sandbox Code Playgroud) 我正在将我的应用程序与Xero集成,后者需要两个证书.我上传他们从帮助到Azure 此文章,但我仍然无法连接到Xero的API.我希望有人有将Xero合作伙伴应用程序与Azure Web App集成的经验.
我上传了两个pfx文件; 一个是自签名证书,另一个是Xero颁发的合作伙伴证书.后一个pfx文件包含两个证书; 一个Entrust商业私人子CA1(无论手段)和我的应用程序的唯一Entrust Id证书.
我使用以下代码通过其独特的指纹加载证书:
static X509Certificate2 GetCertificateFromStore(string thumbprint)
{
var store = new X509Store(StoreLocation.CurrentUser);
try
{
thumbprint = Regex.Replace(thumbprint, @"[^\da-zA-z]", string.Empty).ToUpper();
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates;
var currentCerts = certCollection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
var signingCert = currentCerts.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (signingCert.Count == 0)
{
throw new Exception($"Could not find Xero SSL certificate. cert_name={thumbprint}");
}
return signingCert[0];
}
finally
{
store.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
这在本地工作正常,但在我的天蓝色网站上我收到403.7错误:
The page you are attempting to access requires your browser …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Xero OAuth2.0 API,一旦令牌过期,我就会刷新令牌。 Xero 文档 我将令牌存储在 JSON 文件中,以便下次可以检索。
错误响应:
{
"error": "invalid_grant"
}
Run Code Online (Sandbox Code Playgroud)
请参考下面我使用过的代码
public function getAccessToken($code = null) {
if(file_exists($this->tokenPath) && isset($code)) {
$accessToken = $this->getAccessTokenFromAuthCode($code);
} else if (file_exists($this->tokenPath)) {
$accessToken = $this->getAccessTokenFromJSON();
try {
if (time() > $accessToken->expires) {
$accessToken = $this->provider->getAccessToken('refresh_token', [
'refresh_token' => $accessToken->refresh_token
]);
}
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
//header('Location: ' . $this->getAuthorizationUrl());
}
} else if(isset($code)){
$accessToken = $this->getAccessTokenFromAuthCode($code);
} else {
header('Location: ' . $this->getAuthorizationUrl());
}
return $accessToken;
}
public …
Run Code Online (Sandbox Code Playgroud) 在尝试联系 Xero API 时疯狂地尝试解决 Node.js 上的错误。
我使用了一堆“.cer”、“.crt”和“.pem”的组合。
我遵循了许多 StackOverflow 海报的建议。
Node.js https pem 错误:错误:0906D06C:PEM 例程:PEM_read_bio:无起始行
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Error (native)
at Sign.sign (crypto.js:327:26)
at Xero.oa._createSignature (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/index.js:19:68)
at exports.OAuth._getSignature (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/node_modules/oauth/lib/oauth.js:90:15)
at exports.OAuth._prepareParameters (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/node_modules/oauth/lib/oauth.js:300:16)
at exports.OAuth._performSecureRequest (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/node_modules/oauth/lib/oauth.js:309:31)
at Xero.call (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/xero/index.js:51:20)
at /Users/BeardedMac/projects/clause/clause-mean-stack/routes/external.js:47:10
at Layer.handle [as handle_request] (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/layer.js:95:5)
at /Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/index.js:330:12)
at next (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/router/index.js:271:10)
at expressInit (/Users/BeardedMac/projects/clause/clause-mean-stack/node_modules/express/lib/middleware/init.js:33:5)
Run Code Online (Sandbox Code Playgroud)
有没有人有一些见解?
Xero API 说它想要一个 X509 证书......虽然我什至没有打电话。
我创建了扩展 XeroServiceProvide 的自定义服务提供者,基本上,我有多个 Xero 帐户,我想更改两个配置参数值 runtime consumer_key和consumer_secret。有没有快捷的方法。我检查了服务容器上下文绑定,但不知道如何使用。
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use DrawMyAttention\XeroLaravel\Providers\XeroServiceProvider;
class CustomXeroServiceProvider extends XeroServiceProvider
{
private $config = 'xero/config.php';
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Register the application services.
*
* @return void
*/
public function register($configParams = [])
{
parent::register();
if(file_exists(config_path($this->config))) {
$configPath = config_path($this->config);
$config = include $configPath;
}
$this->app->bind('XeroPrivate', function () use ($config,$configParams) { …
Run Code Online (Sandbox Code Playgroud) 将使用设置文件的应用程序移植到Azure函数时,是否有必要消除对文件的依赖?
我想编写一个功能应用程序,以将数据从Xero导入到Azure sql数据库中。我正在使用的Xero SDK需要一个appsettings.json文件。
因此,当函数运行时,我得到了错误
System.Private.CoreLib: Exception while executing function:
FunctionXeroSync. Xero.Api: The type initializer for
'Xero.Api.Infrastructure.Applications.Private.Core' threw an exception.
Microsoft.Extensions.Configuration.FileExtensions: The configuration file
'appsettings.json' was not found and is not optional. The physical path is
'C:\Users\kirst\AppData\Local\AzureFunctionsTools\Releases\2.6.0\cli\appsettings.json'.
Run Code Online (Sandbox Code Playgroud)
我尝试通过VS2017 Project Publish选项卡上的Manage Application Settings链接将相关设置放入。显然,这失败了。我还有其他方法可以使用吗?
这是api中的相关代码。我希望不必修改它,以便可以使用官方的nuget包。
namespace Xero.Api
{
public class XeroApiSettings : IXeroApiSettings
{
public IConfigurationSection ApiSettings { get; set; }
public XeroApiSettings(string settingspath)
{
var builder = new ConfigurationBuilder()
.AddJsonFile(settingspath)
.Build();
ApiSettings = builder.GetSection("XeroApi");
}
public XeroApiSettings() : this("appsettings.json")
{
} …
Run Code Online (Sandbox Code Playgroud) 根据此处的说明 ( https://developer.xero.com/documentation/webhooks/configuring-your-server ) 设置和验证 Xero webhook 的接收意图。
计算出的签名应与标头中的签名匹配,以获得正确签名的有效负载。
但是,使用 python 3,计算出的签名与标头中的签名根本不匹配。Xero 会向订阅 webhook url 发送大量请求,无论正确还是错误。在我的日志中,所有这些请求都返回为 401。因此,下面是我的测试代码,也被证明不匹配。我不知道缺少什么或者我做错了什么。不要担心这里显示的密钥,我已经生成了另一个密钥,但这是分配给我用于此时散列的密钥。根据他们的指示,运行此代码应该使签名与标头之一匹配。但根本不接近。
XERO_KEY =
"lyXWmXrha5MqWWzMzuX8q7aREr/sCWyhN8qVgrW09OzaqJvzd1PYsDAmm7Au+oeR5AhlpHYalba81hrSTBeKAw=="
def create_sha256_signature(key, message):
message = bytes(message, 'utf-8')
return base64.b64encode(hmac.new(key.encode(), message,
digestmod=hashlib.sha256).digest()).decode()
# first request header (possibly the incorrect one)
header = "onoTrUNvGHG6dnaBv+JBJxFod/Vp0m0Dd/B6atdoKpM="
# second request header (possibly the correct one)
header = "onoTrUNvGHG6dnaBv+JBJxFodKVp0m0Dd/B6atdoKpM="
payload = {
'events':[],
'firstEventSequence':0,
'lastEventSequence':0,
'entropy':
'YSXCMKAQBJOEMGUZEPFZ'
}
payload = json.dumps(payload, separators=(",", ":")).strip()
signature = create_sha256_signature(XERO_KEY, str(payload))
if hmac.compare_digest(header, signature):
print(True)
return 200
else:
print(False)
return …
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用以下 API 端点检索帐户列表的帐户详细信息:https://api.xero.com/api.xro/2.0/Accounts。
我包括以下范围:
openid个人资料电子邮件accounting.transactionsaccounting.reports.readaccounting.contacts.read。
但是我收到以下错误:
[Title] => Unauthorized
[Status] => 401
[Detail] => AuthorizationUnsuccessful
Run Code Online (Sandbox Code Playgroud)
谢谢
我需要设置一个用于接收Webhooks的PHP页面 - 我以前做过很多这样的事情,这不是问题,但我正在为这个项目工作的API要求我的webhook验证标题中提供的签名.
作为验证请求的一部分,它将发送以下内容:
HEADER:
"x-xero-signature" : HASH_VALUE
PAYLOAD:
{
"events": [],
"lastEventSequence": 0,
"firstEventSequence": 0,
"entropy": "S0m3r4N0m3t3xt"
}
Run Code Online (Sandbox Code Playgroud)
我已经创建了一个Webhook密钥(例如'ABC123'),并且作为此Webhook的验证请求的一部分,我必须确保使用带有webhook密钥和base64编码的HMACSHA256散列的有效负载应该与标头中的签名匹配.这是一个正确签名的有效负载.如果签名与散列有效负载不匹配,则它是错误签名的有效负载.
要获得Intent接收验证,接收URL必须响应状态:200 Ok所有正确签名的有效负载并以状态响应:401未授权所有错误签名的有效负载.
关于如何解决这个问题,我现在有点迷失了 - 这个设置的细节可以在这里找到:
https://developer.xero.com/documentation/getting-started/webhooks
我正在关注这个包装器
我有这样的错误:开捕致命错误:传递给XeroPHP \型号\会计\发票:: setDueDate(参数1)必须实现接口DateTimeInterface,字符串中给定
这是我的代码:
try{
$lineitem = new LineItem($this->_xi);
$lineitem->setAccountCode('200')
->setQuantity('5.400')
->setDescription('this is awesome test')
->setUnitAmount('9900.00');
$contact = new Contact($this->_xi);
$contact->setName("John Doe")
->setFirstName("John")
->setLastName("Doe")
->setEmailAddress("johngwapo@hot.com")
->setContactStatus(Contact::CONTACT_STATUS_ACTIVE);
$invoice = new Invoice($this->_xi);
$invoice->setType(Invoice::INVOICE_TYPE_ACCREC)
->setStatus(Invoice::INVOICE_STATUS_AUTHORISED)
->setContact($contact)
//->setDate(\DateTimeInterface::format("Y-m-d"))
->setDueDate("2018-09-09")
->setLineAmountType(Invoice::LINEAMOUNT_TYPE_EXCLUSIVE)
->addLineItem($lineitem)
->setInvoiceNumber('10')
->save();
}catch ( Exception $e ){
$GLOBALS['log']->fatal('[Xero-createContact]-' . $e->getMessage());
echo $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试这样做时:
->setDueDate(\DateTimeInterface::format("Y-m-d"))
Run Code Online (Sandbox Code Playgroud)
我得到了这个错误:致命错误:非静态方法DateTimeInterface :: format()无法静态调用,假设$ this来自不兼容的上下文
这是我调用的setDueDate的功能:
/**
* @param \DateTimeInterface $value
* @return Invoice
*/
public function setDueDate(\DateTimeInterface $value)
{
$this->propertyUpdated('DueDate', $value);
$this->_data['DueDate'] = $value; …
Run Code Online (Sandbox Code Playgroud)