2016-08-03 5 views
0

どうすればこのように見えるPHPのSOAPリクエストを作成できますか?私はPHPのカールで応答を得ることができません。しかし、フィドラーのWebデバッガーは、コードで本当にうまく動作しています。ここでCURLが動作していないPHPでのSoapクライアントリクエスト

は生のリクエストです:

POST http://195.230.180.189:8280/services/TopupService?wsdl HTTP/0.9 ホスト:195.230.180.189:8280 のContent-Length:691 PHPのカール要求で

<?xml version="1.0"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:top="http://www.inew-cs.com/mvno/integration/TopupService/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <top:TopupRequest> 
     <amount>1</amount> 
     <amountUnitRelation>1</amountUnitRelation> 
     <subscriber> 
     <msisdn>8801701340002</msisdn> 
     </subscriber> 
     <source> 
     <distributorId>PayWell</distributorId> 
     </source> 
     <referenceId>12345</referenceId> 
     <transactionId>09876543</transactionId> 
    </top:TopupRequest> 
    </soapenv:Body> 
    </soapenv:Envelope> 

$url="http://195.230.180.189:8280/services/TopupService?wsdl"; 
    $xml='<?xml version="1.0"?> 
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:top="http://www.inew-cs.com/mvno/integration/TopupService/"> 
     <soapenv:Header/> 
     <soapenv:Body> 
     <top:TopupRequest> 
     <amount>1</amount> 
     <amountUnitRelation>1</amountUnitRelation> 
     <subscriber> 
      <msisdn>8801701340002</msisdn> 
     </subscriber> 
     <source> 
      <distributorId>100</distributorId> 
     </source> 
     <referenceId>12345</referenceId> 
     <transactionId>09876543</transactionId> 
     </top:TopupRequest> 
     </soapenv:Body> 
     </soapenv:Envelope>'; 
    $headers = array(
     "Content-type: text/xml", 
     "Content-length: " . strlen($xml), 
     "Connection: close" 
    ); 
    $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL,$url); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 

    echo $result = curl_exec($ch); 
    if(curl_exec($ch) === false) 
    { 
     echo 'Curl error: ' . curl_error($ch); 
    } 
    else 
    { 
     //echo 'Operation completed without any errors'; 
    } 
    // Close handle 
    curl_close($ch); 
+1

http://php.net/manual/en/class.soapclient.php –

答えて

1

あなたはそのURLに投稿しないでください。これはサービスエンドポイントではなく、提供された操作を定義するWSDLです。

PHPのSoapClientクラスを使用すると、簡単にSOAPリクエストを構築することができます:

$wsdl = 'http://195.230.180.189:8280/services/TopupService?wsdl'; 

$options = [ 
    'trace' => true, 
    'cache' => WSDL_CACHE_NONE, 
    'exceptions' => true 
]; 

$client = new SoapClient($wsdl, $options); 

$payload = [ 
    'amount' => 1, 
    'amountUnitRelation' => 1, 
    'subscriber' => [ 
     'msisdn' => '8801701340002' 
    ], 
    'source' => [ 
     'distributorId' => 'PayWell' 
    ], 
    'referenceId' => '12345', 
    'transactionId' => '09876543', 
]; 

$response = $client->topup($payload); 

与えられたWSDLを解析した後、$clientは今<wsdl:operation>で定義されている方法topupを、持っています。

+0

あなたはこのよう $オプション=配列( 'トレース' => trueの場合、 'キャッシュ' => WSDL_CACHE_NONEをしようとすることを意味しました、 '例外' => true ); $ client =新しいSoapClient($ wsdl、$ options); $ペイロード=配列( '量' => 1、 'amountUnitRelation' => 1、 '加入' =>配列( 'MSISDN' => '8801701340002' )、 'ソース' =>配列( 'distributorId' => 'PayWell' )、 'referenceId' => '12345'、 'transactionId' => '09876543' ); print $ response = $ client-> topup($ payload); – Ipshita

+0

あなたの提案した方法を試しましたが、うまくいきませんでした。私は上記の方法を試したときに致命的なエラーが発生しました:Uncaught SoapFault例外:[HTTP] /var/www/html/pwl/paywell_crons/gp_plus_api_test.php:142でホストに接続できませんでしたスタックトレース:#0 [内部関数] :SoapClient-> topup(配列)#3 {main}スローイン/スローされた(配列)#2 /var/www/html/pwl/paywell_crons/gp_plus_api_test.php(142):SoapClient-> var/www/html/pwl/paywell_crons/gp_plus_api_test.php – Ipshita

関連する問題