Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php、curl和api远程登录网站_Php_Yelp - Fatal编程技术网

使用php、curl和api远程登录网站

使用php、curl和api远程登录网站,php,yelp,Php,Yelp,从一周开始,我尝试使用php、curl和api登录yelp,但没有成功。我从我的代码中得到了这个输出:{“message”:{“field”:“signature”,“text”:“请求中缺少一个或多个参数”,“code”:8,“version”:“1.1.1”,“请求id”:“2A3723775B650682C”} 我想,我的签名结构流程不对。我多次尝试使用许多签名生成器代码,但我处于相同的位置(我没有成功) 这是我的密码: /* nonce generator */ ini_set('def

从一周开始,我尝试使用php、curl和api登录yelp,但没有成功。我从我的代码中得到了这个输出:
{“message”:{“field”:“signature”,“text”:“请求中缺少一个或多个参数”,“code”:8,“version”:“1.1.1”,“请求id”:“2A3723775B650682C”}

我想,我的签名结构流程不对。我多次尝试使用许多签名生成器代码,但我处于相同的位置(我没有成功)

这是我的密码:

/* nonce generator */
ini_set('default_mimetype', 'text/plain');
ini_set('default_charset', 'GT-I9500'); //ISO-8859-1
define('NONCE_SECRET', 'SECRET');

require_once('NonceUtil.php');
$nonces = NonceUtil::generate(NONCE_SECRET, 1);

$nonceex = explode(',',$nonces)[0];
$nonce = substr($nonceex, 0, 6).'==';

/* Time Generator */
$time = (strtotime("now"));

$p = array(
'time' => $time,
'nonce' => $nonce,
'ywsid' => 'ywsid',
'device_type' => 'Micromax+Q391/LRX21M',
'app_version' => '9.17.0',
'cc' => 'US',
'lang' => 'en',
'efs' => 'efs',
'signature' => '',
'email' => 'email',
'password' => 'password'
);

ksort($p);
$string = '';
foreach($p as $oneKey=>$oneValue) {
    $string .= urlencode($oneKey) . urlencode($oneValue);
}

$hash = hash_hmac('sha1', $string, 'HMAC-SHA1', true);
$sig = '_'.base64_encode($hash);

$p['signature'] = $sig;

/* post method */
$url = 'https://auto-api.yelp.com/account/login_secure';

$ch = curl_init();
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Version/1 Yelp/v9.17.0 Carrier/Grameenphone Model/Q391 OSBuild/LRX21M Android/5.0");
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
//curl_setopt ($ch, CURLOPT_HEADER, TRUE);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array(
'x-screen-scale: 1.5',
'X-Foregrounded: true',
'Content-Type: application/x-www-form-urlencoded',
'Host: auto-api.yelp.com'
));
curl_setopt ($ch, CURLOPT_URL, $url);
if(!curl_setopt($ch, CURLOPT_URL, $url))
{
    throw new \RuntimeException("curl_setopt with CURLOPT_URL failed. errno: ".curl_errno($ch).". errstr: ".curl_errstr(curl_errno($ch)));  
}

curl_setopt ($ch, CURLOPT_POST, TRUE);
if(!curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($p)))
{
    die("error with CURLOPT_POSTFIELDS");
};

$output = curl_exec($ch);
if(false === $output)
{ 
    if(curl_errno($ch))
{
    echo 'Curl error: ' . curl_error($ch);
}
    die("error, curl_exec failed");
} else {
    echo $output;
}
请检查此请求结果:

POST https://auto-api.yelp.com/account/login_secure?time=1535725620&nonce=nonce&ywsid=ywsid&device_type=Micromax%2BQ391%2FLRX21M&app_version=9.17.0&cc=US&lang=en&efs=efs&signature=_fCmlWphKBRCYD%2BTtZEsb2uaifTw%3D HTTP/1.1
x-screen-scale: 1.5
X-Foregrounded: true
Accept-Encoding: gzip
Content-Length: 51
Content-Type: application/x-www-form-urlencoded
Host: auto-api.yelp.com
Connection: Keep-Alive
User-Agent: Version/1 Yelp/v9.17.0 Carrier/Grameenphone Model/Q391 OSBuild/LRX21M Android/5.0
Content-Encoding: utf-8

email=zimuakter21994%40gmail.com&password=password
还要检查此响应结果:

HTTP/1.1 200 OK
Server: nginx
Content-Type: application/json; charset=utf-8
X-Node: api_com
Set-Cookie: yuv=kMGkxrA-7onbYJ6J9KLR8aHHsDWE103uBm8RE9cUe963pwQoBqYRuvFE8g7gkFR4jDarGMEM6YAu7JubiEXJXGEutGpQN_kx; Domain=.yelp.com; Max-Age=630720000; Path=/; expires=Thu, 26-Aug-2038 14:27:01 GMT
Cache-Control: max-age=0, must-revalidate, no-cache, no-store, private
Expires: Fri, 31 Aug 2018 14:27:01 GMT
Pragma: no-cache
Set-Cookie: bse=bb82de7f35af489082963b7eae7eeae3; Domain=.yelp.com; Path=/; HttpOnly
Set-Cookie: api_s=VrCIz_UekETVc8AOS1x2mHrODFIl83pD; Max-Age=630720000; Path=/; expires=Thu, 26-Aug-2038 14:27:02 GMT; HttpOnly
Set-Cookie: api_ss=i7JtViAbGXkruXsHw5MKzc76edKhqS9A; Max-Age=630720000; Path=/; expires=Thu, 26-Aug-2038 14:27:02 GMT; secure; HttpOnly
Set-Cookie: ds=nzyugdxqoKZEk7ZoCEfOQA; Domain=.yelp.com; Max-Age=120; Path=/; expires=Fri, 31-Aug-2018 14:29:02 GMT
X-Zipkin-Id: 2cb7c23dcfe94ed0
X-Content-Type-Options: nosniff
X-Node: 10-64-147-103-uswest1bprod-5590439d-ad1b-11e8-92ce-02424775f1e2
X-Mode: rw
X-Proxied: 10-64-16-25-uswest1bprod
X-Mode: rw
X-Proxied: 10-69-117-83-uswest2aprod
Accept-Ranges: bytes
Date: Fri, 31 Aug 2018 14:27:02 GMT
Via: 1.1 varnish
Connection: keep-alive
X-Served-By: cache-sin18027-SIN
X-Cache: MISS
X-Cache-Hits: 0
Vary: User-Agent
Content-Length: 384

{"first_name": "Virgie K", "last_name": "Wilson", "user_id": "7rCE1Q25rle9mbIbFccRbg", "last_initial": "W", "is_confirmed": true, "gender": "f", "expiry": 1543501622, "location": "Hillsdale, IL", "name_without_period": "Virgie K W", "message": {"text": "OK", "code": 0, "version": "1.1.1", "request_id": "2cb7c23dcfe94ed0"}, "email": "zimuakter21994@gmail.com", "name": "Virgie K W."}

首先,更换您的密码

那么你应该看这一部分:

foreach($p as $oneKey=>$oneValue) {
    $string .= urlencode($oneKey) . urlencode($oneValue);
}
您需要像这样分离字符串:

$string = ""
foreach($p as $oneKey=>$oneValue) {
    $string .= ($string!="" ? "&" : "") .urlencode($oneKey) . "=" urlencode($oneValue);
}

这是你的电子邮件地址和密码吗?是的,这是我的yelp电子邮件和密码你想登录什么api?似乎他们有超过1个,
yelpfusion
GraphQL
什么是
noncertil.php
?我用了你的字符串
$string=”“;foreach($p as$oneKey=>$oneValue){$string.=($string!=“”?“&”:“”).urlencode($oneKey.“=”.urlencode($oneValue);}
但输出相同。你试过我的代码吗?我从postfields
$p
得到它,并使用这个代码
$hash=hash_hmac('sha1','string'hmac-sha1',true)$sig=''''''.base64'-encode($hash)很抱歉英语不好。我是说你的api文档是从哪里来的?他们有一个api,如果它没有在那里实现,你就不应该实现它。因为你不知道它们是如何生成每个参数的