2016-08-03 3 views
0

어떻게하면 이런 모양으로 PHP 비누 요청을 만들 수 있습니까? php curl으로 응답을 얻을 수 없습니다. 그러나 피들러 (Fiddler) 웹 디버거는 코드와 함께 잘 작동합니다. 여기 PHP에서 CURL이 작동하지 않는 비누 클라이언트 요청

원시 요청입니다 :

POST http://195.230.180.189:8280/services/TopupService?wsdl HTTP/0.9 호스트 : 195.230.180.189:8280 콘텐츠 길이 : 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 클래스는 쉽게 비누 요청을 구축 할 수 있습니다 :

$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

이 방법을 $ 옵션 = 배열 ​​( '추적'을 시도하는 것을 의미했다 => 사실, '캐시'=> WSDL_CACHE_NONE , 'exceptions'=> true ); $ client = 새 SoapClient ($ wsdl, $ options); $ 페이로드 = 배열 ​​( '양'=> 1 'amountUnitRelation'=> 1 '가입자'=> 어레이 ( 'MSISDN'=> '8801701340002' ) '소스'=> 어레이 ( 'distributorId'=> 'PayWell' ), 'referenceId'=> '12345', 'transactionId'=> '09876543' ); print $ response = $ client-> topup ($ payload); – Ipshita

+0

당신의 제안 된 방법을 시도했지만 효과가 없습니다. 위의 방법을 시도했을 때 치명적인 오류가 발생했습니다 : SoapFault 예외가 발견되지 않았습니다 : [HTTP] /var/www/html/pwl/paywell_crons/gp_plus_api_test.php:142에서 호스트에 연결할 수 없습니다. 스택 추적 : # 0 [내부 기능] : SoapClient -> topup (배열) # 3 {main} 던져 넣기/끄기 : SoapClient -> __ doRequest ('__ call ('topup ', Array) # 2 /var/www/html/pwl/paywell_crons/gp_plus_api_test.php(142) var/www/html/pwl/paywell_crons/gp_plus_api_test.php – Ipshita