前提・実現したいこと
PHPを用いて、SOAP通信を実現したいです。
現状通信元のサーバがPHP・SOAPどちらも利用可能であることは確認済みです。
ただ、通信しようとしているAPI側がヘッダーに認証情報を設定しないと
いけないのですが、いろいろと調べて試してみたものの
SOAPヘッダがエラーと返ってきている状況です。
私自身JavaやRubyなどの開発経験はあるのですが、
PHP自体は疎いので、色々とおかしな点があるかもしれません。
そういった点も含めて全体的に見ていただけたら幸いです。
下記ソースのconfig.txtには、認証に必要な
logId,logArgment,apiKey が記載されております。
■WSDL情報
https://ax.ebis.ne.jp/v2.3/services/AdService?wsdl
発生している問題・エラーメッセージ
result
1<?xml version='1.0' encoding='utf-8'?> 2 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 3 <soapenv:Body> 4 <soapenv:Fault> 5 <faultcode>soapenv:EAW10000</faultcode> 6 <faultstring>SOAPヘッダが不正です.</faultstring><detail /> 7 </soapenv:Fault> 8 </soapenv:Body> 9</soapenv:Envelope>
error
1connection error
該当のソースコード
PHP
1<?php 2 3class RequestParams { 4 public $startDate = ''; 5 public $endDate = ''; 6 public $conversionIds = array(); 7 public $adGroup1Ids = array(); 8 public $adGroup2Ids = array(); 9 public $mediaIds = array(); 10 public $adIds = array(); 11 public $terminalTypes = array(); 12 public $keyward = ''; 13 public $includeNaturalConversion = false; 14} 15 16class HeadParams { 17 public $logId; 18 public $logArgument; 19 public $apiKey; 20} 21 22$filename = './config.txt'; 23$file = fopen($filename, 'r'); 24$key_ary = array(); 25if($file) { 26 while($line = fgets($file)) { 27 array_push($key_ary, $line); 28 } 29} else { 30 file_put_contents("./error.txt", 'config read error'); 31} 32fclose($file); 33 34$wsdl = 'https://ax.ebis.ne.jp/v2.3/services/AdService?wsdl'; 35$ns = 'http://entity.ws.extreme.ebis.ne.jp/xsd'; 36$opt = ['trace'=>1]; 37 38$searchcondition = new RequestParams(); 39$searchcondition->startDate = '2020/01/01'; 40$searchcondition->endDate = '2020/01/01'; 41$searchcondition->mediaIds = array(77); 42 43$hp = new HeadParams(); 44$hp->logId = $key_ary[0]; 45$hp->logArgument = $key_ary[1]; 46$hp->apiKey = $key_ary[2]; 47 48try{ 49 $client = new SoapClient($wsdl, $opt); 50 51 $header = new SoapHeader($ns, 'HoteiAuthHeader', $hp); 52 $client->__setSoapHeaders($header); 53 54} catch (Exception $e) { 55 file_put_contents("./error.txt", 'wsdl read error'); 56} 57 58try{ 59 $result = $client->getAdConversionAttributesCount($searchcondition); 60} catch (SoapFault $e) { 61 file_put_contents("./error.txt", 'connection error'); 62} 63 64$resultstr = $client->__getLastResponse(); 65file_put_contents("./result.txt", $resultstr); 66 67?> 68 69<?php 70 echo 'FINISH'; 71?>
試したこと
上記のコードからは何も試せていないです。
補足情報(FW/ツールのバージョンなど)
SOAP 1.1
PHP Version 5.4.45
あなたの回答
tips
プレビュー