Release in Apple Passwallete integration with php

I created a PASS with my code and also get the device id, pushtoken in response from the device.

Here is the code by which I store the entire device and transfer the information to the database.

   $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();
}

      

But when I send a push notification to the device, it will not reflect anything in the device. here is the code for sending push notification to device.

<?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);

?>

      

Can you please help me when I am wrong?

+3


source to share





All Articles