20106 月28
PHP webservice客户端 推送文章和附件(xsd:base64Binary)
<?php //设定字符集 header('Content-Type:text/html;charset=utf-8'); //调用webserver接口class类 require_once('./lib/nusoap.php'); require_once('Article.class.php'); //封装文章信息类 require_once('Attribute.class.php'); //封装字段attr类 require_once('Appendix.class.php'); //封装附件信息类 //-------------------封装推送信息内容开始 $a1 = new Attribute(); $a1->setAttrName('aaa'); $a1->setAttrValue('aaaaa'); $a2 = new Attribute(); $a2->setAttrName('bbb'); $a2->setAttrValue('bbbbbb'); $ar[] = $a1; $ar[] = $a2; echo $ar[0]->getAttrName('aaa'); $Article = new Article(); $Article->setArticleContent(mb_convert_encoding('vvvvvvvvvvv<a href="a.txt">a.txt</a>...<img src="tmp.jpg">','UTF-8','GBK')); //文章正文 $Article->setArticleTitle(mb_convert_encoding("12212AAABBBABAAA".date('Ymd'),'UTF-8','GBK')); //文章题目 $Article->setAttr($ar); //文章定制属性组 $Article->setCreateTime(date('YmdHis')); //文章创立时间 $Article->setDepartment("tongjiju"); //用户部门 $Article->setDescription("description"); //文章描述 $Article->setImportant("0"); //文章级别 $Article->setKeyword("keyword"); //文章关键字 $Article->setLoginName("tongjiju"); //用户登录名 $Article->setModifyTime(date('YmdHis')); //文章修改时间 $Article->setPassword("tongjiju"); //用登录口令 $Article->setWebName(mb_convert_encoding("市政府子网站群二期 > 市统计局 > 市情简介",'UTF-8','GBK')); //网站的名称 $Article->setCommendId(0); $client = new nusoap_client("http://221.122.*.*:7006/cmsweb/services/TransferArticle?wsdl", true); $err = $client->getError(); if ($err) { echo "<h2>Constructor error</h2><pre>". $err ."</pre>"; } $godata=''; //文章中存在附件 'finishMark'=>false------------------------------------------------------------- $godata=array('article'=>$Article,'finishMark'=>false); $result = $client->call("transferContent", $godata); if ($client->fault) { echo "<h2>Fault</h2><pre>"; print_r($result); echo "</pre>"; } else { $err = $client->getError(); if ($err) { echo "<h2>Error</h2><pre>" . $err . "</pre>"; } else { echo "<h2>Result</h2><pre>"; print_r($result); echo "</pre>"; } } $aid=$result['transferContentReturn']; if ($aid){ //第一个附件 'finishMark'=>false------------------------------------------------------------- $filepath='a.txt'; $fp=fopen($filepath, "rb"); $filedata=fread($fp, filesize($filepath)); fclose($fp); $Appendix = new Appendix(); $Appendix->setFileContent(base64_encode($filedata)); $Appendix->setFileName('a.txt'); $Appendix->setFileType('txt'); $godataf=array('aid'=>$aid,'apd'=>$Appendix,'finishMark'=>false); $resultf = $client->call("transferAppendix", $godataf); echo '<br><br>'; echo "<h2>Result_f</h2><pre>"; print_r($resultf); echo "</pre>"; //最后附件 'finishMark'=>true------------------------------------------------------------- $filepath2='tmp.jpg'; $fp2=fopen($filepath2, "rb"); $filedata2=fread($fp2, filesize($filepath2)); fclose($fp2); $Appendix2 = new Appendix(); $Appendix2->setFileContent(base64_encode($filedata2)); $Appendix2->setFileName('tmp.jpg'); $Appendix2->setFileType('image_title');//image_title 此图片为标题图 $godataf2=array('aid'=>$aid,'apd'=>$Appendix2,'finishMark'=>true); $resultf2 = $client->call("transferAppendix", $godataf2); echo '<br><br>'; echo "<h2>Result_f2</h2><pre>"; print_r($resultf2); echo "</pre>"; } ?>
本文地址:https://wizzer.cn/archives/53 , 转载请保留.