简体   繁体   English

在PHP中为Rail PNR API生成HMAC SHA1

[英]Generate HMAC SHA1 for Rail PNR API in PHP

I am trying to generate the HMAC SHA1 Hash to use the Railway PNR API . 我正在尝试生成HMAC SHA1哈希以使用Railway PNR API

I am using PHP Framework Codeigniter . 我正在使用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 . 然后,我尝试生成哈希并将其与Rail PNR API站点中提供的哈希生成器进行比较。

But both the hash ie the one I generated and the one I am getting from the Rail PNR API site are not the same. 但是,无论是哈希值,即我生成的哈希值还是我从Rail PNR API站点获取的哈希值,都不相同。

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. 但是仍然生成的哈希与来自API站点的哈希不同。

My three data are in the following way: 我的三个数据如下:

  • PNR: 1234567890 PNR: 1234567890
  • Format: json 格式: json
  • Public Api Key: < My Public Api Key > 公用Api密钥: < My Public Api Key >

So the data that has to be hashed is: 1234567890json< My Public Api Key > using the < My Private Api Key > 因此必须哈希的数据是: 1234567890json< My Public Api Key >使用< 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. 我可以在javascript中使用该解决方案,但最好使用PHP

EDIT: 编辑:

I even read the following but they couldn't help: 我什至阅读了以下内容,但他们无济于事:

-- Trying to digitally sign via HMAC-SHA1 with PHP - 尝试使用PHP通过HMAC-SHA1进行数字签名

-- OpenSSL HMAC-SHA1 digest does not match Crypto's -OpenSSL HMAC-SHA1摘要与加密的不匹配

Please help me out here... 请在这里帮我...

Thanks. 谢谢。

The values that are to be passed in the API is supposed to be in the alphabetical order. 应该在API中传递的值应按字母顺序排列。 Like in my case above, if we arrange the keys in alphabetical order the keys will be: format, pbapisign (ie the public key) and pnr . 像上面的情况一样,如果我们按字母顺序排列密钥,则密钥将为: format,pbapisign(即公共密钥)pnr

So the string to be hashed will be 'json'.'<My Public API Key>'.'1234567890' . 因此要哈希的字符串将是'json'.'<My Public API Key>'.'1234567890'

Now to generate the hash, basically you can use any PHP function. 现在要生成哈希,基本上可以使用任何PHP函数。 I use the hash_hmac() function to generate the hash. 我使用hash_hmac()函数生成哈希。

Now its working for me. 现在它为我工作。 Hope this helps anyone who's working with the Rail PNR API. 希望这对使用Rail PNR API的任何人有所帮助。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM