PHP卷曲HMAC-SHA1 [英] PHP Curl HMAC-SHA1

查看:139
本文介绍了PHP卷曲HMAC-SHA1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要这个帮助....
我需要从从URL API调用获取JSON数据。
它说,所谓的需求。

Need help on this .... I need to get json data from API call from a URL. It said the called need..


  1. 内容类型:应用程序/ x-WWW的形式urlen codeD

  2. HTTP头:关键---> APIKEY

  3. HTTP头:SIG的--->与密钥后的数据,HMAC-SHA1签名

  4. POST参数:时间戳---->当前Unix时间戳

难道我这样做是否正确?但是,如何实现上述??? 3点

Do I do this correctly? But how to implement point 3 above???

$key = 'APIKEY';
$secret = 'APISECRET';
$signature = '';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/getticker");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "timestamp=".time());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","key: ".$key,"sig: ".$signature));
$response = curl_exec($ch);
curl_close($ch);

echo $response;

被抓我的头在这个。请帮我在PHP这个新手。

Been scratching my head over this. please help me this newbie on PHP.

推荐答案

最后我得到了它....
看到$签名部分。

Finally I got it.... see the $signature part.

$key = 'APIKEY';
$secret = 'APISECRET';

$timestamp = time();
$signature = hash_hmac('sha1', "timestamp=".$timestamp, $secret);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/getticker");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "timestamp=".time());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","key: ".$key,"sig: ".$signature));
$response = curl_exec($ch);
curl_close($ch);

echo $response;

这篇关于PHP卷曲HMAC-SHA1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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