This commit is contained in:
J-F Martel
2015-12-02 20:37:01 -05:00
parent c6937d5e0c
commit 31997aad40
9 changed files with 311 additions and 3 deletions
+9
View File
@@ -0,0 +1,9 @@
#include "CSMSMessage.h"
CSMSMessage::CSMSMessage()
{
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef CSMSMESSAGE_H
#define CSMSMESSAGE_H
#include "GlobalDefine.h"
#include <QString>
#include <QDateTime>
typedef enum eSMSType
{
SMS_SENT_TYPE,
SMS_RECEIVED_TYPE
}SmsType_t;
class CSMSMessage
{
public:
CSMSMessage();
qint64 mVOIPMSDatabaseID;
QDateTime mDateTime;
SmsType_t mType;
QString mDID, mContact, mMessageText;
// [id] => 111120
// [date] => 2014-03-30 10:24:16
// [type] => 0
// [did] => 8574884828
// [contact] => 8577884821
// [message] => hello+john
};
#endif // CSMSOBJECT_H
+92
View File
@@ -0,0 +1,92 @@
#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
+34
View File
@@ -0,0 +1,34 @@
#ifndef CVOIPMSSMSCLIENT_H
#define CVOIPMSSMSCLIENT_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "GlobalDefine.h"
#include <QList>
#include "CSMSMessage.h"
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
class CVoipMsSMSClient : QObject
{
Q_OBJECT
public:
CVoipMsSMSClient();
virtual ~CVoipMsSMSClient();
int DownloadSMSFromServer();
QList<CSMSMessage> mSMSMessagesList;
private:
QNetworkAccessManager *mVOIPMSSocket;
public slots:
void VoipServerReplyFinished(QNetworkReply*);
};
#endif // CVOIPMSSMSCLIENT_H