-2

URLで変数を受け取り、その情報を使用して通帳パスを作成するphpを設定しようとしています。

変数を手動で設定すると、すべてが機能しますが、$ _ GETを使用してURLからデータを取得すると、表示されません。

これが私のインデックスです。URLから変数をロードしています。

<?php


$ac = $_GET['ac'];

$af = $ac;

$log = print_r($_SERVER,1);
$log .= print_r($_POST,1);
$log .= print_r($_GET,1);
file_put_contents('./log/'.time().'.txt', $log);

if(($_POST['time'] != '')||($_GET['update'] != ''))
  {
    require('./passkit.php');



    $Certificates = array('AppleWWDRCA'  => './certs/AppleWWDRCA.pem', 
                          'Certificate'  => './certs/Certificate.p12', 
                          'CertPassword' => 'password');


    $ImageFiles = array('images/icon.png', 'images/icon@2x.png', 'images/logo.png');

    $datostest = array( '1'  => $af, 
                          '2'  => '5', 
                          '3' => '6');  

    $data = array('./data/array.php',
                  './data/json.php',
                  './data/small.php',
                  './data/coupon.json',
                  './data/event.json',
                  './data/small.json',
                  './data/generic.json');

    if($_GET['update'] != '')
      {
        $example_data = 4;
      }
    elseif(!is_numeric($_POST['aexample']))
      {
        $example_data = rand(0,6);
      }
    else
      {
        $example_data = $_POST['aexample'];
      }


    if($example_data < 3)
      {
        include($data[$example_data]);
      }
    else
      {
        $JSON = file_get_contents($data[$example_data]);
      }


    $TempPath = './temp/';

    echoPass(createPass($Certificates, $ImageFiles, $JSON, 'passtest', $TempPath));

    m_uwait(12500);
    die();
  }

?>

パス署名プロセスは次のとおりです

<?php

function PEM2DER($signature)
  {
    $signature = substr($signature, (strpos($signature, 'filename="smime.p7s"')+20));
    return base64_decode(trim(substr($signature, 0, strpos($signature, '------'))));
  }

function createPass($Certificates, $ImageFiles, $JSON, $PassName = 'pass', $TempPath = './temp/', $Debug = false)
  {
    //define pathes
    $UniquePassId  = time().hash("CRC32", $_SERVER["REMOTE_ADDR"].$_SERVER["HTTP_USER_AGENT"]);
    $ManifestPath  = $TempPath.$UniquePassId.'/manifest.json';
    $SignaturePath = $TempPath.$UniquePassId.'/signature';
    $PKPassPath    = $TempPath.$UniquePassId.'/'.$PassName.'.pkpass';

    //create temp dir
    mkdir($TempPath.$UniquePassId, 0777, true);

    //generate SHA1 hashes
    $FileHashes['pass.json'] = hash("SHA1", $JSON);
    foreach($ImageFiles as $ImagePath)
      {
        $ImageName = basename($ImagePath);
        $FileHashes[strtolower($ImageName)] = hash("SHA1", file_get_contents($ImagePath));
      }

    //save hashes as json in temp file
    $Manifest = json_encode($FileHashes);
    file_put_contents($ManifestPath, $Manifest);

    //load .p12 certificate
    $PKCS12 = file_get_contents($Certificates['Certificate']);
    $certs = array();
    if(openssl_pkcs12_read($PKCS12, $certs, $Certificates['CertPassword']) == true)
      {
        $certdata = openssl_x509_read($certs['cert']);
        $privkey = openssl_pkey_get_private($certs['pkey'], $Certificates['CertPassword']);
      }

    //sign file hashes with AppleWWDRCA certificate
    openssl_pkcs7_sign($ManifestPath, $SignaturePath, $certdata, $privkey, array(), PKCS7_BINARY | PKCS7_DETACHED, $Certificates['AppleWWDRCA']);
    $ManifestSignature = file_get_contents($SignaturePath);
    $ManifestSignatureDER = PEM2DER($ManifestSignature);

    //put files (and strings as files) in a zip archive
    $ZIP = new ZipArchive();
    $ZIP->open($PKPassPath, ZIPARCHIVE::CREATE);
    $ZIP->addFromString('signature', $ManifestSignatureDER);
    $ZIP->addFromString('manifest.json', $Manifest);
    $ZIP->addFromString('pass.json', $JSON);
    foreach($ImageFiles as $ImagePath)
      {
        $ImageName = basename($ImagePath);
        $ZIP->addFile($ImagePath, $ImageName);
      }
    $ZIP->close();

    //load pass data und delete temp files (if debug mode is off)
    $Pass['data'] = file_get_contents($PKPassPath);
    $Pass['size'] = filesize($PKPassPath);
    $Pass['name'] = $PassName;
    if(!$Debug)
      {
        unlink($TempPath.$UniquePassId.'/manifest.json');
        unlink($TempPath.$UniquePassId.'/'.$PassName.'.pkpass');
        unlink($TempPath.$UniquePassId.'/signature');
        rmdir($TempPath.$UniquePassId);
      }

    return $Pass;
  }

function echoPass($Pass)
  {
    //send http headers and zip archive content to client
    header('Pragma: no-cache');
    header('Content-type: application/vnd.apple.pkpass');
    header('Content-length: '.$Pass['size']);
    header('Content-Disposition: attachment; filename="'.$Pass['name'].'.pkpass"');
    echo $Pass['data'];
  }

?>

そして最後に、ここではそれらの変数を使用しています。

<?php



$PassStyle = "boardingPass";

$JSON = '{
  "authenticationToken": "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
 "foregroundColor" : "rgb(255, 255, 255)",
  "backgroundColor" : "rgb(27, 66, 152)",
  "labelColor" : "rgb(108, 173, 223)",
  "barcode": {
    "format": "PKBarcodeFormatQR",
    "message": "'.hash("SHA256", time().rand(0,2000000000)).'",
    "messageEncoding": "iso-8859-1"
  },
  "description": "Random '.$PassStyle.' Demo Pass",
  "foregroundColor": "rgb(251, 251, 251)",
  "formatVersion": 1,
  "'.$PassStyle.'": {
    "primaryFields": [
      {
        "key": "number",
        "value": "'.$datostest['1'].'"
      }
    ]
  },
  "logoText": "passkit.php",
  "organizationName": "Apple Inc",
  "passTypeIdentifier": "pass.com.apple.demo",
  "serialNumber": "8j23fm3",
  "teamIdentifier": "123ABCDEFG"
}';

?>

あなたが助けることができることを願っています。変数が手動で割り当てられ、URLからロードされた場合、なぜ機能するのか理解できません。

ありがとう

4

1 に答える 1

0

あなたが上に投稿したコードを見てください。問題を確認するのは難しいと思います...質問によると、Get値にアクセスできないと思います。get の仕組みを教えてください...

<a href="filename.php?value='what_you_want_to_pass'">

and at your page...

$value = $_GET['value'];

これは実際の構文です。リンクに値が渡されているかどうかを確認してください...

于 2013-01-19T05:54:36.307 に答える