YouTube - :)

2

. HTTP(S) (REST API, ), cURL , JSON. .


cURL

Asterisk CURL, WEB FTP . :

CURL(url,post-data)
  • url - URL, ;
  • post-data - GET . , POST ;

:

exten => _X.,1,Set(C_RESULT=${CURL(//merionet.ru/rest?num=84991234567)})

GET URL, C_RESULT.


HTTPS

, HTTPS , SSL . ssl_verifypeer=0, :

same => n,Set(CURLOPT(ssl_verifypeer)=0)

?

. GotoIf , cURL:

exten => _X.,1,Set(C_RESULT=${CURL(//merionet.ru/rest?num=84991234567)})
same => n,GotoIf($["${C_RESULT}" = "1"]?res1:res2)
same => n(res1),Verbose(CURL Result = 1)
same => n,Hangup
same => n(res2),Verbose(CURL Result != 1)
same => n,Hangup

GET - rest, num ( Asterisk). , 1, res1, , res2.


res_json JSON

, API, JSON. , . res_json JSON , JSON.

.
exten => _X.,1,Set(C_RESULT=${CURL(//merionet.ru/rest.json)})
same => n,Set(result=${JSONELEMENT(C_RESULT, result/somefield)})
same => n,GotoIf($["${result}" = "1"]?res1:res2)
same => n(res1),Verbose(CURL Result = 1)
same => n,Hangup
same => n(res2),Verbose(CURL Result != 1)
same => n,Hangup

, web rest.json :

{
  "result": {
    "somefield": 1
  }
}

?


: