怎么在PHP中利用SOAP调用API
今天就跟大家聊聊有关怎么在PHP中利用SOAP调用API,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
具体如下:
/*图片转换为base64格式编码*/ functionbase64EncodeImage($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=newSoapClient($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);
注:出现提示:Fatal error: Class 'SoapClient' not found的情况,可参考《PHP Class SoapClient not found解决方法》
附:SOAP-ERROR: Parsing WSDL:Couldn't load from “xxxxxxx” 解决方案
用php的soapclient连接第三方的webservice,是https的,连接报错SOAP-ERROR: Parsing WSDL:Couldn't load from “xxxxxxx”
首先排查 php的soap扩展是否安装
openssl扩展
服务器本身安装openssl
排除第三方对本服务器的IP限制
最后怀疑是https需要ssl验证,而本机没有pem文件
可以通过如下设置,忽略ssl验证
verify_peer:指定是否验证ssl,默认为true
将verify_peer设为false
另外,允许引用外部xml实体
加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=newSoapClient("https://urlToSoapWs", array( 'stream_context'=>$streamContext ));
禁止引用外部xml实体
libxml_disable_entity_loader(true);
nginx 报错 upstream timed out (110: Connection timed out)解决方案
nginx每隔几个小时就会报下面的错误:
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“
报这个错误之后,整个服务器就不响应了,但是nginx后面的webpy程序没有任何错误,后端的数据库也很正常,从网上查了很多资料,都是说要修改proxy_read_timeout
,proxy_send_timeout
和proxy_buffer
几个相关设置的值。
如下配置,要放在server配置节之内
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;
看完上述内容,你们对怎么在PHP中利用SOAP调用API有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注恰卡编程网行业资讯频道,感谢大家的支持。
推荐阅读
-
php字符串增加1如何实现
php字符串增加1如何实现这篇“php字符串增加1如何实现”文章的...
-
php如何判断字符串是否有中文
-
php如何实现字符串去掉头尾
-
php字符串的组成是什么
php字符串的组成是什么这篇文章主要讲解了“php字符串的组成是什...
-
php如何让Swoole/Pool进程池实现Redis持久连接
php如何让Swoole/Pool进程池实现Redis持久连接本篇...
-
php字符串长度不一致如何解决
-
php时区不正确如何解决
-
php+fread()乱码如何解决
php+fread()乱码如何解决本篇内容介绍了“php+frea...
-
php explode报错如何解决
-
linux Centos如何安装PHP7
linuxCentos如何安装PHP7今天小编给大家分享一下li...