donglao4370 2017-07-28 12:50
浏览 89

使用API​​的APNS通知无效

I tried executing the API APNS using CURL . The code is as below

$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";
}

Iam getting the result as :

  �@@uUnexpected HTTP/1.x request: POST /3/device/54688ae0e1ecc3bc0d517521f4935c014342ecca792ef798f0e63652a4620ed4 bool(true) ----int(0)

I was trying this method to handle the invalid device token .Earlier i tried ssl using PHP like this link(http://learn-php-by-example.blogspot.in/2013/01/working-with-apple-push-notification.html) , In that when a invalid device token is in the db and when we pass it through the loop the push notification stops working . So i was trying the API method .

Thanks in advance for your response guys

  • 写回答

2条回答 默认 最新

  • dqp99585 2017-07-28 13:12
    关注

    for the new HTTP/2 APNS provider API, you can use curl to send push notifications : New APNS Provider API and PHP

    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂