1

私は数日からこの問題に直面していますが、ネット上でも以前の質問(実際にはいくつかのエラーがありました)に対する答えも解決策も見つかりません。

それがシナリオです。パーセルを追加するか、挿入されたパーセルをリストするには、gls Web サービスを使用する必要があります。私はcurlを使用してクライアントを構築し、呼び出しを行っています。クラスのコードは次のとおりです。

/*Headers*/
public function buildGlsHeaders($glsCall,$gls_lenght,$soap_action)
{       
    //header soap 1.1
    $headers = array(
        "Content-Type: text/xml; charset=utf-8",
        "Content-Length: " . $gls_lenght,
        $soap_action,
        );

    return $headers;
}

/*Request*/
public function sendRequest($glsCall, $requestBody, $gls_lenght, $soap_action)
{
    $cookiePath = tempnam('/tmp', 'cookie');

    //build gls headers using variables passed via constructor as well as the gls call to use
    $headers = $this->buildGlsHeaders($glsCall, $gls_lenght, $soap_action);

    //initialise a CURL session
    $connection = curl_init();

    //set the server we are using 
    curl_setopt($connection, CURLOPT_URL, 'http://weblabeling.gls-italy.com/IlsWebService.asmx');

    //Time out
    curl_setopt($connection, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($connection, CURLOPT_TIMEOUT, 10);

    //set it to return the transfer as a string from curl_exec
    curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);

    //stop CURL from verifying the peer's certificate
    curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, false);

    //set method as POST
    curl_setopt($connection, CURLOPT_POST, true);

    //set the XML body of the request
    curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);

    //set the headers using the array of headers
    curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);

    //Header
    curl_setopt($connection, CURLINFO_HEADER_OUT, true);
    curl_setopt($connection, CURLOPT_HEADER, true);

    curl_setopt($connection, CURLOPT_COOKIEJAR, $cookiePath);

    //Send the Request
    $response = curl_exec($connection);

    print_r(curl_getinfo($connection));

    echo "\n" . 'Header Code: ' . curl_getinfo($connection, CURLINFO_HTTP_CODE) . "\n\n";

    //close the connection
    curl_close($connection); 

    //return the response
    return $response;
}

変数 $glsCall、$requestBody、$gls_lenght、$soap_action は、スクリプト自体から取得されます。

$soap_action = "SOAPAction: \"http://weblabeling.gls-italy.com/AddParcel\"";

$gls_lenght = strlen($xml); 

リクエストは次の行で送信されます。

/*AddParcel*/
$glsResponse = $gls->sendRequest('AddParcel', $xml, $gls_lenght, $soap_action);

/*ListSped*/
$glsResponse = $gls->sendRequest('ListSped', $xml, $gls_lenght, $soap_action);

現在、両方の呼び出しが同じ方法で構築されていますが、そのうちの 1 つがネストされています。

$Label = array(
                'XMLInfoParcel' => array(
                'Info' => array(
                    'SedeGls' => $SedeGls,
                    'CodiceClienteGls' => $CodiceClienteGls,
                    'PasswordClienteGls' => $PasswordClienteGls,                
                    'Parcel' => array(
                                       'CodiceContrattoGls' => $cod_cont,
                                       'RagioneSociale' => $rag_soc,
                                       'Indirizzo' => $delivery_indirizzo,
                                       'Localita' => $delivery_city,
                                       'Zipcode' => $data['delivery_postcode'],
                                       'Provincia' => $data['zone_code'],
                                       'Bda' => '',
                                       'DataDocumentoTrasporto' => '',
                                       'Colli' => '1',
                                       'Incoterm' => '',
                                       'PesoReale' => '1,00',
                                       'ImportoContrassegno' => $imp_cont,
                                       'NoteSpedizione' => $data['customers_telephone'],
                                       'TipoPorto' => 'F',
                                       'Assicurazione' => $ass_ins,
                                       'PesoVolume' => '',
                                       'TipoCollo' => $tipo_collo,
                                       'FrancoAnticipata' => '',
                                       'RiferimentoCliente' => '',
                                       'NoteAggiuntive' => '',
                                       'CodiceClienteDestinatario' => '',
                                       'Email' => '',
                                       'Cellulare1' => $telefono,
                                       'Cellulare2' => '',
                                       'ServiziAccessori' => '',
                                       'ModalitaIncasso' => $mod_inc    
                                  ),),),                                
                );

もう1つはそうではありません:

/*Request*/
    $listsp = array(
                    'SedeGls' => $SedeGls,
                    'CodiceClienteGls' => $CodiceClienteGls,
                    'PasswordClienteGls' => $PasswordClienteGls 
                    );

それらは要求された入力です:

AddParcel

ここに画像の説明を入力

リスト速度

ここに画像の説明を入力

ご覧のとおり、入力形式が異なります。AddParcel "string" のスキーマは次のとおりです。

ここに画像の説明を入力

それは他の分野に続き、

       </Parcel>
  </Info>

ListSped 呼び出しは完全に機能しますが、AddParcel は機能しません。常に 400 Bad 要求ヘッダーを返します。xml を GLS IT サポートに送信したので、xml は正しいと思います。直接アップロードすると機能することが確認されています。残念ながら、彼らは php をサポートしていません。

ネストされた配列が問題の原因であると考えていましたが、xml 構造を変更すると webservice が正しく応答するため、「xml 構造が間違っています」という可能性はありません。

私は周りを見回しており、同じ問題を抱えている他の人を見つけましたが、解決策は見つかりませんでした。本当に何も知らない他の言語を使用する代わりに、スクリプトをphpで動作させたいと思います。

4

1 に答える 1

1

要求された入力の図 'AddParcel' でわかるように、入力自体は文字列です。

次のようにフォーマットする必要があることに気付きました。

    &lt;Info&gt;&lt;SedeGls&gt;XXX&lt;/SedeGls&gt;&lt;CodiceContrattoGls&gt;XXX&lt;/CodiceContrattoGls&gt; <!--and so on-->
于 2012-11-06T14:00:11.100 に答える