php 极光推送

 $content,
             //安卓自定义
             "android" => array(
                 "alert" => $content,
                 "title" => "",
                 "builder_id" => 1,
                 "extras" => array("type" => $m_type, "txt" => $m_txt)
             ),
             //ios的自定义
             "ios" => array(
                 "alert" => $content,
                 "badge" => "1",
                 "sound" => "default",
                 "extras" => array("type" => $m_type, "txt" => $m_txt)
             )
         );

         //苹果自定义---为了弹出值方便调测
         $data['message'] = array(
             "msg_content" => $content,
             "extras" => array("type" => $m_type, "txt" => $m_txt)
         );

         //附加选项
         $data['options'] = array(
             "sendno" => time(),
             "time_to_live" => $m_time, //保存离线时间的秒数默认为一天
             "apns_production" => false, //布尔类型   指定 APNS 通知发送环境:0开发环境,1生产环境。或者传递false和true
         );
         $param = json_encode($data);
     //    $postUrl = $this->url;
         $curlPost = $param;

         $ch = curl_init();                                      //初始化curl
         curl_setopt($ch, CURLOPT_URL, $postUrl);                 //抓取指定网页
         curl_setopt($ch, CURLOPT_HEADER, 0);                    //设置header
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            //要求结果为字符串且输出到屏幕上
         curl_setopt($ch, CURLOPT_POST, 1);                      //post提交方式
         curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);           // 增加 HTTP Header(头)里的字段
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);        // 终止从服务端进行验证
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
         $return_data = curl_exec($ch);                                 //运行curl
         curl_close($ch);

         return $return_data;
     }
}

你可能感兴趣的:(php 极光推送)