TP6 使用 nusoap为第三方webservice调用插件

composer下载插件
1
composer require nusoap/nusoap

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use NuSoap\Client\Client;
 
class Index extends BaseController
{
    /**
     *
     */
    public function index()
    {
        // WebService的WSDL地址
        $wsdl = 'http://xxx.ygys.net/ResumeService.asmx?wsdl';
        $soapclient = new Client($wsdl,true);
        if ($soapclient->getError()) {
            echo 'Error: '.$soapclient->getError();
        }else{
            $soapclient->soap_defencoding='utf-8';
            $soapclient->decode_utf8=false;
            $soapclient->xml_encoding='utf-8';
            // 要调用的方法名
            $methodName = 'hello';
            // 调用方法需要传递的参数
            $PSize = filesize('./123.docx');
            $fileData = fread(fopen('./123.docx', "r"), $PSize);
            $content = base64_encode($fileData); // 将字节数组进行base64编码,以便于网络传输的安全性;
            $username = 'u102xxx'; // xxxx 为分配的用户名
            $pwd = 'gh202ccccc'; // xxxxxx 为分配的密码
            $ext = '.docx'; // 读取时文件是什么格式,此处填写什么,比如本例读取的是pdf文件,则此处写“.pdf”
            $params = array('username' => $username,'pwd' => $pwd,'content' => $content,'ext'=> $ext);
            // 调用远程方法
            $result = $soapclient->call($methodName, $params);
            // 检查调用结果
            if ($soapclient->fault) {
                echo 'Fault: ';
                dump($result);
            } else {
                // 输出或处理结果
                if ($soapclient->getError()) {
                    echo 'Error: '.$soapclient->getError();
                } else {
                    echo 'Result: ';
                    dump(json_decode($result['TransResumeByJsonStringForFileBase64Result'],true));
                }
            }
        }
    }

  

posted @   怪-人  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
点击右上角即可分享
微信分享提示