你好,我正在用php为c2dm编写代码,这是Drupal模块中的代码,我的问题是它在我的本地主机"wamp"服务器上工作,但是当尝试在我的CentOS 5服务器上使用它时,var_dump($response)返回bool(false),我的域已通过认证并且curl在我的服务器上运行良好, 我的情况有什么解决方案吗?
function push_notifications_c2dm_token() {
$data = array(
'Email' => PUSH_NOTIFICATIONS_C2DM_USERNAME,
'Passwd' => PUSH_NOTIFICATIONS_C2DM_PASSWORD,
'accountType' => 'HOSTED_OR_GOOGLE',
'source' => 'Company-AppName-Version',
'service' => 'ac2dm',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, PUSH_NOTIFICATIONS_C2DM_CLIENT_LOGIN_ACTION_URL);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
var_dump($response); die();
curl_close($curl);
// Get the auth token.
preg_match("/Auth=([a-z0-9_'-]+)/i", $response, $matches);
$auth_token = $matches[1];
if (!$auth_token) {
watchdog('push_notifications', 'Google C2DM Server did not provide an authentication token.', NULL, WATCHDOG_ERROR);
}
else {
return $auth_token;
}
}
您可以使用
curl_error()
(http://www.php.net/manual/en/function.curl-error.php)来查找代码中的问题。curl_exec()
返回的假布尔值没有提供足够的信息来解决问题。