Upload url on same page

1

I bought the service from an SMS company. But to send the SMS I have to "rotate" the link below:

https://site.com/apiJSON.php?data={"login":"[email protected]","senha":"SENHA","campanha":"ID 1234","mensagens":{"1":{"numero":"2799999999","msg":"MINHA MENSAGEM","data":"2016-08-11 09:20:00"}}}

Basically a JSON call.

The problem is that I need to send the SMS in the middle of a PHP function. And I can not call that link to send the SMS.

Does anyone have an idea?

    
asked by anonymous 11.08.2016 / 14:19

4 answers

1

You can use json_encode to format json , and curl to order:

function enviarSMS($email, $senha, $numero, $msg){
    $curl = curl_init("https://site.com/apiJSON.php?data=");
    $data = date('Y-m-d H:i:s');

    $array = array('login' => $email,
                   'senha' => $senha,
                   'campanha'  => 'ID 1234',
                   'mensagens' => array('1' => array('numero' => $numero,
                                                     'msg' => $msg,
                                                     'data' => $data)));

    $json = json_encode($array);

    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $json);

    $jsonExec = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    curl_close($curl);
    $resposta = json_decode($jsonExec, true);

    echo "Status: $status\n";
    echo $resposta;
}

And to use it, do so:

enviarSMS('foo@bar', '123baz', '2799999999', 'mensagem');
    
11.08.2016 / 14:52
2

Try curl :

function do_sms($serv) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
    curl_setopt($curl, CURLOPT_URL, $serv);
    curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1');
    $return = curl_exec($curl);
    curl_close($curl);
    return $return;
}

do_sms('https://site.com/apiJSON.php?data={"login":"[email protected]","senha":"SENHA","campanha":"ID 1234","mensagens":{"1":{"numero":"2799999999","msg":"MINHA MENSAGEM","data":"2016-08-11 09:20:00"}}}');

Or file_get_contents :

file_get_contents('https://site.com/apiJSON.php?data={"login":"[email protected]","senha":"SENHA","campanha":"ID 1234","mensagens":{"1":{"numero":"2799999999","msg":"MINHA MENSAGEM","data":"2016-08-11 09:20:00"}}}');
    
11.08.2016 / 14:49
1

First use CURL to connect to another service.

In this way, for example:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link_para_chamar);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '10');
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

// Habilita cache do DNS (remover o // para habilitar):
//curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
//curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, '3600');

// Habilita verificação de SSL (em caso de problema defina ambos para FALSE, não é recomendado desligar!):
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);


$resposta = curl_exec($ch);
$erroSite = curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200 ? true : false;
$erroCurl = curl_error($ch);
curl_close($ch);

Then, to set $link_para_chamar , use json_encode :

$json = [];
$json['login'] = '[email protected]';
$json['senha'] = 'senha';
$json['campanha'] = 'ID 1234';

$json['mensagens'][1]['numero'] = '2799999999';
$json['mensagens'][1]['msg'] = 'MENSAGEM';
$json['mensagens'][1]['data'] = '2016-08-11 09:20:00';

$link_para_chamar = 'https://site.com/apiJSON.php?data='.json_encode($json);
    
11.08.2016 / 14:53
-1

Only implementing what the above friend pointed out.

To be more complete, use javascript. Example.

<form id="send">
  <input type="text" name="login" />
  <input type="text" name="number" />
</form>

And in the javascript file retrieve the data and move to Curl in PHP.

$.ajax({
  url: 'arquivo.php',
  data: $(this).seriaze(),
  type: 'POST'
});

And then just retrieve the data in PHP.

    
11.08.2016 / 14:59