|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TarfinLabs\Netgsm\Report; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use SimpleXMLElement; |
|
7
|
|
|
|
|
8
|
|
|
class NetgsmSmsDetailReport extends AbstractNetgsmReport |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $url = 'sms/report/detail'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $errorCodes = [ |
|
19
|
|
|
30, 60, 65, 70, |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $noResultCodes = [ |
|
26
|
|
|
100, 101, |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* sends a report request until one of the $noResultCodes comes in response. |
|
31
|
|
|
* |
|
32
|
|
|
* @var bool |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $paginated = true; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Default filter parameters. |
|
38
|
|
|
* |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $filters = [ |
|
42
|
|
|
'type' => 1, |
|
43
|
|
|
'version' => 1, |
|
44
|
|
|
'view' => 2, |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Sets the Netgsm service bulkId |
|
49
|
|
|
* If bulkId is set, type value is set to 0. |
|
50
|
|
|
* @see https://www.netgsm.com.tr/dokuman/#http-get-rapor |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $bulkId |
|
53
|
|
|
* @return AbstractNetgsmReport |
|
54
|
|
|
*/ |
|
55
|
|
|
public function setBulkId($bulkId): AbstractNetgsmReport |
|
56
|
|
|
{ |
|
57
|
|
|
parent::setBulkId($bulkId); |
|
58
|
|
|
|
|
59
|
|
|
$this->setType(0); |
|
60
|
|
|
|
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Processes and returns a report line. |
|
66
|
|
|
* |
|
67
|
|
|
* @param $line |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function processRow($line): array |
|
71
|
|
|
{ |
|
72
|
|
|
return [ |
|
73
|
|
|
'jobId' => (int) $line->msginfo->jobID, |
|
74
|
|
|
'message' => (string) $line->msginfo->msg, |
|
75
|
|
|
'startDate' => (string) $line->datetime->startdate, |
|
76
|
|
|
'endDate' => (string) $line->datetime->stopdate, |
|
77
|
|
|
'status' => (string) $line->msginfo->state, |
|
78
|
|
|
'total' => (string) $line->msginfo->total, |
|
79
|
|
|
'header' => (string) $line->msginfo->msgheader, |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Parses the XML response returned from the Netgsm API service. |
|
85
|
|
|
* |
|
86
|
|
|
* @param $response |
|
87
|
|
|
* @return Collection |
|
88
|
|
|
* @throws \TarfinLabs\Netgsm\Exceptions\ReportException |
|
89
|
|
|
*/ |
|
90
|
|
|
public function parseResponse(string $response): Collection |
|
91
|
|
|
{ |
|
92
|
|
|
$this->validateResponse($response); |
|
93
|
|
|
$response = utf8_encode(html_entity_decode($response)); |
|
94
|
|
|
$xml = new SimpleXMLElement($response); |
|
95
|
|
|
|
|
96
|
|
|
$collection = new Collection(); |
|
97
|
|
|
|
|
98
|
|
|
foreach ($xml->header->SMSReport as $line) { |
|
99
|
|
|
$item = $this->processRow($line); |
|
100
|
|
|
$collection->push($item); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $collection; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|