PHP人才网站对接内蒙古自治区四位一体就业服务云平台
2021年上半年,內蒙古自治區人社廳發了《關于進一步加強“四位一體”就業服務云平臺推廣應用工作的通知》,要求各盟市人才網站與自治區四位一體就業服務云平臺實現以接口方式對接。通遼市率先完成通遼市人才網的對接工作,這里把其中涉及的PHP和SOAP相關的技術難點和解決方案分享給大家,共同學習,共同進步。
文章目錄
- 前言
- 一、PHP通過SoapClient調用服務端接口
- 二、PHP利用wsdl創建標準webservice
- 1.創建文件SoapDiscovery.class.php
- 2.提供服務的類或者函數
- 3.生成WSDL
- 4.創建webservice服務端程序
- 5.測試
- 總結
前言
通遼市人才網是通遼市人社局主辦的官方招聘求職網站,是通遼地區最大的人才招聘門戶網站,我作為本次與自治區四位一體就業服務云平臺進行api對接的技術負責人,通過本次對接,也學習了不少的內容。上次與國家就業在線對接,難點主要是PHP版本的AES加密算法和HTTP CALLER以及中文亂碼的處理,而本次則是PHP版本的SOAP和WebService,每次都是新的學習內容,讓我在體制內也過了一把當程序員的癮-。
提示:以下是本篇文章正文內容,下面案例可供參考
一、PHP通過SoapClient調用服務端接口
通遼市人才網向自治區四位一體就業服務云平臺同步企業信息、職位信息和招聘會信息,均屬于這種模式,在本地創建一個SoapClient,然后調用服務端提供的同步接口,代碼如下(示例):
$soap = new SoapClient("http://xxxxxx/xxxx/xxxx/WebserviceSWYT?wsdl"); $result = $soap->setDb21($reqString);二、PHP利用wsdl創建標準webservice
自治區四位一體就業服務云平臺向通遼市人才網同步簡歷信息,屬于這種模式,在通遼市人才網本地利用wsdl創建一個WebService,然后提供wsdl地址和對外接口給四位一體就業服務云平臺調用,代碼如下(示例):
1.創建文件SoapDiscovery.class.php
代碼如下(示例):
<pre name="code" class="php"><?php/*** Copyright (c) 2005, Braulio José Solano Rojas* All rights reserved.* * Redistribution and use in source and binary forms, with or without modification, are* permitted provided that the following conditions are met:* * Redistributions of source code must retain the above copyright notice, this list of* conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of* conditions and the following disclaimer in the documentation and/or other materials* provided with the distribution. * Neither the name of the Solsoft de Costa Rica S.A. nor the names of its contributors may* be used to endorse or promote products derived from this software without specific* prior written permission.* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.* ** @version $Id$* @copyright 2005 *//*** SoapDiscovery Class that provides Web Service Definition Language (WSDL).* * @package SoapDiscovery* @author Braulio José Solano Rojas* @copyright Copyright (c) 2005 Braulio José Solano Rojas* @version $Id$* @access public**/ class SoapDiscovery {private $class_name = '';private $service_name = '';/*** SoapDiscovery::__construct() SoapDiscovery class Constructor.* * @param string $class_name* @param string $service_name**/public function __construct($class_name = '', $service_name = '') {$this->class_name = $class_name;$this->service_name = $service_name;}/*** SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.* * @return string**/public function getWSDL() {if (empty($this->service_name)) {throw new Exception('No service name.');}$headerWSDL = "<?xml version=\"1.0\" ?>\n";$headerWSDL.= "<definitions name=\"$this->service_name\" targetNamespace=\"urn:$this->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:$this->service_name\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n";$headerWSDL.= "<types xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />\n";if (empty($this->class_name)) {throw new Exception('No class name.');}$class = new ReflectionClass($this->class_name);if (!$class->isInstantiable()) {throw new Exception('Class is not instantiable.');}$methods = $class->getMethods();$portTypeWSDL = '<portType name="'.$this->service_name.'Port">';$bindingWSDL = '<binding name="'.$this->service_name.'Binding" type="tns:'.$this->service_name."Port\">\n<soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" />\n";$serviceWSDL = '<service name="'.$this->service_name."\">\n<documentation />\n<port name=\"".$this->service_name.'Port" binding="tns:'.$this->service_name."Binding\"><soap:address location=\"http://".$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['PHP_SELF']."\" />\n</port>\n</service>\n";$messageWSDL = '';foreach ($methods as $method) {if ($method->isPublic() && !$method->isConstructor()) {$portTypeWSDL.= '<operation name="'.$method->getName()."\">\n".'<input message="tns:'.$method->getName()."Request\" />\n<output message=\"tns:".$method->getName()."Response\" />\n</operation>\n";$bindingWSDL.= '<operation name="'.$method->getName()."\">\n".'<soap:operation soapAction="urn:'.$this->service_name.'#'.$this->class_name.'#'.$method->getName()."\" />\n<input><soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</input>\n<output>\n<soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</output>\n</operation>\n";$messageWSDL.= '<message name="'.$method->getName()."Request\">\n";$parameters = $method->getParameters();foreach ($parameters as $parameter) {$messageWSDL.= '<part name="'.$parameter->getName()."\" type=\"xsd:string\" />\n";}$messageWSDL.= "</message>\n";$messageWSDL.= '<message name="'.$method->getName()."Response\">\n";$messageWSDL.= '<part name="'.$method->getName()."\" type=\"xsd:string\" />\n";$messageWSDL.= "</message>\n";}}$portTypeWSDL.= "</portType>\n";$bindingWSDL.= "</binding>\n";//return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>');//生成wsdl文件,將上面的return注釋$fso = fopen($this->class_name . ".wsdl" , "w"); fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '</definitions>')); }/*** SoapDiscovery::getDiscovery() Returns discovery of WSDL.* * @return string**/public function getDiscovery() {return "<?xml version=\"1.0\" ?>\n<disco:discovery xmlns:disco=\"http://schemas.xmlsoap.org/disco/\" xmlns:scl=\"http://schemas.xmlsoap.org/disco/scl/\">\n<scl:contractRef ref=\"http://".$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['PHP_SELF']."?wsdl\" />\n</disco:discovery>";} }?>2.提供服務的類或者函數
創建文件swyt_rcv_down_msg.class.php,里面有一個接收信息的接口dd03ByPerson
<?phpheader("content-type:text/html;charset=utf-8");class swyt_rcv_msg{public function dd03ByPerson ($strDd03){$json_data['code'] = "1"; //$json_data['message'] = "成功"; //$req['data'] = $json_data;$reqString = json_encode($req,JSON_UNESCAPED_UNICODE);return $reqString;}}3.生成WSDL
創建文件swyt_server.php,運行即可生成一個swyt_rcv_msg.wsdl文件:
<?phpheader("content-type:text/html;charset=utf-8");include("swyt_rcv_down_msg.class.php");include("SoapDiscovery.class.php");$disco = new SoapDiscovery('swyt_rcv_msg','swyt_rcv_msg');$disco->getWSDL(); ?>4.創建webservice服務端程序
將swyt_server.php文件的內容清空,復制以下代碼進去::
<?phpheader("content-type:text/html;charset=utf-8");include("swyt_rcv_down_msg.class.php");$objSoapServer = new SoapServer("swyt_rcv_msg.wsdl");//swyt_rcv_msg.wsdl是剛創建的wsdl文件$objSoapServer->setClass("swyt_rcv_msg");//注冊swyt_rcv_msg類的所有方法$objSoapServer->handle();//處理請求 ?>5.測試
代碼如下(示例),傳入地址填寫swyt_rcv_msg.wsdl文件里面這個地址:
總結
最后我發一下通遼市人才網在內蒙古自治區四位一體就業服務云平臺上面的截圖,職位信息每天都會自動同步,極大地節約的企業的招聘成本,避免二次錄入,提高了企業的招聘效率和擴展了企業的宣傳面。
總結
以上是生活随笔為你收集整理的PHP人才网站对接内蒙古自治区四位一体就业服务云平台的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Airtest入门及多设备管理总结
- 下一篇: 微信小程序同步方法,方法内顺序从上至下依