1. Go to this page and download the library: Download devaguia/correios-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devaguia / correios-php example snippets
// Parâmetros obrigatórios - Required Paramns
$correios = new \Correios\Correios(
username: 'user',
password: 'password',
postcard: 'postcard',
isTestMode: true
);
// Parâmetros opcionais - Optional parameters
$correios = new \Correios\Correios(
username: 'user',
password: 'password',
postcard: 'postcard',
isTestMode: true,
token: 'string'
);
// Use um número de requisição e ID do lot personalizado - Use a custom request number and Lot ID
$correios->setRequestNumber(requestNumber: '20230831');
$correios->getRequestNumber();
$correios->setLotId(lotId: '20230831LT');
$correios->getLotId();
// Gerando um novo token - Generating a new token
$correios = new \Correios\Correios(
username: 'user',
password: 'password',
postcard: 'postcard',
isTestMode: true
);
$token = $correios->authentication()->getToken();
$tokenExpiration = $correios->authentication()->getTokenExpiration();
$responseBody = $correios->authentication()->getResponseBody();
$responseCode = $correios->authentication()->getResponseCode();
$errors = $correios->authentication()->getErrors();
// Pega o número do e da diretoria com base na responsta da autenticação - Gets the board number based on the authentication response
$contractNumber = $correios->authentication()->getContract();
$drNumber = $correios->authentication()->getDr();
// Usando um token gerado anteriormente - Using a token generated earlie
$correios = new \Correios\Correios(
username: 'user',
password: 'password',
postcard: 'postcard',
isTestMode: true
token: 'eyJhbGciOiJSUzUxMiJ9.eyJhbWJpZW50ZSI6IlBST0RVQ0FPIiwiaWQiOiI0MDExMjE1NDAwMDE5MCIsInBmbCI6IlBKIiwiY25waiI6IjQwMTEyMTU0MDAwMTkwIiwiY29udHJhdG8iOnsibnVtZXJvIjoiOTkxMjYxNjgzOSIsImRyIjoyMCwiYXBpIjpbMjcsMzQsMzUsNDEsNzYsODcsNTY2XX0sImlwIjoiMTcwLjc4LjY4Ljg2LDE3MC43OC42OC44NiIsImlhdCI6MTY5MjY0MTU2MywiaXNzIjoidG9rZW4tc2VydmljZSIsImV4cCI6MTY5MjcyNzk2MywianRpIjoiZGViMTczM2EtYmVjYS00NmIyLWFkNGYtYWQ5ZjBkYWFlZjhlIn0.uxJCCQFj0c1qzI4BGk9JWTh6TT_Drp7YaMbKQoT9m-ie5wXRun4cOuQdbj28MQR3IYuntB2B9C8aqSoa_eXADtvf4J2H-ZTWS0wAnxsxxkNf1lXmHYrD2jCgRMVgQ_2dy40uBt0bJyk0M9e4jNg2almtZMlAwjbVrgSbopuNrqhHe49GuDIuQzJLqsNC60mA6KberD9eSSNZsvHbgNYQysK0mZTkIFdWy8DBJ7b5FrbLzbeikqKbRW9pDj_3Q-YrxhwQ79ZjEF8dLiAU3BcCDHwOxpSv6HKD5984mz1VppFXcaBAsqW6oB9iCHrENjVqtRXa8mx0nqbjelyz0Of6qA'
);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.