Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中正确放置和命名apple通知的.pem文件的位置_Php_Mysql_Ios_Cron - Fatal编程技术网

在php中正确放置和命名apple通知的.pem文件的位置

在php中正确放置和命名apple通知的.pem文件的位置,php,mysql,ios,cron,Php,Mysql,Ios,Cron,我的cron文件位于根目录下的cron文件夹下。但它总是显示一个错误,如—— Warning: stream_socket_client(): SSL: crypto enabling timeout in /home/myname/beta.myhost.com/cron/dailycron.php on line 43 Warning: stream_socket_client(): Failed to enable crypto in /home/myname/beta.myhost.c

我的cron文件位于根目录下的cron文件夹下。但它总是显示一个错误,如——

Warning: stream_socket_client(): SSL: crypto enabling timeout in /home/myname/beta.myhost.com/cron/dailycron.php on line 43

Warning: stream_socket_client(): Failed to enable crypto in /home/myname/beta.myhost.com/cron/dailycron.php on line 43

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/myname/beta.myhost.com/cron/dailycron.php on line 43
43
在附近-

$apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);
我的代码如下-

<?php

//############################# Database connection ################################/

//######################### Daily notification code ############################################/

$result = mysql_query("SELECT DISTINCT EntryId, twittes, groupname, created_at FROM users_twitte NATURAL JOIN (SELECT EntryId, MAX( created_at ) created_at FROM users_twitte GROUP BY EntryId) t");
while( $row = mysql_fetch_array($result) ) {

  // Get user array from EntryId
  $rowdata = $row['EntryId'];

  $result2 = mysql_query("SELECT * FROM `users_subscription` WHERE EntryId = $rowdata");

  while( $row2 = mysql_fetch_assoc($result2) ) {
    $group_name = $row['groupname'];
    $grp_usr_id = $row2['uid'];
    send_notification($group_name, $grp_usr_id);
  }
}

// Send Notification
function send_notification($groupname, $uid) {

    // GET device token from uid
    //$device_token = get_device_token($uid);   

    $payload = array();
    $payload['aps'] = array('alert' => "THERE IS AN MESSAGE FROM $groupname", 'badge' => 0, 'sound' => 'default');
    $payload = json_encode($payload);

    $apns_url = NULL;
    $apns_cert = NULL;
    $apns_port = 2195;

    $apns_url = 'gateway.sandbox.push.apple.com';
    $apns_cert = '/home/myname/beta.myhost.com/cron/ck.pem';

    $stream_context = stream_context_create();
    stream_context_set_option($stream_context, 'ssl', 'local_cert', $apns_cert);
    stream_context_set_option($stream_context, 'ssl', 'passphrase', "12345");

    $apns = stream_socket_client('ssl://' . $apns_url . ':' . $apns_port, $error, $error_string, 2, STREAM_CLIENT_CONNECT, $stream_context);

    $get_token_info = get_device_token_and_type($uid);
    if( 1 === $get_token_info['status'] ) {
        if(0 === $get_token_info['device_type']) {
            $device_token = $get_token_info['$device_token'];   
            $apns_message = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $device_token)) . chr(0) . chr(strlen($payload)) . $payload;
        }
        fwrite($apns, $apns_message);
        @socket_close($apns);
        @fclose($apns);
    }
}

// GET device token for uid
function get_device_token_and_type($uid) {
    $dev_tok_type_arr = array();
    // GET EMAIL id from uid
    $result = mysql_query("SELECT LoginData.device_token, LoginData.device_type FROM LoginData INNER JOIN users ON LoginData.userid = users.email WHERE users.uid =$uid");
    if( mysql_num_rows($result) > 0 ) {
        while( $rows = mysql_fetch_assoc($result) ) {
            $dev_tok_type_arr = array('device_token'=> $rows['device_token'], 'device_type'=> $rows['device_type'], 'status'=> 1);
        }
    }
    else {
        $dev_tok_type_arr = array('status'=>0, 'message'=> 'No device token exists for the userid');
    }
    return $dev_tok_type_arr;
}

?>


我的.pem文件在同一个cron文件夹中,我在-
$apns\u cert
中提到了绝对路径。让我知道我做错了什么,我检查了正确的密码短语。

只需将pem文件放在php脚本的同一文件夹中,并将变量更改为:

$apns_cert = 'ck.pem';