使用laravel生成令牌的军刀api

时间:2017-05-02 07:33:32

标签: api laravel-5 sabre

我要将saber soap api与laravel集成,第一步是生成令牌,有人可以建议,用什么策略来调用saber api for token。因为我打算使用GuzzleHttp \ Client进行api通话,但不知道如何设置。

 public function getApi($method,$body='')
    {


try {


 $client = new GuzzleClient();

            $xml = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope>
    <SOAP-ENV:Header>
        <eb:MessageHeader eb:version="1">
            <eb:From>
                <eb:PartyId>Client</eb:PartyId>
            </eb:From>
            <eb:To>
                <eb:PartyId>SWS</eb:PartyId>
            </eb:To>
            <eb:CPAId>'.base64_encode('8cpd').'</eb:CPAId>
            <eb:ConversationId>1234</eb:ConversationId>
            <eb:Service>Session</eb:Service>
            <eb:Action>TokenCreateRQ</eb:Action>
            <eb:MessageData>
                <eb:MessageId>1234</eb:MessageId>
                <eb:Timestamp>2015-01-01T00:00:00</eb:Timestamp>
            </eb:MessageData>
        </eb:MessageHeader>
        <wsse:Security>
            <wsse:UsernameToken>
                <wsse:Username>'.base64_encode($this->username).'</wsse:Username>
                <wsse:Password>'.base64_encode($this->password).'</wsse:Password>
               <Organization>'.base64_encode('8cpd').'</Organization>
            </wsse:UsernameToken>
        </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <sws:TokenCreateRQ Version="1.0.0" />
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

            $request = $client->post('https://api.test.sabre.com/v2/auth/token', [
              'body' => [
                'xml' => $xml
              ]
            ]);



            $xml = simplexml_load_string($request->getBody());
            return json_encode($xml);

        } catch (\GuzzleHttp\Exception\ClientException $e) {

            dd($e);
            return $e;
        }

0 个答案:

没有答案