实际上,我不确定这是一个wordpress问题还是应该在其他地方问(但一件事可能导致另一件事……)在任何情况下,试图编写一个定制的荷兰合作银行Omnikasa集成,我只会得到一个“无效或缺少签名”的结果。根据omnikassa支持回答(不是很有帮助),这是由于
刷新令牌不完整是过期的令牌使用沙盒令牌,反之亦然,这对
当然我已经使用了整个刷新令牌(refresh token expired)不是这样的(refresh toke在2099年到期,因为它是一个沙盒令牌)(c)当然我正在使用沙盒令牌等进行沙盒测试(目前的代码是这样的(当然使用变量作为顺序参数),因此,如果有任何人能想出一个主意,为什么这不起作用/我做错了什么,或者对我应该尝试的其他方法有任何想法或暗示,我将不胜感激。
/*
[url - sandbox]
*/
$apiUrl = \'https://betalen.rabobank.nl/omnikassa-api-sandbox\';
/*
Sandbox RefreshToken and Signing key
(obviuosly the whole token/keys are being used here)
*/
$RefreshToken = \'abc...xyz\';
$SigningKey = \'ABC...XYZ\';
/*
get token
*/
$response = wp_remote_get( $apiUrl.\'/gatekeeper/refresh\', array(
\'headers\' => array(
\'Authorization\' => \'Bearer \' . $RefreshToken ,
),
));
$body = wp_remote_retrieve_body( $response );
$token_data = json_decode( $body, true);
/*
token_data returns something like
[token] => eyJr.......................EnxK
[validUntil] => 2018-04-07T18:03:23.692+0000
[durationInMillis] => 3600000
*/
/*
[set orderData]
*/
$omnikassaOrder=array();
$omnikassaOrder[\'timestamp\'] = 2018-04-07T17:03:20+00:00;
$omnikassaOrder[\'merchantOrderId\'] = 101;
$omnikassaOrder[\'amount\'] = array();
$omnikassaOrder[\'amount\'][\'currency\'] = \'EUR\';
$omnikassaOrder[\'amount\'][\'amount\'] = 797;
$omnikassaOrder[\'language\'] = \'NL\';
$omnikassaOrder[\'description\'] = \'Your order at test\' ;
$omnikassaOrder[\'merchantReturnURL\'] = \'http://www.test.com/orders/?id=2666ea175d0a223114db596c86\';
/*
string to hash
*/
$toHash = array();
$toHash[] = $omnikassaOrder[\'timestamp\'];
$toHash[] = $omnikassaOrder[\'merchantOrderId\'];
$toHash[] = $omnikassaOrder[\'amount\'][\'currency\'];
$toHash[] = $omnikassaOrder[\'amount\'][\'amount\'] ;
$toHash[] = $omnikassaOrder[\'language\'];
$toHash[] = $omnikassaOrder[\'description\'];
$toHash[] = $omnikassaOrder[\'merchantReturnURL\'];
/*
add signature
*/
$omnikassaOrder[\'signature\'] = hash_hmac(\'sha512\', json_encode(implode(\',\',$toHash)), base64_decode($SigningKey));
/*
post to omnikassa
*/
$response = wp_remote_post( $apiUrl.\'/order/server/api/order\', array(
\'headers\' => array(
\'Content-Type\' => \'application/json\' ,
\'Authorization\' => \'Bearer \' . $token_data[\'token\'] ,
),
\'body\' => json_encode($omnikassaOrder),
));
$body = wp_remote_retrieve_body( $response );
$redirect_data = json_decode( $body, true );
/*
redirect_data returns always
Array
(
[errorCode] => 5001
[consumerMessage] => Invalid or missing signature
)
*/
最合适的回答,由SO网友:Olly 整理而成
事实证明(以防对其他人有帮助)
$omnikassaOrder[\'signature\'] = hash_hmac(\'sha512\', json_encode(implode(\',\',$toHash)), base64_decode($SigningKey));
应该是以下内容(没有json_encode)
$omnikassaOrder[\'signature\'] = hash_hmac(\'sha512\', implode(\',\',$toHash), base64_decode($SigningKey));