-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sms.cpp
66 lines (57 loc) · 2.33 KB
/
Sms.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Sms.h"
#include <QJsonObject>
#include <QJsonArray>
#include <QNetworkRequest>
#include <QSslConfiguration>
//Sms::Sms(int id, int srvIdx):
// _id(id), _destinations(), _msg(), _srvIdx(srvIdx)
//{}
Sms::Sms(const QJsonObject &json, int srvIdx):
_id(json[JSON_ID].toInt()),
_dest(json[JSON_DEST].toString()),
_msg(json[JSON_MSG].toString()),
_srvIdx(srvIdx)
{}
SmsServer::SmsServer(const QString &host, bool https, const QString &mobileAPI, const QString &urlGet, const QString &urlNotify, bool checkSSL):
_urlGetSMS(QString("http%1://%2/%3?mobile=%4").arg(https ? "s" : "").arg(host).arg(urlGet).arg(mobileAPI)),
_urlNotifyStatusSMS(QString("http%1://%2/%3?mobile=%4").arg(https ? "s" : "").arg(host).arg(urlNotify).arg(mobileAPI)),
_checkCetificateSSL(checkSSL),
_reqGetSMS(new QNetworkRequest(urlGet)),
_reqNotifyStatus(urlNotify.isEmpty() ? nullptr : new QNetworkRequest(urlNotify))
{
_init();
}
SmsServer::SmsServer(const QString &urlGet, const QString &urlNotify, bool checkSSL):
_urlGetSMS(urlGet), _urlNotifyStatusSMS(urlNotify), _checkCetificateSSL(checkSSL),
_reqGetSMS(new QNetworkRequest(urlGet)),
_reqNotifyStatus(urlNotify.isEmpty() ? nullptr : new QNetworkRequest(urlNotify))
{
_init();
}
SmsServer::~SmsServer()
{
delete _reqNotifyStatus;
delete _reqGetSMS;
}
void SmsServer::_init()
{
_reqGetSMS->setHeader(QNetworkRequest::UserAgentHeader, "SmsJsonPolling C++ app" );
_reqGetSMS->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
if (!_checkCetificateSSL)// && _urlGetSMS.scheme() == "https")
{
QSslConfiguration conf = QSslConfiguration::defaultConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
_reqGetSMS->setSslConfiguration(conf);
}
if (_reqNotifyStatus)
{
_reqNotifyStatus->setHeader(QNetworkRequest::UserAgentHeader, "SmsJsonPolling C++ app" );
_reqNotifyStatus->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
if (!_checkCetificateSSL) // && _urlNotifyStatusSMS.scheme() == "https")
{
QSslConfiguration conf = QSslConfiguration::defaultConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
_reqNotifyStatus->setSslConfiguration(conf);
}
}
}