順豐bsp訂單號查詢接口soap的請求示例

字號:


    在一些接口的設(shè)計中有時用到了soap方式的請求,比如順豐bsp的接口。
    我嘗試不同方式的post方式請求,要么完全請求不到東西,要么接收到亂碼,均以失敗告終。
    針對順豐接口的soap請求的核心代碼分享如下:
    代碼如下:
    /**
    * 發(fā)送soap請求
    */
    private function _soap()
    {
    $client = new soapclient($this->serviceurl);
    $info = new stdclass();
    $info->arg0 = $this->xml;
    $param = array($info);
    $response = $client->__call(“sfexpressservice”,$param);
    return $response->return ;
    }
    /**
    * 拼接出請求的xml
    */
    public function createxml()
    {
    $xml = ‘<request service=”routeservice” lang=”zh-cn”>
    <head>’.$this->user.’,’.$this->password.’</head>
    <body>
    <routerequest tracking_type=”1″ method_type=”1″ tracking_number=”‘.$this->invoice_no.’” />
    </body>
    </request>’;
    $this->xml = $xml;
    }
    提示:
    1.$this->serviceurl 順豐分配的bsp請求地址,注意是?wsdl的地址
    2.$this->user,$this->password 即是順豐分配的id和校驗碼
    3.返回的return是一個xml的string,你可能需要simplexml_load_string來解析。