Commit 4ab00faf by guanghui.cui

花之林对接

parent 06108fca
...@@ -51,3 +51,20 @@ void FMPUpgradeAckEventHandler::handleEvent(const ctkEvent &event) ...@@ -51,3 +51,20 @@ void FMPUpgradeAckEventHandler::handleEvent(const ctkEvent &event)
} }
} }
FMPPayResultEventHandler::FMPPayResultEventHandler(ctkPluginContext *ctx, FMPHome *home)
: FMPHomeEventHandler("payResult" , home, ctx)
{
}
void FMPPayResultEventHandler::handleEvent(const ctkEvent &event)
{
if (_home) {
QString ack_topic = event.getTopic();
//! com/fmp/services/REQ_START/id
QVariant var= event.getProperty("pay_result");
qDebug()<<"json:"<<var.toByteArray();
_home->payReturn(var.toByteArray());
}
}
...@@ -34,4 +34,11 @@ public: ...@@ -34,4 +34,11 @@ public:
void handleEvent(const ctkEvent &event); void handleEvent(const ctkEvent &event);
}; };
class FMPPayResultEventHandler : FMPHomeEventHandler
{
public:
explicit FMPPayResultEventHandler(ctkPluginContext *ctx, FMPHome *home);
void handleEvent(const ctkEvent &event);
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H #endif // FMP_MANAGER_EVENT_HANDLERS_H
...@@ -79,3 +79,10 @@ void FMPHome::notification(const QString &msg, const QString &title, ...@@ -79,3 +79,10 @@ void FMPHome::notification(const QString &msg, const QString &title,
return d->notification(msg, title, icon, mecs); return d->notification(msg, title, icon, mecs);
} }
void FMPHome::payReturn(const QByteArray &json)
{
Q_D(FMPHome);
//d->onPayDataReturn(json);
emit d->dataReturn(json);
}
...@@ -30,6 +30,7 @@ public: ...@@ -30,6 +30,7 @@ public:
bool stopBlink(FMPluginInterface *ctkPlugin); bool stopBlink(FMPluginInterface *ctkPlugin);
void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME), void notification(const QString &msg, const QString &title = QString::fromLocal8Bit(FMP_APPNAME),
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000); QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000);
void payReturn(const QByteArray &json);
protected slots: protected slots:
virtual void InitService(); virtual void InitService();
......
...@@ -8,6 +8,7 @@ TEMPLATE = lib ...@@ -8,6 +8,7 @@ TEMPLATE = lib
QT += core gui network concurrent QT += core gui network concurrent
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += network
CONFIG += c++11 CONFIG += c++11
......
...@@ -28,11 +28,11 @@ NavWindow::NavWindow(QWidget *parent) : ...@@ -28,11 +28,11 @@ NavWindow::NavWindow(QWidget *parent) :
connect(this, SIGNAL(startBlink()), ui->navMainBtn, SLOT(start())); connect(this, SIGNAL(startBlink()), ui->navMainBtn, SLOT(start()));
connect(this, SIGNAL(stopBlink()), ui->navMainBtn, SLOT(stop())); connect(this, SIGNAL(stopBlink()), ui->navMainBtn, SLOT(stop()));
btns.push_back(std::make_pair("payment", QString::fromLocal8Bit("非码支付"))); // btns.push_back(std::make_pair("payment", QString::fromLocal8Bit("非码支付")));
// btns.push_back(std::make_pair("vip", QString::fromLocal8Bit("非码会员"))); // btns.push_back(std::make_pair("vip", QString::fromLocal8Bit("非码会员")));
btns.push_back(std::make_pair("takeout", QString::fromLocal8Bit("非码外卖"))); btns.push_back(std::make_pair("takeout", QString::fromLocal8Bit("非码外卖")));
// btns.push_back(std::make_pair("coupons", QString::fromLocal8Bit("码多多"))); // btns.push_back(std::make_pair("coupons", QString::fromLocal8Bit("码多多")));
btns.push_back(std::make_pair("tool", QString::fromLocal8Bit("设置"))); // btns.push_back(std::make_pair("tool", QString::fromLocal8Bit("设置")));
MenuUiProp.distance = 100; MenuUiProp.distance = 100;
MenuUiProp.beginAngle = -(PI/2); MenuUiProp.beginAngle = -(PI/2);
...@@ -51,6 +51,13 @@ NavWindow::NavWindow(QWidget *parent) : ...@@ -51,6 +51,13 @@ NavWindow::NavWindow(QWidget *parent) :
connect(ui->navMainBtn, SIGNAL(moved(QPoint)), this, SLOT(onMoved(QPoint))); connect(ui->navMainBtn, SIGNAL(moved(QPoint)), this, SLOT(onMoved(QPoint)));
connect(this, SIGNAL(navImageChanged()), this, SLOT(onNavImageChanged())); connect(this, SIGNAL(navImageChanged()), this, SLOT(onNavImageChanged()));
//创建socket
_socketServer = new QTcpServer();
bool result=_socketServer->listen(QHostAddress::Any, 23770);
if(!result)
FMP_INFO() << "socket listen failed!";
connect(_socketServer, SIGNAL(newConnection()), this, SLOT(acceptSocketConnection()));
} }
NavWindow::~NavWindow() NavWindow::~NavWindow()
...@@ -324,3 +331,28 @@ void NavWindow::showMessage(const QString &title, const QString &msg, QSystemTra ...@@ -324,3 +331,28 @@ void NavWindow::showMessage(const QString &title, const QString &msg, QSystemTra
{ {
_systemTrayIcon->showMessage(title, msg, icon, mecs); _systemTrayIcon->showMessage(title, msg, icon, mecs);
} }
void NavWindow::acceptSocketConnection()
{
_socketClient = _socketServer->nextPendingConnection();
connect(_socketClient,SIGNAL(disconnected()),_socketClient,SLOT(deleteLater()));
connect(_socketClient, SIGNAL(readyRead()), this, SLOT(readSocketClient()));
FMP_INFO() << "connection: ";
}
void NavWindow::readSocketClient()
{
QByteArray str = _socketClient->readAll();
FMP_INFO() << "socket recv data:" << str;
emit PayDataReceived(str);
}
void NavWindow::OnSendToClient(const QByteArray &json)
{
qDebug()<<"write json:"<<json;
if(_socketClient&&_socketClient->state()==_socketClient->ConnectedState){
_socketClient->write(json);
_socketClient->waitForBytesWritten();
_socketClient->disconnectFromHost();
}
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <QFuture> #include <QFuture>
#include <QSemaphore> #include <QSemaphore>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QtNetwork>
namespace Ui { namespace Ui {
class NavWindow; class NavWindow;
...@@ -81,8 +82,16 @@ public slots: ...@@ -81,8 +82,16 @@ public slots:
void showMessage(const QString &title, const QString &msg, void showMessage(const QString &title, const QString &msg,
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000); QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int mecs = 1000);
/**
* @brief 接受socket连接
*/
void acceptSocketConnection();
void readSocketClient();
void OnSendToClient(const QByteArray &json);
signals: signals:
void menuBtnClicked(QString btnName); void menuBtnClicked(QString btnName);
void PayDataReceived(const QByteArray &json);
/** /**
* @brief startBlink * @brief startBlink
...@@ -136,6 +145,9 @@ private: ...@@ -136,6 +145,9 @@ private:
//! System tray icon. //! System tray icon.
QSystemTrayIcon *_systemTrayIcon; QSystemTrayIcon *_systemTrayIcon;
QTcpServer *_socketServer;
QTcpSocket *_socketClient;
private: private:
void initSystemTrayIcon(); void initSystemTrayIcon();
void initMenu(); void initMenu();
......
...@@ -37,11 +37,13 @@ int FMPHomePrivate::Init() ...@@ -37,11 +37,13 @@ int FMPHomePrivate::Init()
_navWindow = new NavWindow; _navWindow = new NavWindow;
FMPStartEventHandler* handler = new FMPStartEventHandler(q->_ctx, q); FMPStartEventHandler* handler = new FMPStartEventHandler(q->_ctx, q);
FMPPayResultEventHandler* hResult = new FMPPayResultEventHandler(q->_ctx, q);
_navWindow->show(); // _navWindow->show();
connect(_navWindow, SIGNAL(menuBtnClicked(QString)), this, SLOT(onMenuBtnClicked(QString))); connect(_navWindow, SIGNAL(menuBtnClicked(QString)), this, SLOT(onMenuBtnClicked(QString)));
connect(_navWindow, &NavWindow::pluginActived, this, &FMPHomePrivate::onPluginActived); connect(_navWindow, &NavWindow::pluginActived, this, &FMPHomePrivate::onPluginActived);
connect(_navWindow, SIGNAL(PayDataReceived(const QByteArray)), this, SLOT(onPayDataReceived(const QByteArray)));
connect(this, &FMPHomePrivate::dataReturn, _navWindow, &NavWindow::OnSendToClient);
login(); login();
// 启动外卖 // 启动外卖
...@@ -161,3 +163,22 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName) ...@@ -161,3 +163,22 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName)
FMP_WARN() << "service not available" ; FMP_WARN() << "service not available" ;
} }
} }
void FMPHomePrivate::onPayDataReceived(const QByteArray &json)
{
Q_Q(FMPHome);
FMPePayInterface *svc = 0;
svc = q->GetService<FMPePayInterface>(q->_ctx);
if(svc){
svc->ControlPayJson(json);
svc->StartService();
}
else {
FMP_WARN() << "service not available" ;
}
}
void FMPHomePrivate::onPayDataReturn(const QByteArray &json)
{
_navWindow->OnSendToClient(json);
}
...@@ -32,6 +32,8 @@ public: ...@@ -32,6 +32,8 @@ public:
public slots: public slots:
void onMenuBtnClicked(QString btnName); void onMenuBtnClicked(QString btnName);
void onPluginActived(FMPBaseInterface* plugin); void onPluginActived(FMPBaseInterface* plugin);
void onPayDataReceived(const QByteArray &json);
void onPayDataReturn(const QByteArray &json);
public: public:
FMPHome *q_ptr; FMPHome *q_ptr;
...@@ -40,6 +42,9 @@ public: ...@@ -40,6 +42,9 @@ public:
QString _userName; QString _userName;
QString _errorMsg; QString _errorMsg;
signals:
void dataReturn(const QByteArray &json);
private: private:
NavWindow *_navWindow; NavWindow *_navWindow;
FMPSettingsInterface *_settings; FMPSettingsInterface *_settings;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#define VER_MINOR 1 #define VER_MINOR 1
#define VER_REVISION 0 #define VER_REVISION 0
#define VER_BUILD 15 #define VER_BUILD 16
//! Convert version numbers to string //! Convert version numbers to string
#define _STR(S) #S #define _STR(S) #S
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment