在PHP中为Rail PNR API生成HMAC SHA1 [英] Generate HMAC SHA1 for Rail PNR API in PHP

查看:112
本文介绍了在PHP中为Rail PNR API生成HMAC SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成HMAC SHA1 Hash以使用铁路PNR API [ ^ ]


我正在使用 PHP Framework Codeigniter


我使用了帮助这里


然后我尝试生成哈希值并进行比较使用 Rail PNR API中的哈希生成器[ ^ ] 网站


但我所生成的哈希值和我从 Rail PNR API网站获得的哈希值都不相同。


然后我尝试使用在线工具生成相同的哈希值。但是仍然生成的哈希值与来自API站点的哈希值不同。


我的三个数据如下:



- PNR: 1234567890

- 格式: json

- Public Api Key : < My Public Api Key>



因此必须进行哈希处理的数据是: 1234567890json < My Public Api Key> 使用 < My Private Api Key>


我不知道如果生成哈希的方法是错误的,或者我做错了。我几乎遵循那里正确的每一步。


我没关系,如果解决方案可以在 JavaScript 中找到,但 PHP 是更受欢迎的。



编辑:



我甚至阅读以下内容但他们无能为力:



- 尝试使用PHP通过HMAC-SHA1进行数字签名



- OpenSSL HMAC-SHA1摘要与加密不匹配




请帮帮我这里.. 。



谢谢。



I am trying to generate the HMAC SHA1 Hash to use the Railway PNR API[^].

I am using PHP Framework Codeigniter.

I used the helper given here.

Then I tried to generate the hash and compare it with the Hash Generator[^] given in the Rail PNR API site.

But both the hash i.e. the one I generated and the one I am getting from the Rail PNR API site are not the same.

Then I tried to use online tools to generate the hash value for the same. But still the hash that is generated is not same as that is coming from the API site.

My three data are in the following way:

- PNR: 1234567890
- Format: json
- Public Api Key: <My Public Api Key>

So the data that has to be hashed is: 1234567890json<My Public Api Key> using the <My Private Api Key>

I don't know that if the method to generate hash is wrong or if I am doing it wrong. I pretty much followed every step that is stated there correctly.

I am okay if the solution is available in JavaScript, but PHP is more preferred.



I even read the following but they couldn't help:

-- Trying to digitally sign via HMAC-SHA1 with PHP

-- OpenSSL HMAC-SHA1 digest does not match Crypto


Please help me out here...

Thanks.







推荐答案

API中要传递的值应该按字母顺序排列。就像我上面的情况一样,如果我们按字母顺序排列键,将是: 格式,pbapisign(即公钥) pnr



因此要哈希的字符串将是 ' json'。'< My Public API Key>'。'1234567890'



现在生成哈希,基本上你可以使用任何PHP函数。我使用 hash_hmac() 函数生成哈希。



现在它为我工作。希望这可以帮助任何使用Rail PNR API的人。



谢谢。
The values that are to be passed in the API is supposed to be in the alphabetical order. Like in my case above, if we arrange the keys in alphabetical order the keys will be: format, pbapisign (i.e. the public key) and pnr.

So the string to be hashed will be 'json'.'<My Public API Key>'.'1234567890'.

Now to generate the hash, basically you can use any PHP function. I use the hash_hmac() function to generate the hash.

Now its working for me. Hope this helps anyone who's working with the Rail PNR API.

Thanks.


这篇关于在PHP中为Rail PNR API生成HMAC SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆