Last active
May 10, 2018 12:55
-
-
Save rubens-shoji/67fe980ca7e5f9b262e533d1ca1ba03a to your computer and use it in GitHub Desktop.
Envio em lotes via PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$config = [ | |
'apiv2' => 'http://v2.bestuse.com.br/api/v1/' | |
]; | |
function makeRequest($url, $jsonData, $method) { | |
//Initiate cURL. | |
$ch = curl_init($url); | |
//Encode the array into JSON. | |
$jsonDataEncoded = json_encode($jsonData); | |
//Tell cURL that we want to send a POST request. | |
if ($method === 'POST') { | |
curl_setopt($ch, CURLOPT_POST, 1); | |
//Attach our encoded JSON string to the POST fields. | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded); | |
} | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
//Set the content type to application/json | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
//Execute the request | |
$retornos = curl_exec($ch); | |
$retornos = json_decode($retornos, 1); | |
return $retornos; | |
} | |
function envioLote($token, $carteira, $lote) { | |
$url = $config['apiv2'].'envioApi?token='.$token; | |
$dados = [ | |
'smss' => $lote, | |
'centroCusto' => $carteira, | |
'envioImediato' => true | |
]; | |
$response = makeRequest($url, $dados, 'POST'); | |
return json_encode($response); | |
} | |
$token = 'eyJhbGciOiJIUzI1NiJ9.NWEwMGIzNNWMyMTI1ZmUwYjYzMjE3.Wti1ZgrYI7Wo81iWJW7jy5nE8OyvJHCeTxgl1n5fqKs'; | |
$carteira = '5a00b37ab5c2145fe0b63221'; | |
$lote = [ | |
array('numero' => '42999999999', 'mensagem' => 'Mensagem'), | |
array('numero' => '42999999999', 'mensagem' => 'Mensagem2') | |
], | |
$envio = envioLote($token, $carteira, $lote); | |
print_r($envio); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment