Php 使用API的APNS通知不起作用

Php 使用API的APNS通知不起作用,php,curl,apple-push-notifications,Php,Curl,Apple Push Notifications,我尝试使用CURL执行API APN。代码如下 $pem_file = 'public/assets/pem/test.pem'; $pem_secret = ''; $apns_topic = 'com.test.demo'; if(defined('CURL_HTTP_VERSION_2_0')) { $devicetoken=['54688ae0e1ecc3bc0d517521f4935c014342ecca792ef798f0e63652a4620ed

我尝试使用CURL执行API APN。代码如下

$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)
我尝试用这个方法来处理无效的设备令牌。早些时候,我尝试使用类似于此链接的PHP使用ssl,因为当一个无效的设备令牌在db中时,当我们通过循环传递它时,推送通知停止工作。所以我尝试了API方法


提前感谢您的回复。对于新的HTTP/2 APNS提供程序API,您可以使用curl发送推送通知:

首先确保您的curl版本支持HTTP/2,您必须使用它编译curl,默认情况下它不处于活动状态

然后确保cURL使用的是opensslv1.0.2或更高版本。

请在php的cURL包中启用http2

如果您已经启用了对curl的http2支持,也可以查看phpinfo

之后,只需将CURLOPT_HTTP_VERSION curl选项设置为3


不要将原始凭证放在此处,响应似乎表明他们在HTTP1.x中收到了此信息!不符合您的设置。检查您的php curl安装?您是否尝试过详细的curl?我有时会通过这种方式更深入地了解明显的同级问题。我只尝试了那个链接,检查了我发布的代码。早些时候,我使用了ssl,我也从前面提到的一个链接中了解到了这一点。