3

我已经用我的代码生成了 PASS 并且还从设备获取了设备 ID、推送令牌作为响应。

这是我在数据库中存储所有设备和传递信息的代码。

   $params = array(
                    "get"=>$_GET,
                    "request"=>$_REQUEST,
                    "post"=>$_POST,
                    "server"=>$_SERVER
                );
$url = $_SERVER['SCRIPT_URI'];
$myfile = file_put_contents('callback.txt', json_encode($params).PHP_EOL , FILE_APPEND | LOCK_EX);
$content = trim(file_get_contents("php://input"));
$myfile = file_put_contents('log.txt', $content.PHP_EOL , FILE_APPEND | LOCK_EX);
$header = json_encode(getallheaders());
$myfile = file_put_contents('header.txt', $header.PHP_EOL , FILE_APPEND | LOCK_EX);



/*
 * store registered device data
 * */

$str = $_SERVER['SCRIPT_URI'];
$str = stripslashes($str);


$url_slot = parse_url($str);
$urlArray = explode('/',$url_slot['path']);
$passid = $urlArray['11']; // serial no
$deviceId = $urlArray['8'];
$passtype = $urlArray['10'];
try {
    $dbh = new PDO('mysql:host=localhost;dbname=''', 'yyyy', 'zzzz');


    $stmt = $dbh->prepare("INSERT INTO devices_passes (device_id, pass_id, pass_type, created, modified) VALUES
(:device_id,:pass_id,:pass_type,:created,:modified)");
    $stmt->bindParam(':device_id', $device_id);
    $stmt->bindParam(':pass_id', $pass_id);
    $stmt->bindParam(':pass_type', $pass_type);
    $stmt->bindParam(':created', date('d-m-y'));
    $stmt->bindParam(':modified', date('d-m-y'));

    $device_id = $deviceId;
    $pass_id = $passid;
    $pass_type = $passtype;

    $stmt->execute();
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}



try {
    $dbh = new PDO('mysql:host=localhost;dbname=yyyy', 'uuuuu', 'yyyyyy');
    $stmt = $dbh->prepare("INSERT INTO devices (push_token) VALUES
(:push_token)");
    $stmt->bindParam(':push_token', $push_token);
    $push_token = $content['pushToken'];
    $stmt->execute();
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

但是当我向设备发送推送通知时,它不会反映设备中的任何内容。这是向设备发送推送通知的代码。

<?php
$apnsHost = 'gateway.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apple_push_notification_production.pem';
$push_token = 'my token';
$passIdentify = 'pass.yyyyy.xxxx';

$payload = '{}';
$msg = chr(0) . pack('n', 32) . pack('H*', $push_token) . pack('n', strlen($payload)) . $payload . pack('n', strlen($passIdentify)) . $passIdentify;

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

fwrite($apns, $msg);

@socket_close($apns);
fclose($apns);

?>

当我出错时,你能帮我吗?

4

0 回答 0