93 lines
2.9 KiB
C++
93 lines
2.9 KiB
C++
#include "VoipMsSMSClient.h"
|
|
#include <QTextStream>
|
|
#include <QDebug>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QDateTime>
|
|
|
|
CVoipMsSMSClient::CVoipMsSMSClient()
|
|
{
|
|
mVOIPMSSocket = new QNetworkAccessManager();
|
|
connect(mVOIPMSSocket,SIGNAL(finished(QNetworkReply*)),this,SLOT(VoipServerReplyFinished(QNetworkReply*)));
|
|
}
|
|
|
|
CVoipMsSMSClient::~CVoipMsSMSClient()
|
|
{
|
|
delete mVOIPMSSocket;
|
|
mSMSMessagesList.clear();
|
|
}
|
|
|
|
int CVoipMsSMSClient::DownloadSMSFromServer()
|
|
{
|
|
|
|
QString Username = "jean-francois.martel@polymtl.ca";
|
|
QString Password = "Pentium2";
|
|
QString Method = "getSMS";
|
|
QString Url;
|
|
Url.clear();
|
|
QTextStream UrlStream(&Url);
|
|
|
|
UrlStream << VOIP_MS_API_URL
|
|
<< "api_username=" << Username << "&"
|
|
<< "api_password=" << Password << "&"
|
|
<< "method=" << Method << "&"
|
|
<< "from=" << "2015-10-01" << "&"
|
|
<< "to=" << "2015-11-30" << "&"
|
|
<< "did=" << "5143606463" << "&"
|
|
<< "limit=" << "50";
|
|
|
|
mVOIPMSSocket->get(QNetworkRequest(Url));
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
|
|
void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
|
{
|
|
QByteArray Reply = NetworkReply->readAll();
|
|
|
|
QJsonDocument JsonReply = QJsonDocument::fromJson(Reply);
|
|
QJsonObject JsonObject = JsonReply.object();
|
|
if(JsonObject["status"].toString() == "success")
|
|
{
|
|
QJsonArray SMSArray = JsonObject["sms"].toArray();
|
|
|
|
foreach (const QJsonValue & value, SMSArray)
|
|
{
|
|
CSMSMessage NewMessage;
|
|
QJsonObject obj = value.toObject();
|
|
NewMessage.mContact = obj["contact"].toString();
|
|
NewMessage.mDateTime = QDateTime::fromString(obj["date"].toString(),"yyyy-MM-dd HH:mm:ss");
|
|
NewMessage.mDID = obj["did"].toString();
|
|
NewMessage.mMessageText = obj["message"].toString();
|
|
NewMessage.mType = (SmsType_t)obj["type"].toString().toInt();
|
|
NewMessage.mVOIPMSDatabaseID = (qint64)obj["type"].toString().toLongLong();
|
|
mSMSMessagesList.append(NewMessage);
|
|
qDebug() << obj["contact"].toString().toUtf8() << " : " << obj["message"].toString().toUtf8();
|
|
}
|
|
|
|
qDebug("Added %d messages in the list",mSMSMessagesList.size());
|
|
}
|
|
|
|
|
|
// qDebug() << "Reply from server: " << Reply;
|
|
|
|
|
|
// [id] => 111120
|
|
// [date] => 2014-03-30 10:24:16
|
|
// [type] => 0
|
|
// [did] => 8574884828
|
|
// [contact] => 8577884821
|
|
// [message] => hello+john
|
|
|
|
|
|
}
|
|
|
|
|
|
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
|
|
|
|
|
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2014-01-01&to=2015-11-11&did=5143606463&limit=50
|
|
|