Dev..
This commit is contained in:
@@ -17,7 +17,7 @@ class CSMSMessage
|
||||
public:
|
||||
CSMSMessage();
|
||||
|
||||
qint64 mVOIPMSDatabaseID;
|
||||
/*qint64*/QString mVOIPMSDatabaseID;
|
||||
QDateTime mDateTime;
|
||||
SmsType_t mType;
|
||||
QString mDID, mContact, mMessageText;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDateTime>
|
||||
|
||||
CVoipMsSMSClient::CVoipMsSMSClient()
|
||||
@@ -18,42 +17,132 @@ CVoipMsSMSClient::~CVoipMsSMSClient()
|
||||
mSMSMessagesList.clear();
|
||||
}
|
||||
|
||||
unsigned int CVoipMsSMSClient::SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData)
|
||||
{
|
||||
mVOIPMsSettings = SettingsData;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CVoipMsSMSClient::DownloadSMSFromServer()
|
||||
{
|
||||
|
||||
QString Username = "jean-francois.martel@polymtl.ca";
|
||||
QString Password = "Pentium2";
|
||||
QString Method = "getSMS";
|
||||
QDate EndDate;
|
||||
mCurStartDate = mVOIPMsSettings.mStartDate;
|
||||
if(mCurStartDate.daysTo(QDate::currentDate()) > VOIP_MS_SMS_DATESPAN)
|
||||
{
|
||||
EndDate = mCurStartDate.addDays(VOIP_MS_SMS_DATESPAN);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndDate = mCurStartDate.addDays(mCurStartDate.daysTo(QDate::currentDate()));
|
||||
}
|
||||
|
||||
SendSMSDownloadRequest(mCurStartDate,EndDate);
|
||||
|
||||
// QString Url;
|
||||
// Url.clear();
|
||||
// QTextStream UrlStream(&Url);
|
||||
|
||||
// // Url = "https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2015-11-01&to=2015-11-11&did=5143606463&limit=50";
|
||||
|
||||
// UrlStream << VOIP_MS_API_URL
|
||||
// << "api_username=" << mVOIPMsSettings.mUsername << "&"
|
||||
// << "api_password=" << mVOIPMsSettings.mPassword << "&"
|
||||
// << "method=" << "getSMS" << "&"
|
||||
// << "from=" << mCurStartDate.toString("yyyy-MM-dd") << "&"
|
||||
// << "to=" << EndDate.toString("yyyy-MM-dd") << "&"
|
||||
// << "did=" << mVOIPMsSettings.mDefaultDID << "&"
|
||||
// << "limit=" << "50";
|
||||
|
||||
// qDebug() << "Cmd: " << Url;
|
||||
// mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||
// mCurStartDate = EndDate;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CVoipMsSMSClient::SendSMSDownloadRequest(QDate StartDate, QDate EndDate)
|
||||
{
|
||||
QString Url;
|
||||
Url.clear();
|
||||
QTextStream UrlStream(&Url);
|
||||
|
||||
qDebug() << "Sending request for dates from: " << StartDate.toString("yyyy-MM-dd") << " to: " << EndDate.toString("yyyy-MM-dd");
|
||||
|
||||
// Url = "https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getSMS&from=2015-11-01&to=2015-11-11&did=5143606463&limit=50";
|
||||
|
||||
UrlStream << VOIP_MS_API_URL
|
||||
<< "api_username=" << mVOIPMsSettings.mUsername << "&"
|
||||
<< "api_password=" << mVOIPMsSettings.mPassword << "&"
|
||||
<< "method=" << "getSMS" << "&"
|
||||
<< "from=" << StartDate.toString("yyyy-MM-dd") << "&"
|
||||
<< "to=" << EndDate.toString("yyyy-MM-dd") << "&"
|
||||
<< "did=" << mVOIPMsSettings.mDefaultDID << "&"
|
||||
<< "limit=" << "50";
|
||||
|
||||
qDebug() << "Cmd: " << Url;
|
||||
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||
mCurStartDate = EndDate;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
unsigned int CVoipMsSMSClient::GetDidFromUserAccount(const QString username, const QString Password)
|
||||
{
|
||||
QString Method = "getDIDsInfo";
|
||||
QString Url;
|
||||
Url.clear();
|
||||
QTextStream UrlStream(&Url);
|
||||
|
||||
UrlStream << VOIP_MS_API_URL
|
||||
<< "api_username=" << Username << "&"
|
||||
<< "api_username=" << username << "&"
|
||||
<< "api_password=" << Password << "&"
|
||||
<< "method=" << Method << "&"
|
||||
<< "from=" << "2015-10-01" << "&"
|
||||
<< "to=" << "2015-11-30" << "&"
|
||||
<< "did=" << "5143606463" << "&"
|
||||
<< "limit=" << "50";
|
||||
<< "method=" << Method << "&";
|
||||
|
||||
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||
mVOIPMSSocket->get(QNetworkRequest(Url));
|
||||
|
||||
return RET_OK;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
||||
{
|
||||
QByteArray Reply = NetworkReply->readAll();
|
||||
|
||||
QJsonDocument JsonReply = QJsonDocument::fromJson(Reply);
|
||||
QJsonObject JsonObject = JsonReply.object();
|
||||
QStringList Keys = JsonObject.keys();
|
||||
if(JsonObject["status"].toString() == "success")
|
||||
{
|
||||
QJsonArray SMSArray = JsonObject["sms"].toArray();
|
||||
if(Keys.contains("sms"))
|
||||
{
|
||||
QJsonArray SMSArray = JsonObject["sms"].toArray();
|
||||
SMSReceived(&SMSArray);
|
||||
}
|
||||
else if(Keys.contains("dids"))
|
||||
{
|
||||
QJsonArray DIDsInfoArray = JsonObject["dids"].toArray();
|
||||
DIDsInfoReceived(&DIDsInfoArray);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(JsonObject["status"].toString() == "no_sms")
|
||||
{
|
||||
SMSReceived(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed VOIP.MS reply: " << JsonObject["status"].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QJsonValue & value, SMSArray)
|
||||
unsigned int CVoipMsSMSClient::SMSReceived(QJsonArray *SMSArray)
|
||||
{
|
||||
if(SMSArray != 0)
|
||||
{
|
||||
foreach (const QJsonValue & value, *SMSArray)
|
||||
{
|
||||
CSMSMessage NewMessage;
|
||||
QJsonObject obj = value.toObject();
|
||||
@@ -62,28 +151,57 @@ void CVoipMsSMSClient::VoipServerReplyFinished(QNetworkReply *NetworkReply)
|
||||
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();
|
||||
NewMessage.mVOIPMSDatabaseID = obj["id"].toString();//.toLongLong();
|
||||
mSMSMessagesList.append(NewMessage);
|
||||
qDebug() << obj["contact"].toString().toUtf8() << " : " << obj["message"].toString().toUtf8();
|
||||
}
|
||||
|
||||
qDebug("Added %d messages in the list",mSMSMessagesList.size());
|
||||
}
|
||||
|
||||
if(mCurStartDate != QDate::currentDate())
|
||||
{
|
||||
if(mSMSMessagesList.size() != 0)
|
||||
{
|
||||
mCurStartDate = QDate::fromString(mSMSMessagesList.last().mDateTime.toString("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
// qDebug() << "Reply from server: " << Reply;
|
||||
|
||||
|
||||
// [id] => 111120
|
||||
// [date] => 2014-03-30 10:24:16
|
||||
// [type] => 0
|
||||
// [did] => 8574884828
|
||||
// [contact] => 8577884821
|
||||
// [message] => hello+john
|
||||
QDate EndDate;
|
||||
if(mCurStartDate.daysTo(QDate::currentDate()) > VOIP_MS_SMS_DATESPAN)
|
||||
{
|
||||
EndDate = mCurStartDate.addDays(VOIP_MS_SMS_DATESPAN);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndDate = mCurStartDate.addDays(mCurStartDate.daysTo(QDate::currentDate()));
|
||||
}
|
||||
|
||||
SendSMSDownloadRequest(mCurStartDate,EndDate);
|
||||
}
|
||||
|
||||
qDebug("Added %d messages in the list",mSMSMessagesList.size());
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
unsigned int CVoipMsSMSClient::DIDsInfoReceived(QJsonArray *DIDsInfoPtr)
|
||||
{
|
||||
QStringList DIDs;
|
||||
QJsonArray DIDsInfo = *DIDsInfoPtr;
|
||||
|
||||
foreach (const QJsonValue & value, DIDsInfo)
|
||||
{
|
||||
QJsonObject DIDInfo = value.toObject();
|
||||
QString CurDID = DIDInfo["did"].toString();
|
||||
int SMSEnabled = DIDInfo["sms_enabled"].toString().toInt();
|
||||
if(SMSEnabled == 1)
|
||||
{
|
||||
DIDs.append(CurDID);
|
||||
}
|
||||
qDebug("DID: %s - SMSEnabled %d",CurDID.toUtf8().data(),SMSEnabled);
|
||||
|
||||
emit DIDSFetched(DIDs);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
//https://www.voip.ms/api/v1/rest.php?api_username=jean-francois.martel@polymtl.ca&api_password=Pentium2&method=getBalance&advanced=True
|
||||
|
||||
|
||||
@@ -7,10 +7,21 @@
|
||||
#include "GlobalDefine.h"
|
||||
#include <QList>
|
||||
#include "CSMSMessage.h"
|
||||
#include <QStringList>
|
||||
#include <QJsonArray>
|
||||
#include "ProgramSettings.h"
|
||||
|
||||
#define VOIP_MS_API_URL "https://www.voip.ms/api/v1/rest.php?"
|
||||
#define VOIP_MS_SMS_DATESPAN 90
|
||||
|
||||
class CVoipMsSMSClient : QObject
|
||||
enum VoipMSRetValues
|
||||
{
|
||||
VOIPMS_RET_SUCCESS,
|
||||
VOIPMS_RET_FAILED,
|
||||
VOIPMS_RET_NO_DID_FOUND
|
||||
};
|
||||
|
||||
class CVoipMsSMSClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -18,14 +29,26 @@ public:
|
||||
virtual ~CVoipMsSMSClient();
|
||||
|
||||
int DownloadSMSFromServer();
|
||||
int SendSMSDownloadRequest(QDate StartDate, QDate EndDate);
|
||||
|
||||
QList<CSMSMessage> mSMSMessagesList;
|
||||
|
||||
unsigned int GetDidFromUserAccount(const QString username, const QString Password);
|
||||
unsigned int SetVOIPMsSettings(CVoipMSSMSSettings *SettingsData);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *mVOIPMSSocket;
|
||||
|
||||
unsigned int SMSReceived(QJsonArray *sms);
|
||||
unsigned int DIDsInfoReceived(QJsonArray *DIDsInfo);
|
||||
|
||||
CVoipMSSMSSettings mVOIPMsSettings;
|
||||
|
||||
QDate mCurStartDate;
|
||||
|
||||
|
||||
signals:
|
||||
void DIDSFetched(QStringList);
|
||||
|
||||
public slots:
|
||||
void VoipServerReplyFinished(QNetworkReply*);
|
||||
|
||||
Reference in New Issue
Block a user