Salesforce API PHP:生成令牌错误SSL23_CLIENT_HELLO

时间:2016-07-01 05:34:03

标签: php curl salesforce

我指的是API>> http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php

我必须生成令牌以将潜在客户添加到SF。

以下是我的代码>> `

if (!isset($code) || $code == "") {
    die("Error - code parameter missing from request!");
}

$params = "code=" . $code. "&grant_type=authorization_code". "&client_id=" . CLIENT_ID. "&client_secret=" . CLIENT_SECRET. "&redirect_uri=" . urlencode(REDIRECT_URI);

$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Connection: Keep-Alive'));
curl_setopt($curl, CURLOPT_SSLVERSION, 6);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
    die("Error: call to token URL $token_url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
$access_token = $response['access_token'];
$instance_url = $response['instance_url'];
if (!isset($access_token) || $access_token == "") {
    die("Error - access token missing from response!");
}
if (!isset($instance_url) || $instance_url == "") {
    die("Error - instance URL missing from response!");
}
$_SESSION['access_token'] = $access_token;
$_SESSION['instance_url'] = $instance_url;
`

上面的代码在我的localhost上工作正常,但在服务器>>

上返回以下错误
Error: call to token URL https://login.salesforce.com/services/oauth2/token failed with status 0, response , curl_error error:140740BF:SSL routines:SSL23_CLIENT_HELLO:no protocols available, curl_errno 35

我们在服务器上安装了SSL。请提出有关问题的建议。

感谢。

1 个答案:

答案 0 :(得分:2)

问题是旧的OpenSSL库(0.9.8b)不支持TLS 1.2。您需要安装OpenSSL 1.0.1或更高版本才能获得TLS 1.1和TLS 1.2支持。