我通过从URL运行检查了我的代码,当我从浏览器尝试运行时,它运行正常。但它不适用于curl代码,我找不到解决方案。 curl_error
什么也不给。我已经读过“设备不会总是连接到相同的公共IP地址进行通知。”但是该解决方案是什么?请提出卷曲代码有什么问题/其他问题。
这是卷曲代码
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, BASE_URL .'api-v2/admin_notification_cron.php');
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec($ch );
curl_close( $ch );
并且admin_notification_cron.php
文件从数据库中获取数据,并每1分钟从数据库中获取20个数据后调用sendNotification函数
下面是sendNotification
功能代码:
function sendToIphone($deviceToken, $data)
{
$data['push_image'] = (($data['push_image']!='')?PHOTO_URL.'push/'.$data['push_image']:'');
$passphrase = '';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev-cert.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', '');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
$type = ($data['type']!='')?$data['type']:'0';
if ($data['message']=='add_job' || $data['message']=='process') {
//$sound = 'newrequest.mp3';
$sound = 'default';
} else {
$sound = 'default';
}
$body['aps'] = array(
'alert' => stripslashes($final_message),
'title' => APP_TITLE,
'job_id' => $data['job_id'],
'user_id' => $data['user_id'],
'created'=> $data['created'],
'type'=> $type,
'sound' => $sound,
"mutable-content"=> 1,
"category"=> "rich-apns",
"image-url"=> $data['push_image'],
'badge' => intval($badge)
);
$body['att'] = array('id' => $data['push_image']);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result) {
return 0;
} else {
return 1;
}
}
预先感谢