溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么在PHP中利用SOAP調(diào)用API

發(fā)布時(shí)間:2021-03-25 17:08:29 來源:億速云 閱讀:197 作者:Leah 欄目:開發(fā)技術(shù)

今天就跟大家聊聊有關(guān)怎么在PHP中利用SOAP調(diào)用API,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

具體如下:

/*圖片轉(zhuǎn)換為 base64格式編碼*/
function base64EncodeImage($image_file)
{
  $base64_image = '';
  $image_info = getimagesize($image_file);
  $image_data = fread(fopen($image_file, 'r'), filesize($image_file));
  //$base64_image = 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
  $base64_image = chunk_split(base64_encode($image_data));
  return $base64_image;
}
$strPhotoFront_base64 = base64EncodeImage("static/img/a.png");
$strPhotoRear_base64 = base64EncodeImage("static/img/b.png");
$paras["strPhotoFront"] = $strPhotoFront_base64;
$paras["strPhotoRear"] = $strPhotoRear_base64;
$paras["strSecretKey"] = "";
$wsdl = "";
$client = new SoapClient($wsdl);
$soapParas = array($paras);
$outString = $client->__soapCall("UploadPhotoId", $soapParas);
$obj = simplexml_load_string($outString->UploadPhotoIdResult->any);
echo($obj->ExtraInfo);
echo "<br/>";
echo($obj->ExtraCode);
echo "<br/>";
echo($obj->Code);
echo "<br/>";
echo($obj->Message);

注:出現(xiàn)提示:Fatal error: Class 'SoapClient' not found的情況,可參考《PHP Class SoapClient not found解決方法》

附:SOAP-ERROR: Parsing WSDL:Couldn't load from “xxxxxxx” 解決方案

用php的soapclient連接第三方的webservice,是https的,連接報(bào)錯(cuò)SOAP-ERROR: Parsing WSDL:Couldn't load from “xxxxxxx”

首先排查 php的soap擴(kuò)展是否安裝

openssl擴(kuò)展

服務(wù)器本身安裝openssl

排除第三方對(duì)本服務(wù)器的IP限制

最后懷疑是https需要ssl驗(yàn)證,而本機(jī)沒有pem文件

可以通過如下設(shè)置,忽略ssl驗(yàn)證

verify_peer:指定是否驗(yàn)證ssl,默認(rèn)為true

將verify_peer設(shè)為false

另外,允許引用外部xml實(shí)體

libxml_disable_entity_loader(false);語句

libxml_disable_entity_loader(false);
$opts = array(
  'ssl'  => array(
      'verify_peer'     => false
    ),
  'https' => array(
      'curl_verify_ssl_peer' => false,
      'curl_verify_ssl_host' => false
   )
);
$streamContext = stream_context_create($opts);
$client = new SoapClient("https://urlToSoapWs",
 array(
   'stream_context'  => $streamContext
 ));

禁止引用外部xml實(shí)體

libxml_disable_entity_loader(true);

nginx 報(bào)錯(cuò) upstream timed out (110: Connection timed out)解決方案

nginx每隔幾個(gè)小時(shí)就會(huì)報(bào)下面的錯(cuò)誤:

2013/05/18 21:21:36 [error] 11618#0: *324911 upstream timed out (110: Connection timed out) while reading response header from upstream,
client: 42.62.37.56, server: localhost, request: “GET /code-snippet/2747/HTML5-Canvas-usage HTTP/1.0”,
upstream: “fastcgi://127.0.0.1:9002”, host: “outofmemory.cn”, referrer: “http://outofmemory.cn/code-snippet/tagged/canvas“

報(bào)這個(gè)錯(cuò)誤之后,整個(gè)服務(wù)器就不響應(yīng)了,但是nginx后面的webpy程序沒有任何錯(cuò)誤,后端的數(shù)據(jù)庫也很正常,從網(wǎng)上查了很多資料,都是說要修改proxy_read_timeout,proxy_send_timeoutproxy_buffer幾個(gè)相關(guān)設(shè)置的值。

如下配置,要放在server配置節(jié)之內(nèi)

large_client_header_buffers 4 16k;
client_max_body_size 30m;
client_body_buffer_size 128k;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
proxy_buffer_size 64k;
proxy_buffers   4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
fastcgi_connect_timeout 300;
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers   4 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_temp_file_write_size 64k;

看完上述內(nèi)容,你們對(duì)怎么在PHP中利用SOAP調(diào)用API有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI