Skip to content

Commit f7cad4a

Browse files
aggiunti sms
1 parent 5f1be3b commit f7cad4a

12 files changed

Lines changed: 821 additions & 7 deletions

File tree

src/OpenApi.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ function __construct(array $scopes, string $username, string $apikey, $environme
4646
$this->apikey = $apikey;
4747
$this->prefix = $prefix;
4848
$this->scopes = $realScopes;
49-
5049
$token = $this->getToken();
51-
//var_dump($token);exit;
5250
list($moduli,$nomi) = $this->getListaModuli();
5351
$this->clients = [];
5452
foreach($domains as $d){
@@ -61,6 +59,8 @@ function __construct(array $scopes, string $username, string $apikey, $environme
6159
}
6260

6361
$this->validations = new \OpenApi\classes\utility\Plugins\Validations();
62+
$this->fiscalCode = new \OpenApi\classes\utility\Plugins\FiscalCode();
63+
//$this->geocoding = new \OpenApi\classes\Geocoding($token->token, [], $this->cache, "");
6464
}
6565

6666
/**
@@ -83,6 +83,21 @@ private function getListaModuli(){
8383

8484
$moduli['comuni.openapi.it'] = "\\OpenApi\\classes\\Comuni";
8585
$nomi['comuni.openapi.it'] = "comuni";
86+
87+
88+
$moduli['ws.marchetemporali.com'] = "\\OpenApi\\classes\\MarcheTemporali";
89+
$nomi['ws.marchetemporali.com'] = "marcheTemporali";
90+
91+
92+
$moduli['geocoding.realgest.it'] = "\\OpenApi\\classes\\Geocoding";
93+
$nomi['geocoding.realgest.it'] = "geocoding";
94+
95+
$moduli['ws.messaggisms.com'] = "\\OpenApi\\classes\\Sms";
96+
$nomi['ws.messaggisms.com'] = "SMS";
97+
98+
99+
$moduli['ws.firmadigitale.com'] = "\\OpenApi\\classes\\FirmaDigitale";
100+
$nomi['ws.firmadigitale.com'] = "FirmaDigitale";
86101
return array($moduli,$nomi);
87102
}
88103

@@ -205,7 +220,7 @@ function getOldToken(){
205220
$tostore['scopes'] = serialize($this->scopes);
206221
$tostore['username'] = $this->username;
207222
$tostore['prefix'] = $this->prefix;
208-
$this->session->save($tostore);
223+
$this->store->save($tostore);
209224
return TRUE;
210225
}
211226
return FALSE;

src/classes/Comuni.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ function getProvince($regione = NULL, $ttl = 86400){
7373
return $province;
7474
}
7575

76+
77+
/**
78+
* Restituisce la lista comuni a partire dalla provincia
79+
* @param mixed $provincia provincia Es.: RM
80+
* @param int $ttl time to reload cache
81+
*
82+
* @return array
83+
*/
7684
function getComuni($provincia, $ttl = 86400){
7785

7886
$provincia = trim(\strtolower($provincia));
7987
$data = $this->connect("province/$provincia", "GET", [], $ttl);
8088

81-
8289
$comuni = $data->data;
83-
//sort($comuni->comuni);
84-
//usort($comuni->dettaglio_comuni,[$this, 'sortComune']);
8590
return $comuni;
8691

8792
}

src/classes/FirrmaDigitale.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace OpenApi\classes;
3+
class FirmaDigitale extends OpenApiBase {
4+
5+
/**
6+
* @param string $token Il token da utilizzare per il collegamento
7+
* @param array $scopes Array con la lista degli scope per cui il token è abilitato
8+
* @param object $cache Classe che gestisce la cahce, deve essere una classe che estende {@see OpenApi\clasess\utility\DummyCache} o comunque compatibile con essa (stessi metodi)
9+
*/
10+
function __construct(string $token, array $scopes, object $cache, string $prefix){
11+
parent::__construct($token, $scopes, $cache, $prefix);
12+
$this->basePath = "https://ws.firmadigitale.com";
13+
}
14+
15+
16+
}

src/classes/Geocoding.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ function __construct(string $token, array $scopes, object $cache, string $prefi
1212
$this->basePath = "https://geocoding.realgest.it";
1313
}
1414

15+
/**
16+
* Restituisce le coordinate geografiche a partire dall'indirizzo
17+
* @param string $address Indirizzo
18+
* @param int $ttl Tempo in cui la risposta resta in cahce
19+
*
20+
* @return object
21+
*/
1522
function geocode(string $address, $ttl = 86400){
1623
$data = $this->connect("geocode", "POST", ["address" => $address], $ttl, TRUE);
1724

src/classes/OpenApiBase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ protected function connect(string $endpoint, $type = "GET", $param = [], $ttr =
9797
if(!$force){
9898
$this->checkHasScope($url, $type);
9999
}
100+
100101

101102
if($type == "GET" && $ttr > 0 && $ret = $this->getCacheObject($url)) {
102103
return $ret;
@@ -121,7 +122,7 @@ protected function connect(string $endpoint, $type = "GET", $param = [], $ttr =
121122
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Authorization: Bearer ".$this->token));
122123
curl_setopt($ch, CURLOPT_HEADER, 1);
123124
$response = curl_exec($ch);
124-
//var_dump($response);exit;
125+
// var_dump($response);exit;
125126
$this->rawResponse = $response;
126127
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
127128
$this->header = substr($response, 0, $header_size);

src/classes/Sms.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
namespace OpenApi\classes;
3+
class Sms extends OpenApiBase {
4+
/**
5+
* @param string $token Il token da utilizzare per il collegamento
6+
* @param array $scopes Array con la lista degli scope per cui il token è abilitato
7+
* @param object $cache Classe che gestisce la cahce, deve essere una classe che estende {@see OpenApi\clasess\utility\DummyCache} o comunque compatibile con essa (stessi metodi)
8+
*/
9+
function __construct(string $token, array $scopes, object $cache, string $prefix){
10+
parent::__construct($token, $scopes, $cache, $prefix);
11+
$this->basePath = "https://ws.messaggisms.com";
12+
$this->messageId = NULL;
13+
}
14+
15+
function addRecipeints($recipients, $finish = false){
16+
if($this->messageId == NULL){
17+
throw new \OpenApi\classes\exception\OpenApiSMSException("No message id presente",40010);
18+
exit;
19+
}
20+
$data = $this->addRecipeintsByMessageId($this->messageId, $recipients, $finish );
21+
if($finish){
22+
$this->messageId = NULL;
23+
}
24+
return $data;
25+
}
26+
27+
function addRecipeintsByMessageId($messageId, $recipients, $finish = false){
28+
$param['recipients'] = $recipients;
29+
$param['transaction'] = !$finish;
30+
try{
31+
$data = $this->connect("messages/$messageId", "PUT", $param);
32+
33+
return $data;
34+
}catch (\OpenApi\classes\exception\OpenApiConnectionsException $e){
35+
if($e->getHTTPCode() == 404){
36+
return null;
37+
}
38+
throw $e;
39+
exit;
40+
}
41+
}
42+
43+
function getRecipients($messageId, $number = NULL){
44+
try{
45+
$data = $this->connect("messages/$messageId/recipients/".$number, "GET", []);
46+
return $data;
47+
}catch (\OpenApi\classes\exception\OpenApiConnectionsException $e){
48+
49+
if($e->getHTTPCode() == 404){
50+
return null;
51+
}
52+
throw $e;
53+
exit;
54+
}
55+
}
56+
57+
function getMessage($messageId){
58+
try{
59+
$data = $this->connect("messages/$messageId", "GET", []);
60+
return $data;
61+
}catch (\OpenApi\classes\exception\OpenApiConnectionsException $e){
62+
63+
if($e->getHTTPCode() == 404){
64+
return null;
65+
}
66+
throw $e;
67+
exit;
68+
}
69+
}
70+
71+
function sendMore($sender, $recipients, $text, $transaction = false, $priority = 1,$options = NULL, $test = false){
72+
73+
$param['test'] = $test;
74+
$param['sender'] = $sender;
75+
$param['recipients'] = $recipients;
76+
$param['body'] = $text;
77+
$param['transaction'] = $transaction;
78+
if($options != NULL){
79+
$param['priority'] = $priority;
80+
}
81+
try{
82+
$data = $this->connect("messages/", "POST", $param);
83+
if(isset($data->data[0]) && $transaction){
84+
$this->messageId =$data->data[0]->id;
85+
}
86+
return $data;
87+
}catch (\OpenApi\classes\exception\OpenApiConnectionsException $e){
88+
89+
if($e->getHTTPCode() == 404){
90+
return null;
91+
}
92+
throw $e;
93+
exit;
94+
}
95+
}
96+
97+
98+
function sendOne($sender, $recipient, $text, $prefix = NULL, $priority = 1,$options = NULL, $test = false){
99+
if($prefix != NULL){
100+
$recipient = $prefix."-".$recipient;
101+
}
102+
103+
$param['test'] = $test;
104+
$param['sender'] = $sender;
105+
$param['recipients'] = $recipient;
106+
$param['body'] = $text;
107+
$param['transaction'] = FALSE;
108+
if($options != NULL){
109+
$param['priority'] = $priority;
110+
}
111+
112+
try{
113+
$data = $this->connect("messages/", "POST", $param);
114+
115+
return $data;
116+
}catch (\OpenApi\classes\exception\OpenApiConnectionsException $e){
117+
if($e->getHTTPCode() == 404){
118+
return null;
119+
}
120+
throw $e;
121+
exit;
122+
}
123+
}
124+
125+
}

src/classes/UfficioPostale.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ function __construct(string $token, array $scopes, object $cache, string $prefi
1212
$this->basePath = "https://ws.ufficiopostale.com";
1313
}
1414

15+
16+
/**
17+
* Restiuisce un oggetto di tipo raccomandata
18+
* @return object
19+
*/
20+
function createRaccomandata(){
21+
return new \OpenApi\classes\utility\UfficioPostale\Raccomandata($this->connect);
22+
}
23+
24+
//function createRaccomandataByData()
25+
26+
1527

1628

1729

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace OpenApi\classes\exception;
3+
4+
/**
5+
* Gestisce le eccezioni relative alle funzionalità SMS
6+
* 400010: Si è tentato di aggiungere dei recipienti, ma non è presente l'id del messagggio
7+
*/
8+
class OpenApiSMSException extends OpenApiExceptionBase
9+
{
10+
public function __construct($message, $code = 0, \Exception $previous = null) {
11+
parent::__construct($message, $code, $previous);
12+
}
13+
}

0 commit comments

Comments
 (0)