gpt4 book ai didi

php - 将 cURL 命令转换为 PHP cURL (SSL)

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:45 25 4
gpt4 key购买 nike

我跑了

我终端命令行中的这个 curl

curl -c session_cookies.txt "https://login.uat.site.be/openid/oauth/authorize?client_id=site&state=e1968018-bb04-4475-86fa-b0728e9fb038&nonce=f7b76b29-2c42-423d-8d1c-5b1d0a8ce8bf&response_type=code&claims=%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D" 2>/dev/null| curl -v -b session_cookies.txt -L -H "Content-Type: application/x-www-form-urlencoded" -v -d 'j_username=manager-sitelogin@gmail.com&j_password=123' "https://login.uat.site.be/openid/login.do" 2>&1 >/dev/null | grep Location | grep code=

我得到了

此回复

< Location: https://testserver.sitenets.com/user/secure/dashboard?code=4z71kBZ4iYlqfDB7qOHvZgyXkqVEaL7v&state=e1968018-bb04-4475-86fa-b0728e9fb038


注意事项

code=4z71kBZ4iYlqfDB7qOHvZgyXkqVEaL7v

这就是我所追求的。


然后

我已经尝试将我的 curl 命令行转换为 PHP curl

  $ch = curl_init( 'https://login.uat.site.be/openid/oauth/authorize' );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, array(

'client_id' => 'site',
'state' => $state,
'nonce' => $nonce,
'claims' => '%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D',
'response_type' => 'code'

) );

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, public_path().'/session_cookies.txt');
curl_setopt($ch, CURLOPT_VERBOSE, true);

$first_curl = curl_exec($ch);

$cookie_file = public_path(). '/session_cookies.txt';
if (file_exists($cookie_file)) {

$pem_file_path = '/Applications/MAMP/conf/apache/openid.site.com.cert.pem';

$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO=> $pem_file_path,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array(
'j_username' => urlencode($un),
'j_password' => $pw,
)),
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_COOKIEFILE => $cookie_file,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_URL, 'https://login.uat.site.be/openid/login.do');
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

dd($result);
}

我从来没有得到与在我的终端上执行该命令相同的结果。

当我 dd 时,我的浏览器上不断收到这些垃圾邮件出我的$result变量

   """
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->\r\n
<!DOCTYPE html>\r\n
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->\r\n
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->\r\n
<!--[if gt IE 8]><!-->\r\n
<html class="no-js">\r\n
<!--<![endif]-->\r\n
<head>\r\n
<title>site: Meld je aan</title>\r\n
<meta content="IE=edge" http-equiv="X-UA-Compatible">\r\n
<meta charset="utf-8">\r\n
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">\r\n
<meta name="description" content="">\r\n
\r\n
<link rel="shortcut icon" href="//static.site.be/assets/favicon/favicon.ico" type="image/x-icon"/>\r\n
<link rel="stylesheet" href="css/vendor/normalize.min.css">\r\n
<link rel="stylesheet" href="css/login.css">\r\n
<link rel="stylesheet" type="text/css" href="//static.site.be/assets/fonts/omnes-breuer-logo/stylesheet.css">\r\n
\r\n
<link rel="stylesheet" href="https://static.uat.site.be/oauth2/css/main.css">\r\n
\r\n
<!-- Adobe analytics -->\r\n
<script src="https://www2.site.be/etc/designs/site-be/js/statistics/SiteCatalyst.js"></script>\r\n
\r\n
<script type="text/javascript">\r\n
function hideHtmlElement(id) {\r\n
document.getElementById(id).style.display = "none";\r\n
}\r\n
\r\n
function showHtmlElement(id) {\r\n
document.getElementById(id).style.display = "block";\r\n
}\r\n
\r\n
function showPanel(id) {\r\n
hideHtmlElement("forgotLogin");\r\n
hideHtmlElement("showLogin");\r\n
hideHtmlElement("forgotPassword");\r\n
showHtmlElement(id);\r\n
}\r\n
\r\n
</script>\r\n
\r\n
<!--[if lt IE 9]>\r\n
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>\r\n
<![endif]-->\r\n
</head>\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
<div class="wrapper">\r\n
<span id="showBackgroundForStatic" style="display: none">true</span>\r\n
<!-- ERROR SCREEN -->\r\n
<div class="container">\r\n
<div id="loginContainer">\r\n
<div id="showLogin">\r\n
<div class="options clearfix">\r\n
<div class="option-sites">\r\n
<ul>\r\n
<li><a target="_blank"\r\n
href="http://site.be/nl">Meer site</a></li>\r\n
<li><a target="_blank" href="http://site.be/nl"\r\n
tabindex="-1">site.be</a></li>\r\n
<li><a target="_blank" href="http://business.site.be/"\r\n
tabindex="-1">Business</a></li>\r\n
<li><a target="_blank"\r\n
href="http://corporate.site.be/" tabindex="-1">Over site</a></li>\r\n
<li><a target="_blank"\r\n
href="http://klantenservice.site.be/"\r\n
tabindex="-1">Klantenservice</a></li>\r\n
</ul>\r\n
</div>\r\n
<div class="option-language">\r\n
<ul>\r\n
<span id="languageForStatic" style="display: none">nl</span>\r\n
<!-- IT-4522 The design team uses languageForStatic to display text dynamically-->\r\n
\r\n
\r\n
<li class="active"><a href="?lang=nl" tabindex="-1">NL</a></li>\r\n
<li><a href="?lang=fr" tabindex="-1">FR</a></li>\r\n
\r\n
\r\n
\r\n
</ul>\r\n
</div>\r\n
</div>\r\n
\r\n
<div class="branding clearfix">\r\n
<div id="logo"><img src="https://static.site.be/oauth2/images/logosite.png"\r\n
data-at2x="https://static.site.be/oauth2/images/logosite.png@2x.png"\r\n
alt="site"></div>\r\n
<h1><label>Fout bij aanmelden</label></h1>\r\n
<span id="languageForStatic" style="display: none">nl</span>\r\n
<!-- IT-5252 The design team uses languageForStatic to display text dynamically-->\r\n
</div>\r\n
<div class="contentContainer">\r\n
<p>Er ging iets mis. Gelieve de applicatie af te sluiten en daarna opnieuw op te starten.</p>\r\n
</div>\r\n
</div>\r\n
\r\n
\r\n
</div>\r\n
<div class="copyright">&copy; site\r\n
<script>document.write(new Date().getFullYear());</script>\r\n
- <a href="http://klantenservice.site.be/content/juridische-informatie" target="_blank"\r\n
tabindex="-1">Juridische informatie</a>\r\n
- <a href="https://www2.site.be/nl/privacy/"\r\n
href="https://www2.site.be/nl/privacy/" target="_blank"\r\n
tabindex="-1">Privacy</a><br>\r\n
<a href="http://klantenservice.site.be/content/waar-vind-ik-de-algemene-voorwaarden-van-site" target="_blank"\r\n
tabindex="-1">Tariefinfo en algemene voorwaarden</a>\r\n
</div>\r\n
</div>\r\n
<div class="bgContainer"></div>\r\n
</div>\r\n
\r\n
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>\r\n
<script src="/openid/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>\r\n
<script src="/openid/js/vendor/retina-1.1.0.min.js"></script>\r\n
\r\n
<!--[if lt IE 9]>!\r\n
<script type="text/javascript" src="/openid/js/vendor/jquery.backgroundSize.js"></script>!\r\n
<![endif]-->\r\n
\r\n
<script src="https://static.uat.site.be/oauth2/js/items.js"></script>\r\n
<script src="https://static.uat.site.be/oauth2/js/main.js"></script>\r\n
\r\n
</body>\r\n
</html>\r\n
"""

我现在卡住了,我不确定我做错了什么,我不知道下一步该做什么。


问题

如何转换我的 curl 以获得相同的结果?

我需要在我的 PHP curl 设置中启用它吗?

我需要更新我的 Apache 设置吗?

我的 PHP CURL 有什么问题?

如何进一步调试它?

最佳答案

问题很可能是您的第一个请求失败,因为您没有正确设置 SSL 验证。您必须为这两个请求设置相同的 CURL 选项。区别仅在于 URL 和 POST 数据。

所以代码应该是这样的:

$cookie_file = public_path(). '/session_cookies.txt';
if (!file_exists($cookie_file)) return;
$pem_file_path = '/Applications/MAMP/conf/apache/openid.benu.com.cert.pem';
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_CAINFO=> $pem_file_path,
CURLOPT_POST => true,
CURLOPT_COOKIEJAR => $cookie_file,
CURLOPT_COOKIEFILE => $cookie_file,
);
$ch = curl_init('https://login.uat.site.be/openid/oauth/authorize');
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'client_id' => 'benu',
'state' => $state,
'nonce' => $nonce,
'claims' => '%7B%22id_token%22%3A%7B%22http%3A%2F%2Fsite.be%2Fclaims%2Froles%22%3Anull%7D%7D',
'response_type' => 'code'
)));
$result = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) {
echo 'Error:' . curl_error($ch); return;
}
$ch = curl_init('https://login.uat.site.be/openid/login.do');
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'j_username' => 'manager-sitelogin@gmail.com',
'j_password' => 'site1',
)));
$result = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err) {
echo 'Error:' . curl_error($ch);
}

关于php - 将 cURL 命令转换为 PHP cURL (SSL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41855264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com