我尝试使用CURL执行API APNS。代码如下使用API的APNS通知不起作用
$pem_file = 'public/assets/pem/test.pem';
$pem_secret = '';
$apns_topic = 'com.test.demo';
if(defined('CURL_HTTP_VERSION_2_0'))
{
$devicetoken=['54688ae0e1ecc3bc0d517521f4935c014342ecca792ef798f0e63652a4620ed4','de963dfbc03f5de416c7d806e04a6f3276716f246942fa2a61cffa393a780120','a08832de8b72567aa487beefe50e4e29caaa4a51ab14706fc8f0ef9df1f6b9c4','48335901c12bf02a03cef453d2e7739eaac9779991cafef3fa70ffe587ea3f12'];
$sample_alert = '{"aps":{"alert":"hi","sound":"default"}}';
foreach($devicetoken as $device_token)
{
$url = "https://api.development.push.apple.com/3/device/$device_token";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sample_alert);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("apns-topic: $apns_topic"));
curl_setopt($ch, CURLOPT_SSLCERT, $pem_file);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//On successful response you should get true in the response and a status code of 200
var_dump($response);echo "----";var_dump($httpcode);
}
}
else{
echo"NOt a supported version";
}
荫得到结果为:
�@@uUnexpected HTTP/1.x request: POST /3/device/54688ae0e1ecc3bc0d517521f4935c014342ecca792ef798f0e63652a4620ed4 bool(true) ----int(0)
我尝试这个方法来处理无效的设备令牌.Earlier我尝试SSL使用PHP这样的链接(http://learn-php-by-example.blogspot.in/2013/01/working-with-apple-push-notification.html)在这种情况下,当一个无效的设备令牌位于数据库中,并且当我们将其传递给循环时,推送通知将停止工作。所以我正在尝试API方法。
预先感谢您的答复家伙
不要在这里放置原始凭证 – C2486
回复似乎表明他们已收到此HTTP1.x!不按照您的设置。检查你的'php curl'安装? – YvesLeBorg
你尝试过一个详细的卷曲吗?我有时会通过这种方式深入了解明显的“同行”问题。 – YvesLeBorg