· 4 years ago · Aug 24, 2021, 08:40 PM
1/* Metodo para a primeira Eta da Api Comprovei */
2 public static function comproveiApiEtapa1($chaves, $route_id){
3
4 /* Aqui pegamos as informações do motorista */
5 $routes = Routes::find($route_id);
6 $motorista = Driver::find($routes->driver_id);
7
8
9 /* Estrutura XML que será enviar para a Api */
10 $estruturaXml = "
11
12 <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:web='WebServiceComprovei' xmlns:web1='WebServiceComprovei:uploadRouteUsingDocumentKey'>
13 <soapenv:Header>
14 <web:Credenciais>
15 <web:Usuario>wd.profarma.ws</web:Usuario>
16 <web:Senha>Q77X6WUV9@0abo!aDZMBOfAwN2ecEkIz</web:Senha>
17 </web:Credenciais>
18 </soapenv:Header>
19 <soapenv:Body>
20 <web1:uploadRouteUsingDocumentKey>
21 <web1:Rotas>
22 <web1:Rota numero='".$route_id."'>
23 <web1:Data>".date("Ymd")."</web1:Data>
24 <web1:Transportadora>
25 <!-- usar cnpj da transportadora como codigo -->
26 <web1:Codigo>07442020000161</web1:Codigo>
27 <web1:Razao>WD TRANSPORTES RODOVIARIOS EIRELI</web1:Razao>
28 </web1:Transportadora>
29 <web1:Motorista>
30 <!-- usar cpf do motorista como usuario -->
31 <web1:Usuario>".$motorista->cnpj_cpf."</web1:Usuario>
32 <web1:PlacaVeiculo>".$motorista->car_licenseplate."</web1:PlacaVeiculo>
33 <web1:Nome>".$motorista->name."</web1:Nome>
34 <web1:Telefone>".$motorista->mobile_phonenumber ."</web1:Telefone>
35 </web1:Motorista>
36 <!-- Fixo D porque nesta primeira fase teremos somente trechos de distribuicao -->
37 <web1:TipoRota>D</web1:TipoRota>
38 <web1:Paradas> ";
39
40 foreach ($chaves as $key => $chave) {
41 $key++;
42 $estruturaXml .= "
43
44 <web1:Parada numero='". $key ."'>
45 <web1:Documento>
46 <!-- Colocar chaves liberadas para vocês -->
47 <web1:ChaveNota>". $chave["key"] ."</web1:ChaveNota>
48 </web1:Documento>
49 </web1:Parada>";
50 }
51
52 $estruturaXml .= "
53 </web1:Paradas>
54 </web1:Rota>
55 </web1:Rotas>
56 <!-- o nome do arquivo pode seguir o padrao que voce quiser. Serve para ajudar resolver chamados referentes a este request -->
57 <web1:nomeArquivo>transporteteste-".$route_id.".xml</web1:nomeArquivo>
58 </web1:uploadRouteUsingDocumentKey>
59 </soapenv:Body>
60 </soapenv:Envelope> ";
61
62
63
64 try {
65
66 $client = new Client(); //GuzzleHttp\Client
67
68 $result = $client->post('https://soap.comprovei.com.br/importQueue/v3/index.php?wsdl', [
69 "headers" =>
70 [
71 "Accept" => "*/*",
72 "Content-type" => "application/xml",
73 "Access-Control-Allow-Origin" => "*",
74 ],
75 'body' => $estruturaXml
76 ]);
77
78 $response = $result->getBody()->getContents();
79 print_r($response);
80
81 // Decodifica o formato JSON e retorna um Objeto
82 $json = json_decode($response);
83
84
85
86
87
88
89 } catch (\GuzzleHttp\Exception\BadResponseException $e) {
90
91 /* Entrará aqui caso haja algum erro na requisição */
92 //return $e->getResponse()->getBody()->getContents();
93 }
94
95 }