php无法连接js,节点JS到PHP,无法让它工作

博主正尝试将一段用于登录Sony PlayStation Network (PSN) 的Node.js代码转换为PHP。在Node.js中,代码能够成功获取OAuth代码,但在PHP中遇到问题,收到'authentication_error=true'的响应。他们已经使用了CURL库,但似乎在处理登录和获取授权码的过程中遇到了困难。寻求帮助以解决PHP代码中的问题。
摘要由CSDN通过智能技术生成

我试图将一些Node JS复制到

PHP中,但似乎无法让它工作!节点在下面;

function initLogin(callback) {

debug('Getting login');

request.get({

url: psnURL.SignIN

, headers : {

'User-Agent': 'Mozilla/5.0 (Linux; U; Android 4.3; '+options.npLanguage+'; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 PlayStation App/1.60.5/'+options.npLanguage+'/'+options.npLanguage

}

}

, function (error, response, body) {

(typeof callback === "function" ? getLogin(callback, psnVars.SENBaseURL + response.req.path) : getLogin(undefined, psnVars.SENBaseURL + response.req.path));

})

}

/*

* @desc Login into PSN/SEN and creates a session with an auth code

* @param Function callback - Calls this function once the login is complete

*/

function getLogin(callback, url) {

request.post(psnURL.SignINPOST

,{

headers: {

'Origin':'https://auth.api.sonyentertainmentnetwork.com'

,'Referer': url

}

,form:{

'params' : 'service_entity=psn'

,'j_username' : options.email

,'j_password' : options.password

}

}, function (error, response, body) {

request.get(response.headers.location, function (error, response, body) {

if (!error) {

var urlString = unescape(response.req.path);

psnVars.authCode = urlString.substr(urlString.indexOf("authCode=") + 9, 6);

debug('authCode obtained: ' + psnVars.authCode);

getAccessToken(psnVars.authCode, callback);

}

else {

debug('ERROR: ' + error)

}

})

}

)

}

而我的PHP,我无法工作;

$c = curl_init();

curl_setopt_array($c, array(

CURLOPT_URL => $PSNSignIn,

CURLOPT_USERAGENT => $userAgent,

CURLOPT_HEADER => true,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_FOLLOWLOCATION => true,

CURLOPT_SSL_VERIFYPEER => false,

CURLOPT_SSL_VERIFYHOST => 2,

CURLOPT_COOKIEJAR => realpath('/tmp/cookieJar.txt'),

CURLOPT_FAILONERROR => 1,

));

$res = curl_exec($c);

$path = explode($SENBaseURL, curl_getinfo($c, CURLINFO_EFFECTIVE_URL));

$referer = $SENBaseURL . $path[1];

var_dump(file_get_contents('tmp/cookieJar.txt'), $res);

$c = curl_init();

curl_setopt_array($c, array(

CURLOPT_URL => $SignINPOST,

CURLOPT_USERAGENT => $userAgent,

CURLOPT_REFERER => $referer,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_FOLLOWLOCATION => true,

CURLOPT_SSL_VERIFYPEER => false,

CURLOPT_SSL_VERIFYHOST => 2,

CURLOPT_HEADER => array(

'Origin: https://auth.api.sonyentertainmentnetwork.com',

'Content-Type: application/x-www-form-urlencoded',

),

CURLOPT_POST => true,

CURLOPT_POSTFIELDS => array(

'params' => 'service_entity=psn',

'j_username' => $username,

'j_password' => $password,

),

CURLOPT_COOKIEFILE => 'tmp/cookieJar',

CURLOPT_FAILONERROR => 1,

));

$res = curl_exec($c);

var_dump($res, curl_getinfo($c));

它应该登录到索尼的服务器并检索OAuth代码,Node.js正在工作,所以它是可能的,但我似乎无法让它在PHP中工作.

任何帮助将非常感激.

CURL正在工作但我得到一个?authentication_error = true,它应该返回一个我可以使用的代码.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值