2011-01-21 19 views
0

干し草私はphpスクリプトからupcdatabaseを呼び出すと、エラーが出るので、バーコードリーダープロジェクトに取り組んでいます。私は$のUPC = '0639382000393' をチェックするときのコードがUPCデータベースにPHP XML/RPCを呼び出す方法

<?php error_reporting(E_ALL); 
ini_set('display_errors', true); 

require_once 'XML/RPC.php'; 

$rpc_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Set your rpc_key here 
$upc='0639382000393'; 
// Setup the URL of the XML-RPC service 
$client = new XML_RPC_Client('/xmlrpc', 'http://www.upcdatabase.com'); 
$params = array(new XML_RPC_Value(array(
    'rpc_key' => new XML_RPC_Value($rpc_key, 'string'), 
    'upc' => new XML_RPC_Value($upc, 'string'), 
), 'struct')); 
$msg = new XML_RPC_Message('lookup', $params); 
$resp = $client->send($msg); 
if (!$resp) 
      { 
    echo 'Communication error: ' . $client->errstr; 
    exit; 
} 
if(!$resp->faultCode()) 
{ 
    $val = $resp->value(); 
    $data = XML_RPC_decode($val); 
    echo "<pre>" . print_r($data, true) . "</pre>"; 
}else{ 
    echo 'Fault Code: ' . $resp->faultCode() . "\n"; 
    echo 'Fault Reason: ' . $resp->faultString() . "\n"; 
} 
?> 

あるwww.upcdatabase.com

によって提供されるPHPの例を使用します。 upcデータベースにview thisそれは正常に動作しますが、私はブラウザにこのスクリプトを実行すると、それは次のエラーを与える

Array 
(
    [status] => fail 
    [message] => Invalid UPC length 
)

答えて

3

残念ながら、彼らのAPIは、ドキュメントではかなり短いと思われる。

サイトはItem Lookup pageに言及コードの3つのタイプがあり:EAN/UCC-13

  • 12種類UPCコードの桁、又は
  • 8桁ため

    • 13桁タイプE(ゼロに抑えられた)UPCコードの場合。

    右ページには、これらの3つのタイプに言及した後、それはまた言う、8または12桁以外の

    ものは、UPCコードないです!

    13-digit EAN/UCC-13は、UPCのスーパーセットです。有効なUPCが含まれていますが、有効なUPCではない他の多くの値があります。 the Wikipedia article on EAN-13から

    最初の桁がゼロ、UPCに使用されるパターンを用いて符号化された6つの第1グループのすべての数字である場合は、それゆえUPCバーコードはまた、とEAN-13バーコードであります最初の桁はゼロに設定されます。

    これは、$upcから先行ゼロを削除すると、期待通りに機能していたと言われています。明らかにItem Lookupページには先行ゼロを削除するロジックがありますが、APIではそうではありません。

     
    Array 
    (
        [upc] => 639382000393 
        [pendingUpdates] => 0 
        [status] => success 
        [ean] => 0639382000393 
        [issuerCountryCode] => us 
        [found] => 1 
        [description] => The Teenager's Guide to the Real World by BYG Publishing 
        [message] => Database entry found 
        [size] => book 
        [issuerCountry] => United States 
        [noCacheAfterUTC] => 2011-01-22T14:46:15 
        [lastModifiedUTC] => 2002-08-23T23:07:36 
    ) 
    

    また、代わりにupcのparamを設定するには、eanのparamにオリジナルの13桁の値を設定することができますし、それも動作します。

  • 関連する問題