PHP使用SOAP調(diào)用API操作示例
本文實(shí)例講述了PHP使用SOAP調(diào)用API操作。分享給大家供大家參考,具體如下:
/*圖片轉(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ī)沒(méi)有pem文件
可以通過(guò)如下設(shè)置,忽略ssl驗(yàn)證
verify_peer:指定是否驗(yàn)證ssl,默認(rèn)為true
將verify_peer設(shè)為false
另外,允許引用外部xml實(shí)體
加libxml_disable_entity_loader(false);
語(yǔ)句
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程序沒(méi)有任何錯(cuò)誤,后端的數(shù)據(jù)庫(kù)也很正常,從網(wǎng)上查了很多資料,都是說(shuō)要修改proxy_read_timeout
,proxy_send_timeout
和proxy_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;
你可以看到上面是proxy_和fastcgi_兩種配置,就是說(shuō)如果你的nginx后面是proxy,就設(shè)置proxy相關(guān)的配置,如果是fastcgi就設(shè)置fastcgi相關(guān)的配置。
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- PHP程序員簡(jiǎn)單的開(kāi)展服務(wù)治理架構(gòu)操作詳解(二)
- PHP程序員簡(jiǎn)單的開(kāi)展服務(wù)治理架構(gòu)操作詳解(一)
- PHP中soap用法示例【SoapServer服務(wù)端與SoapClient客戶端編寫(xiě)】
- php中curl和soap方式請(qǐng)求服務(wù)超時(shí)問(wèn)題的解決
- PHP使用NuSOAP調(diào)用Web服務(wù)的方法
- PHP中soap的用法實(shí)例
- PHP使用SOAP擴(kuò)展實(shí)現(xiàn)WebService的方法
- PHP使用SOAP調(diào)用.net的WebService數(shù)據(jù)
- PHP Class SoapClient not found解決方法
- PHP實(shí)現(xiàn)Soap通訊的方法
- PHP程序員簡(jiǎn)單的開(kāi)展服務(wù)治理架構(gòu)操作詳解(三)
相關(guān)文章
PHP中用接口、抽象類、普通基類實(shí)現(xiàn)“面向接口編程”與“耦合方法”簡(jiǎn)述
邊學(xué)邊做的,為方便自己翻閱而發(fā)布,更為得到高人指點(diǎn)而發(fā)布,歡迎高手指點(diǎn)2011-03-03php+jQuery ajax實(shí)現(xiàn)的實(shí)時(shí)刷新顯示數(shù)據(jù)功能示例
這篇文章主要介紹了php+jQuery ajax實(shí)現(xiàn)的實(shí)時(shí)刷新顯示數(shù)據(jù)功能,結(jié)合實(shí)例形式分析了php結(jié)合jQuery ajax實(shí)時(shí)刷新讀取顯示數(shù)據(jù)庫(kù)數(shù)據(jù)相關(guān)操作技巧,需要的朋友可以參考下2019-09-09PHP中CURL方法curl_setopt()函數(shù)的參數(shù)分享
PHP中CURL方法curl_setopt()函數(shù)的使用介紹,需要深入了解curl_setopt的朋友可以參考下2013-01-01thinkphp Tp6經(jīng)常報(bào)錯(cuò) Call to undefined
在使用Tp6框架時(shí)經(jīng)常遇到"Call to undefined method"的錯(cuò)誤,這里就為大家分享一下具體的使用方法,需要的朋友可以參考下2023-08-08