1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gamer\Jobs; |
4
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
6
|
|
|
use Illuminate\Queue\SerializesModels; |
7
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
8
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
9
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
10
|
|
|
use Log; |
11
|
|
|
|
12
|
|
|
class Sms implements ShouldQueue |
13
|
|
|
{ |
14
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
15
|
|
|
|
16
|
|
|
protected $number; |
17
|
|
|
protected $message; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Create a new job instance. |
21
|
|
|
* |
22
|
|
|
* @return void |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct($number, $message) |
25
|
|
|
{ |
26
|
|
|
$this->number = $number; |
27
|
|
|
$this->message = $message; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Execute the job. |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function handle() |
36
|
|
|
{ |
37
|
|
|
$ch = curl_init(); |
38
|
|
|
$data = "{ |
39
|
|
|
\"sendSmsRequest\": { |
40
|
|
|
\"to\": \"". $this->number ."\", |
41
|
|
|
\"msg\": \"". $this->message ."\", |
42
|
|
|
\"aggregateId\": \"".\Illuminate\Support\Facades\Config::get('services.zenvia.aggregateId')."\" |
43
|
|
|
} |
44
|
|
|
}"; |
45
|
|
|
curl_setopt($ch, CURLOPT_URL, "https://api-rest.zenvia.com/services/send-sms"); |
46
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
47
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false); |
48
|
|
|
curl_setopt($ch, CURLOPT_POST, true); |
49
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
50
|
|
|
|
51
|
|
|
// Authorization: Basic {credenciais em base 64 no formato usuário:senha} |
52
|
|
|
curl_setopt( |
53
|
|
|
$ch, CURLOPT_HTTPHEADER, array( |
54
|
|
|
"Content-Type: application/json", |
55
|
|
|
// "Authorization: Basic cG9wYXBwcy5hcGkyOmZtWjFaMXVt", |
56
|
|
|
// "Authorization: Basic cG9wYXBwcy5hcGk6b2RWZ0ZGTllLZg==", |
57
|
|
|
"Authorization: Basic ".base64_encode(\Illuminate\Support\Facades\Config::get('services.zenvia.conta').':'.\Illuminate\Support\Facades\Config::get('services.zenvia.senha')), |
58
|
|
|
"Accept: application/json" |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$response = json_decode(json_encode(curl_exec($ch)), true); |
63
|
|
|
curl_close($ch); |
64
|
|
|
|
65
|
|
|
if (is_array($response) && isset($response['sendSmsResponse']) |
66
|
|
|
&& isset($response['sendSmsResponse']['statusDescription']) |
67
|
|
|
&& $response['sendSmsResponse']['statusDescription']!='Ok' |
68
|
|
|
) { |
69
|
|
|
Log::critical( |
70
|
|
|
'[Sms Job] Erro -> Data: '.$data.' Resposta: '. print_r($response, true) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.