首页 » phpcode » php苹果原生apns推送接口

php苹果原生apns推送接口

 
public function c_push(){
    if(defined('CURL_HTTP_VERSION_2_0')){

        $device_token   = '413eed6b6253f16fdc010217caa845cadab7abde6360ee959051dc3b6645a06b';
        //$pem_file     = 'path to your pem file';
        $pem_file       = "/Users/xzh/www/test/www/pem/dev.pem";
        //$pem_secret   = 'your pem secret';
        $pem_secret     = '';
        //$apns_topic   = 'your apns topic. Can be your app bundle ID';
        $apns_topic     = 'com.zhapp.fhzxg.BPushProject';

        $data = array(
            "aps"=>array(
                'alert'=>'这是推送标题',
                "sound"=>"default",
                "badge"=>0,
            ),
            'app'=>array(
                "title"=>"这是展示标题内容",
                "content"=>"这是自定义内容",
            ),
        );
        $url = "https://api.development.push.apple.com/3/device/$device_token";

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $j = json_encode($data));
        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_SSLKEYTYPE, 'PEM');
        curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
        $response = curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        if($httpcode == 200){
            echo "push ok";
        }
    }else{

        echo "error http2!";
    }
}

原文链接:php苹果原生apns推送接口,转载请注明来源!

0