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

composer下载插件
composer require nusoap/nusoap

  

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 @ 2024-03-19 10:36  怪-人  阅读(24)  评论(0编辑  收藏  举报