【发布时间】:2023-03-21 01:52:01
【问题描述】:
我通过从 URL 运行检查了我的代码,当我从浏览器尝试时它工作正常。但它不适用于 curl 代码,我找不到解决方案。 curl_error 什么也没给。我已经读过“设备不会总是连接到相同的公共 IP 地址以获取通知。”但是解决方案是什么请提出 curl 代码有什么问题/其他问题的可能性。
这是卷曲代码
$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;
}
}
提前致谢
【问题讨论】:
标签: php ios curl push-notification apple-push-notifications