I impleted https://github.com/tschoffelen/php-pkpass to generate pkpass.
I integrated in backed restfull api which send response in text/xml content type.
I am trying to read .pkpass file in backed and send in api response as below that could be decoded by ios app and use this pkpass.
but using file-get-content we are not geting valid content that could be sent as string. this works fine if we use this to dowload file from web browser.
Is there anything that I am missing to read content of .pkpass file.
public function create($output = false)
{
$paths = $this->getTempPaths();
// Creates and saves the json manifest
if(!($manifest = $this->createManifest())) {
$this->clean();
return false;
}
// Create signature
if($this->createSignature($manifest) == false) {
$this->clean();
return false;
}
if($this->createZip($manifest) == false) {
$this->clean();
return false;
}
// Check if pass is created and valid
if(!file_exists($paths['pkpass']) || filesize($paths['pkpass']) < 1) {
$this->sError = 'Error while creating pass.pkpass. Check your ZIP extension.';
$this->clean();
return false;
}
// Get contents of generated file
$file = file_get_contents($paths['pkpass']);
$size = filesize($paths['pkpass']);
$name = basename($paths['pkpass']);
// Cleanup
//$this->clean();
// Output pass
if($output == true) {
$fileName = $this->getName() ? $this->getName() : $name;
if(!strstr($fileName, '.')) {
$fileName .= '.pkpass';
}
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.apple.pkpass');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s T'));
header('Pragma: public');
header('Content-Length: ' . $size);
@ob_end_flush();
set_time_limit(0);
echo $file;
return true;
}
return $file;
}
method call
$pk_pass = $pass->create('false');
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<root>';
$xml .= '<pass>'.$pk_pass.'</pass>';
$xml .= '</root>';
Response I get as below
<?xml version="1.0" encoding="UTF-8"?>
<root>
<pass>PKX��L����l &
signature͖{8�[�����0��F�J�=.!G�%��k:��1���L��R��"�NT��J���)���t��n_�')Gw���P�������1����Z{�{��~{)���$�3�-R�eR���4a"kF-"�b��0���?B2))��A
�`X��e�������nSv�2�&)$�5*�т��Z`�\�j`W��lыK#����R]�dR���b�Atcla�y|����`SD,WHv.rk����aMteD�HM!Wn1y�(��Ñ큭�ؐ��Dt�&I%��1X�\ӝy��!Hc�"�h<��`��<W��QYl�G�Pd[`=�a�~�!10����m�;nS!Q���
���
$���8i��{{��z����xy��ݾ�)�B��Î�J
i*!z,,� �+7��W���=�1�ì���N��Ч�!>��~{�����p�����������[ޥ)����\����(������U��E�[���,jM_�+��ZU��wV��
5ϰ�.Ģ�s�V�jh�}������W<�Q�x�nB��J�O&��9���������v����t`��qC�Gb_]8��pb_�9|ۗ[Zb�����?r)���ك�c��+/��]��%ZTt2��ò��l{�[�t��E������!,b�i&����J��Lh� %�T
�)�\8�J�P>4A��n����zjU
��́gg�x�^�,mNU3��*�&K`�QP�S$�/���ф|E���;V�b1]��Д�@DK!�V H&���FW��d,�� ������S�hK i�d�,Ԡ!9�$9�¥1�Hb��,!��)�Dj�CrO BFB�fCH��h�h�'�a�\�|ċ����St��!� \:����Y�ń8m2̿؈�C|�&-��5��B�h�5E�+��
<y@�����Ӡ�O1A�@>o�^�2�Q��TTh����L��% �=f�u�ڑ���.4�N��(4mTJ���p��D�Q�J2���Nm�A�h�����&~�ƿ�J^^�ݔ����`���
����
</pass>
</root>
$file = base64_encode($file);
. Then the API needs to decode it, using$content = base64_decode($theEncodedData);
. XML is a text-format. You can't send binary data in XML.