Commit d75b38fb by Carwyn

1.支付模块独立项目上传

parent b5ea4794
#include "fmnumpad.h"
#include "ui_fmnumpad.h"
#include <QLineEdit>
FMNumPad::FMNumPad(QWidget *parent) :
QWidget(parent),
ui(new Ui::FMNumPad),
_lineEdit(nullptr)
{
ui->setupUi(this);
connect(ui->no0, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no1, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no2, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no3, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no4, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no5, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no6, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no7, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no8, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->no9, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
connect(ui->dot, &QPushButton::clicked, this, &FMNumPad::on_digit_clicked);
}
FMNumPad::~FMNumPad()
{
delete ui;
}
void FMNumPad::on_digit_clicked()
{
QString num_str = qobject_cast<QPushButton*>(sender())->text();
if(_lineEdit) {
_lineEdit->insert(num_str);
_lineEdit->setFocus();
}
emit digit_click(num_str);
}
void FMNumPad::on_backspace_btn_clicked()
{
if(_lineEdit) {
_lineEdit->backspace();
_lineEdit->setFocus();
}
emit digit_delete();
}
void FMNumPad::on_clear_btn_clicked()
{
if(_lineEdit) {
_lineEdit->clear();
_lineEdit->setFocus();
}
emit digit_clear();
}
void FMNumPad::on_confirm_btn_clicked()
{
emit digit_confirm();
}
void FMNumPad::setLineEdit(QLineEdit *lineEdit)
{
Q_ASSERT(nullptr != lineEdit);
this->_lineEdit = lineEdit;
}
#ifndef FMNUMPAD_H
#define FMNUMPAD_H
#include <QWidget>
class QLineEdit;
namespace Ui {
class FMNumPad;
}
class FMNumPad : public QWidget
{
Q_OBJECT
public:
explicit FMNumPad(QWidget *parent = 0);
~FMNumPad();
void setLineEdit(QLineEdit* lineEdit);
signals:
void digit_click(QString keynum);
void digit_delete();
void digit_clear();
void digit_confirm();
private slots:
void on_digit_clicked();
void on_backspace_btn_clicked();
void on_clear_btn_clicked();
void on_confirm_btn_clicked();
private:
Ui::FMNumPad *ui;
QLineEdit *_lineEdit;
};
#endif // FMNUMPAD_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FMNumPad</class>
<widget class="QWidget" name="FMNumPad">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>246</width>
<height>234</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true">QWidget {
font: normal 22px &quot;Microsoft YaHei&quot;;
color: rgb(90,90,90);
}
#FMNumPad {
background-color: rgb(249, 249, 249);
border: 1 solid silver;
}
/*
* 标题栏
*/
#title {
background: rgb(61,65,77);
min-height: 32px; max-height: 32px;
border: 1 solid silver;
border-bottom: 0 solid silver;
}
#title_label {
margin-left: 4px;
font: normal 15px &quot;Microsoft YaHei&quot;;
color: rgb(252,252,252);
}
#close_btn {
min-width: 32px; min-height: 32px;
max-width: 32px; max-height: 32px;
border-image: url(&quot;:/img/btn_close.png&quot;);
background: transparent;
}
#close_btn:hover{
min-width: 31px; min-height: 31px;
max-width: 31px; max-height: 31px;
border-image: url(&quot;:/img/btn_alert_close.png&quot;);
}
QPushButton {
min-width: 50px; min-height: 50px;
max-width: 50px; max-height: 50px;
background-color: rgb(255, 255, 255);
font: 75 18pt &quot;微软雅黑&quot;;
border-radius: 12px;
border: 1 solid silver;
color: rgb(57, 57, 57);
}
QPushButton:hover {
background-color: rgb(249, 249, 249);
border:2px solid rgb(99, 148, 235);
border-radius:12px;
color: rgb(99, 148, 235);
padding: 2 0 0 2;
}
#no0 {
min-width: 106px;
max-width: 106px;}
#backspace_btn, #clear_btn {
font: normal 16px &quot;Microsoft YaHei&quot;;
}
#backspace_btn {
image: url(:/img/dlt02.png);
}
#backspace_btn:hover {
image: url(:/img/dlt01.png);
}
#dot
{
background-color: rgb(255, 255, 255);
image: url(:/img/dot01.png);
}
#dot:hover
{
background-color: rgb(249, 249, 249);
image: url(:/img/dot02.png);
}
#confirm_btn {
background: rgb(93,144,237);
font: 400 16px &quot;Microsoft YaHei&quot;;
color: white;
min-height: 106px;
max-height: 106px;
border: 0 solid white;
border-right: 1 solid silver;
}
#confirm_btn:hover {
padding: 2 0 0 2;
background-color: rgb(249, 249, 249);
border:2px solid rgb(99, 148, 235);
border-radius:12px;
color: rgb(99, 148, 235);
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>8</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<item row="1" column="3">
<widget class="QPushButton" name="clear_btn">
<property name="text">
<string>清空</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="no0">
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="no9">
<property name="text">
<string>9</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="no6">
<property name="text">
<string>6</string>
</property>
</widget>
</item>
<item row="2" column="3" rowspan="2">
<widget class="QPushButton" name="confirm_btn">
<property name="text">
<string>确认</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="no1">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="no2">
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="no3">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="no5">
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="no4">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="backspace_btn">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="dot">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="no7">
<property name="text">
<string>7</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="no8">
<property name="text">
<string>8</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "fmp_database.h"
#include <QDebug>
#include <QSqlError>
#include <QSqlQuery>
#include <QVariantHash>
#include <QSqlQueryModel>
#include <fmp_logger_i.h>
FMPDataBase::FMPDataBase(QString dbname, FMPLoggerInterface *logger, QString connectname, QObject *parent) : QObject(parent), _logger(logger)
{
_db = QSqlDatabase::addDatabase("QSQLITE", connectname);
_db.setDatabaseName(dbname);
_isopen = _db.open();
}
FMPDataBase::~FMPDataBase()
{
if(_isopen)
_db.close();
}
bool FMPDataBase::creat(QString sql)
{
if(!_isopen)
return false;
QSqlQuery query(_db);
bool flag = query.exec(sql);
if(!flag)
FMP_WARN(_logger) << query.lastError();
return flag;
}
bool FMPDataBase::dlt(QString table, QString condition)
{
if(!_isopen)
return false;
QString sql = QString("delete from %1 where %2").arg(table, condition);
QSqlQuery query(_db);
bool flag = query.exec(sql);
if(!flag)
FMP_WARN(_logger) << query.lastError();
return flag;
}
bool FMPDataBase::insert(QString table, QVariantHash data)
{
if(!_isopen)
return false;
QString sql;
QStringList columnnamelist;
QStringList columnvaluelist;
if(!getSql(table, data, columnnamelist, columnvaluelist))
{
_db.close();
return false;
}
QSqlQuery query(_db);
sql = QString("insert into %1 (").arg(table) + columnnamelist.join(", ") + ") values (" + columnvaluelist.join(", ") + ")";
FMP_INFO(_logger) << "inset sql : " << sql;
qDebug() << "inset sql : " << sql;
bool flag = query.exec(sql);
if(!flag)
FMP_WARN(_logger) << query.lastError();
return flag;
}
bool FMPDataBase::update(QString table, QVariantHash data, QString condition)
{
if(!_isopen)
return false;
QString sql;
if(!getSql(table, data, sql))
{
_db.close();
return false;
}
QSqlQuery query(_db);
sql = QString("update %1 set ").arg(table) + sql + " where " + condition;
FMP_INFO(_logger) << "update sql : " << sql;
bool flag = query.exec(sql);
if(!flag)
FMP_WARN(_logger) << query.lastError();
return flag;
}
bool FMPDataBase::find(QString table, QSqlQuery &query, QStringList keylist, QString condition)
{
if(!_isopen)
return false;
QSqlQuery tmpquery(_db);
QString sql = "select ";
if(keylist.size() != 0)
sql += keylist.join(", ");
else
sql += "*";
if(condition == "")
condition = "1=1";
sql += QString(" from %1 where ").arg(table) + condition;
FMP_INFO(_logger) << "find sql : " << sql;
bool flag = tmpquery.exec(sql);
if(!flag)
FMP_WARN(_logger) << tmpquery.lastError();
query = tmpquery;
return flag;
}
bool FMPDataBase::getSql(QString table, QVariantHash data, QStringList& columnnamelist, QStringList& columnvaluelist)
{
QSqlQuery query(_db);
QString tmpsql = QString("PRAGMA table_info(%1)").arg(table);
query.exec(tmpsql);
while(query.next())
{
QString columnname = query.value(1).toString();
if(data.contains(columnname))
{
/**
*add support type;
* */
// switch (data.value(columnname).type()) {
// case QVariant::Int:
// columnnamelist.append(columnname);
// columnvaluelist.append(QString("'") + QString::number(data.value(columnname).toInt()) + "'");
// break;
// case QVariant::String:
// columnnamelist.append(columnname);
// columnvaluelist.append(QString("'") + data.value(columnname).toString() + "'");
// break;
// case QVariant::Bool:
// columnnamelist.append(columnname);
// columnvaluelist.append(QString("'") + QString::number(data.value(columnname).toBool()? 1 : 0) + "'");
// break;
// default:
// break;
// }
columnnamelist.append(columnname);
columnvaluelist.append(QString("'") + data.value(columnname).toString() + "'");
}
continue ;
}
if(columnnamelist.size() == 0)
return false;
return true;
}
QSqlDatabase FMPDataBase::getDb() const
{
return _db;
}
bool FMPDataBase::getSql(QString table, QVariantHash data, QString& sql)
{
QSqlQuery query(_db);
QString tmpsql = QString("PRAGMA table_info(%1)").arg(table);
query.exec(tmpsql);
QStringList list;
while(query.next())
{
QString columnname = query.value(1).toString();
if(data.contains(columnname))
{
/**
*add support type(mysql/sqlserver/...);
* */
// switch (data.value(columnname).type()) {
// case QVariant::Int:
// list.append(columnname + " = '" + QString::number(data.value(columnname).toInt()) + "'");
// break;
// case QVariant::String:
// list.append(columnname + " = '" + data.value(columnname).toString() + "'");
// break;
// case QVariant::Bool:
// list.append(columnname + " = '" + QString::number(data.value(columnname).toBool()? 1 : 0) + "'");
// break;
// default:
// break;
// }
/**
* sqlite
* */
list.append(columnname + " = '" + data.value(columnname).toString() + "'");
}
continue ;
}
if(list.size() == 0)
return false;
sql = list.join(", ");
return true;
}
#ifndef FMP_DATABASE_H
#define FMP_DATABASE_H
#include <QObject>
#include <QSqlDatabase>
#include "fmp_epay_def.h"
class FMPLoggerInterface;
class QSqlQuery;
class QSqlDatabase;
class FMPDataBase : public QObject
{
Q_OBJECT
public:
FMPDataBase(QString dbname, FMPLoggerInterface *logger, QString connectname = QString(DEFAULT_EPAY_CONNECTNAME), QObject *parent = 0);
~FMPDataBase();
bool insert(QString table, QVariantHash data);
bool update(QString table, QVariantHash data, QString condition);
bool find(QString table, QSqlQuery &query, QStringList keylist = QStringList(), QString condition = QString(""));
bool creat(QString sql);
bool dlt(QString table, QString condition);
QSqlDatabase getDb() const;
private:
bool exist(QString table);
bool getSql(QString table, QVariantHash data, QString &sql);
bool getSql(QString table, QVariantHash data, QStringList &columnnamelist, QStringList &columnvaluelist);
private:
QSqlDatabase _db;
FMPLoggerInterface *_logger;
bool _isopen;
};
#endif // FMP_DATABASE_H
#include "fmp_epay_p.h"
#include "fmp_epay_def.h"
#include "fmp_pe_handlers.h"
#include <QDateTime>
class ctkPluginContext;
FMPePay::FMPePay(ctkPluginContext *context)
: FMPePayInterface(context),
_url(DEFAULT_EPAY_RWQUESTURL),
_inited(false),
_databasename(DEFAULT_EPAY_DATABASENAME),
_table(DEFAULT_EPAY_TABLE),
_businessdate(QDateTime::currentDateTime().toString("yyyy-MM-dd")),
_ordershelflife(DEFAULT_EPAY_ORDERLIFE),
_operator_id(DEFAULT_EPAY_OPTID),
_store_id(DEFAULT_EPAY_STRID),
_station_id(DEFAULT_EPAY_STNID),
_ste_handler(new FMPStartEventHandler(_ctx, this)),
d_ptr(new FMPePayPrivate(this))
{
}
int FMPePay::StopService()
{
if (!_inited) return FMP_SUCCESS;
Q_D(FMPePay);
return d->StopService();
}
int FMPePay::Pay()
{
Q_D(FMPePay);
return d->Pay();
}
void FMPePay::SetBasicInfo(QVariantHash hash)
{
Q_D(FMPePay);
this->_businessdate = hash[FMP_BASIC_BUSINESSDATE].toString();
d->SetBasicInfo(hash);
}
#ifndef FMP_EPAY_H
#define FMP_EPAY_H
#include <QObject>
#include <QPointer>
#include "fmp_epay_i.h"
class FMPePayPrivate;
class FMPStartEventHandler;
class FMPePay : public QObject, public FMPePayInterface
{
Q_OBJECT
Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPePayInterface)
Q_DECLARE_PRIVATE(FMPePay)
public:
FMPePay(ctkPluginContext *context);
int StopService();
int Pay();
void SetBasicInfo(QVariantHash hash);
private:
bool _inited;
QString _url;
QString _databasename;
QString _table;
QString _businessdate;
QString _store_id;
QString _station_id;
QString _operator_id;
//销售单保存时间
int _ordershelflife;
FMPePayPrivate* d_ptr;
QPointer<FMPStartEventHandler> _ste_handler;
};
#endif // FMP_EPAY_H
#-------------------------------------------------
#
# Project created by QtCreator 2017-01-11T15:59:15
#
#-------------------------------------------------
TEMPLATE = lib
QT += core gui network sql concurrent
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
SOURCES += \
fmp_epay.cpp \
fmp_epay_p.cpp \
fmp_epay_plugin.cpp \
fmp_epayview_dialog.cpp \
fmp_epayview_wait.cpp \
fmp_database.cpp \
fmp_pe_handlers.cpp \
fmnumpad.cpp
HEADERS +=\
fmp_epay.h \
fmp_epay_i.h \
fmp_epay_p.h \
fmp_epay_plugin_p.h \
fmp_epay_def.h \
fmp_epayview_dialog.h \
fmp_epayview_focuslineedit.h \
fmp_epayview_wait.h \
fmp_database.h \
fmp_epay_checkmodel.h \
fmp_pe_handlers.h \
fmnumpad.h
unix {
target.path = /usr/lib
INSTALLS += target
}
#Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET)
ORIGIN_TARGET = $$TARGET
TARGET = $${TARGET}_$${VER}
#Header path
INCLUDEPATH += $$PWD/../include/ctk \
+= $$PWD/../include/interface \
#Library path
LIBS += -L$$PWD/../lib
CONFIG(debug, debug|release) {
#Linking library
LIBS += -lCTKCored -lCTKPluginFrameworkd -lfmcrypt -lws2_32 -lDbgHelp
#Destination path
DESTDIR = $$PWD/../debug/plugins
} else {
LIBS += -lCTKCore -lCTKPluginFramework
DESTDIR = $$PWD/../release/plugins
}
#
RESOURCES += \
res/$${ORIGIN_TARGET}.qrc \
res/img.qrc
win32 {
RC_FILE += res/$${ORIGIN_TARGET}.rc
system($$PWD/../fmprc.bat $$PWD/version.h $$ORIGIN_TARGET)
}
else {
system($$PWD/../fmprc.sh $$PWD/version.h $$ORIGIN_TARGET)
}
FORMS += \
fmp_epayview_dialog.ui \
fmp_epayview_wait.ui \
fmnumpad.ui
#ifndef FMPT_H
#define FMPT_H
#include <QSqlTableModel>
#include <QStyledItemDelegate>
class FMPPayCheckModel : public QSqlTableModel
{
public:
explicit FMPPayCheckModel(QObject *parent, QSqlDatabase db) : QSqlTableModel(parent, db)
{
}
QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const
{
if (idx.column() == 6 && role == Qt::DisplayRole) {
QVariant d = QSqlTableModel::data(idx,role);
return d.toString().toFloat() / 100;
}
if ((idx.column() == 12) && role == Qt::DisplayRole) {
QVariant d = QSqlTableModel::data(idx,role);
if (d.toBool()) {
return QString::fromLocal8Bit("已退款");
}
else
{
return QString::fromLocal8Bit("未退款");
}
}
return QSqlTableModel::data(idx, role);
}
};
class FMPPayItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit FMPPayItemDelegate()
{
}
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
}
QWidget * createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE
{
return 0;
}
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QStyledItemDelegate::sizeHint(option, index);
}
};
#endif // FMPT_H
#ifndef FMP_EPAY_DEF
#define FMP_EPAY_DEF
//公用字段
#define FMP_EPAY_VER "ver"
#define FMP_EPAY_CLIENTREQCOUNT "clientReqCount"
#define FMP_EPAY_BUSINESSDATE "business_date"
#define FMP_EPAY_OPERATORID "operator_id"
#define FMP_EPAY_REQUESTTYPE "reqtype"
#define FMP_EPAY_STATIONID "station_id"
#define FMP_EPAY_STOREID "store_id"
#define FMP_EPAY_TRANSID "trans_id"
#define FMP_EPAY_TRANSTRACTION "transactions"
#define FMP_EPAY_TRANSTRACTION_AMOUNT "amount"
#define FMP_EPAY_TRANSTRACTION_CODE "code"
//支付返回
#define FMP_RPAY_PAY_RETURN_PAYID "pay_id"
#define FMP_RPAY_PAY_RETURN_TRANSID "pay_transId"
#define FMP_RPAY_PAY_RETURN_EBCODE "pay_ebcode"
#define FMP_RPAY_PAY_RETURN_TOTAL "total_amount"
#define FMP_RPAY_PAY_RETURN_MCUPON "mcoupon_amount"
#define FMP_RPAY_PAY_RETURN_ALIPAY "alipay_amount"
#define FMP_RPAY_PAY_RETURN_STATUSCODE "statusCode"
#define FMP_RPAY_PAY_RETURN_MSG "msg"
//退款请求
#define FMP_EPAY_REFUND_TRANSTRACTION_FMID "fmId"
#define FMP_EPAY_REFUND_TRANSTRACTION_AMOUNT "refund_count"
#define FMP_EPAY_REFUND_TRANSTRACTION_TRANSID "paied_trans_id"
#define FMP_EPAY_REFUND_TRANSTRACTION_EBCODE "paied_ebcode"
//sql字段
#define SQL_KEY_ISREFUND "isrefund"
#define SQL_KEY_REFUND_DATE "refund_date"
#define SQL_KEY_PAYID "pay_id"
#define SQL_KEY_PAYTRANSID "pay_transId"
#define SQL_KEY_TRANSID "trans_id"
#define SQL_KEY_BUSSINEDATE "business_date"
#define SQL_KEY_CODE "code"
#define SQL_KEY_FMID "fmId"
#define SQL_KEY_EBCODE "pay_ebcode"
#define SQL_KEY_TOTALAMOUNT "total_amount"
//缺省
#define DEFAULT_EPAY_RWQUESTURL "http://115.159.142.32:80/api?partner=aisen"
#define DEFAULT_EPAY_DATABASENAME "fmp_test.db"
#define DEFAULT_EPAY_TABLE "fmp_pay"
#define DEFAULT_EPAY_CONNECTNAME "fmp_pay_connect"
#define DEFAULT_EPAY_ORDERLIFE 60
#define DEFAULT_EPAY_STRID "99999"
#define DEFAULT_EPAY_OPTID "02"
#define DEFAULT_EPAY_STNID "01"
//基础信息 营业日/操作员/pos编号
#define FMP_BASIC_BUSINESSDATE "businessdate"
#endif // FMP_EPAY_DEF
#ifndef FMP_EPAY_I_H
#define FMP_EPAY_I_H
#include <fmp_plugin_i.h>
/**
* 业务插件接口,必须继承自 FMPluginInterface
* @brief The FMPePayInterface class
*/
class FMPePayInterface : public FMPluginInterface
{
public:
explicit FMPePayInterface(ctkPluginContext *ctx) : FMPluginInterface(ctx) {}
virtual int Pay() = 0;
// /**
// * @brief ShowPayDialog
// * 呈现支付主界面
// * @return
// */
// virtual int ShowPayDialog() = 0;
// /**
// * @brief ControlPayJson
// * 获取发送支付请求
// * @param sum
// * @param code
// */
// virtual void ControlPayJson(QString sum, QString code) = 0;
// /**
// * @brief ControlRefundJson
// * 获取发送退款请求
// * @param sum
// * @param code(fmID/pay_transId)
// */
// virtual void ControlRefundJson(QString sum, QString code) = 0;
// /**
// * @brief ControlReverseJson
// * 冲正
// */
// virtual void ControlReverseJson() = 0;
};
Q_DECLARE_INTERFACE(FMPePayInterface, "com.fmp.epay")
#endif // FMP_LOGGER_I_H
This diff is collapsed. Click to expand it.
#ifndef FMP_EPAY_P_H
#define FMP_EPAY_P_H
#include "fmp_epay.h"
#include <QObject>
#include <QFuture>
#include <QJsonObject>
class FMPPayDialog;
class FMPSettingsInterface;
class FMPLoggerInterface;
class FMPNetworkInterface;
class FMPDataBase;
class QSqlTableModel;
class FMPePayPrivate : public QObject
{
Q_OBJECT
Q_DECLARE_PUBLIC(FMPePay)
public:
explicit FMPePayPrivate(FMPePay* parent);
~FMPePayPrivate();
int StopService();
int Pay();
void ControlPayJson(QString sum, QString code);
void ControlRefundJson(QString sum, QString code);
void GetCheckMode(QString sum);
void GetMode();
QSqlTableModel *model() const;
private:
void ControlReverseJson();
bool GetRefundJson(const QString &sum, const QString &code, QString ebcode, QString transid);
void GetReverseJson();
bool GetPayJson(const QString &sum, const QString &code);
bool HttpPost(QJsonObject& outjson, QJsonObject json, QString &error, int timeout = 60);
bool CheckReturnJson(QByteArray data, QJsonObject &returnjson);
void SetBasicInfo(QVariantHash hash);
void clearorder();
signals:
void showPayWnd();
void error(QString errormsg);
void finished(QJsonObject json);
public slots:
void onShowPayWnd();
void witedata();
public:
FMPePay *q_ptr;
FMPPayDialog *_payDialog;
FMPSettingsInterface *_setting;
FMPLoggerInterface *_logger;
FMPNetworkInterface *_network;
private:
QJsonObject _current_json;
bool _reverse_flag;
static unsigned int s_ClientReqCount;
FMPDataBase *_db;
QSqlTableModel *_model;
QFutureWatcher<QByteArray> *_watcher;
void HttpPost(const QString &url, const QByteArray &data, QFutureWatcher<QByteArray> *furture, int timeout = 10);
};
#endif // FMP_EPAY_P_H
/*=============================================================================
Library: CTK
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
#include "fmp_epay_plugin_p.h"
#include "fmp_epay.h"
#include <QtPlugin>
#include <QStringList>
#include <QDebug>
FMPePayPlugin::FMPePayPlugin()
: _epay_service(0)
{
}
void FMPePayPlugin::start(ctkPluginContext* context)
{
_epay_service = new FMPePay(context);
context->registerService<FMPePayInterface>( _epay_service);
}
void FMPePayPlugin::stop(ctkPluginContext* context)
{
Q_UNUSED(context)
if (_epay_service)
{
delete _epay_service;
_epay_service = 0;
}
}
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
Q_EXPORT_PLUGIN2(fmp_epay, FMPePayPlugin)
#endif
#ifndef FMP_EPAY_PLUGIN_P_H
#define FMP_EPAY_PLUGIN_P_H
#include <ctkPluginActivator.h>
class FMPePay;
class FMPePayPlugin : public QObject, public ctkPluginActivator
{
Q_OBJECT
Q_INTERFACES(ctkPluginActivator)
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
Q_PLUGIN_METADATA(IID "com_fmp_epay")
#endif
public:
explicit FMPePayPlugin();
void start(ctkPluginContext* context);
void stop(ctkPluginContext* context);
private:
FMPePay* _epay_service;
}; // FMPePayPlugin
#endif // FMP_EPAY_PLUGIN_P_H
#ifndef DIALOG_H
#define DIALOG_H
#include <QJsonObject>
#include <QJsonArray>
#include <QVariantHash>
#include <QJsonDocument>
#include <QModelIndex>
#include <QDateTime>
#include <QTimer>
#include <QDialog>
#include <QLineEdit>
#include "fmp_epayview_wait.h"
#include "fmp_epayview_focuslineedit.h"
class FMPePayPrivate;
class FMPLoggerInterface;
namespace Ui {
class FMPPayDialog;
}
class FMPPayDialog : public QDialog
{
Q_OBJECT
typedef enum
{
TopToBtm = 0,
BtmToTop,
LeftToRight,
RightToLeft
} Movemode;
public:
explicit FMPPayDialog(FMPePayPrivate *control, FMPLoggerInterface *logger, QVariantHash basicinfo, QWidget *parent = 0);
~FMPPayDialog();
public slots:
void showErrorMsg(QString errormsg);
void showSuccessMsg(QJsonObject json);
void onSelectionChanged(QModelIndex idx);
void setBasicInfo(QVariantHash basicinfo);
protected:
void keyPressEvent(QKeyEvent *);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
private slots:
void onWidgetChange();
void onBtnNumClicked();
void onBtnConfirmClicked();
void on_btn_backspace_clicked();
void on_btn_clear_clicked();
void on_btn_close_clicked();
void onLineeditCodeGetFocus();
void on_btn_success_confirm_clicked();
void on_btn_paycheck_clicked();
void on_pushButton_2_clicked();
void on_btn_clear_refund_clicked();
void on_btn_backspace_refund_clicked();
private:
void setPayView();
void setRefundView();
void setCheckView();
void setPaySuccessView(QJsonObject json);
void setRefundSuccessView(QJsonObject json);
bool CheckLineEditSum(QString sum);
bool CheckLineEditCode(QString code);
//-----------
void PlayAnimation(QWidget* target0, QWidget* target1, Movemode movemode);
private:
Ui::FMPPayDialog *ui;
FMPFocusLineEdit *_current_LineEdit;
FMPePayPrivate *_control;
FMPPayWait *_wait;
FMPLoggerInterface *_logger;
//----------
QPushButton* _curt_btn;
bool _success_flag;
bool _is_amt;
bool _b_mouse_pressed;
QPoint _mMovePosition;
};
#endif // DIALOG_H
#ifndef FMP_EPAYVIEW_FOCUSLINEEDIT_H
#define FMP_EPAYVIEW_FOCUSLINEEDIT_H
#include <QLineEdit>
class FMPFocusLineEdit : public QLineEdit
{
Q_OBJECT
public:
FMPFocusLineEdit(QWidget *parent=0): QLineEdit(parent) {}
~FMPFocusLineEdit() {}
signals:
void focusIn();
protected:
void FMPFocusLineEdit::focusInEvent( QFocusEvent *e)
{
QLineEdit::focusInEvent(e);
emit focusIn();
}
};
#endif // FMP_EPAYVIEW_FOCUSLINEEDIT_H
#include "fmp_epayview_wait.h"
#include "fmp_epayview_dialog.h"
#include "ui_fmp_epayview_wait.h"
FMPPayWait::FMPPayWait(QWidget *parent) : QDialog(parent), ui(new Ui::FMPPayWait)
{
ui->setupUi(this);
setAttribute(Qt::WA_TranslucentBackground);
ui->widget->setWindowOpacity(1);
setGeometry(parent->geometry());
this->move(parent->pos());
setWindowFlags(Qt::FramelessWindowHint| Qt::Tool );
connect(ui->btn_confirm, &QPushButton::clicked, this, &FMPPayWait::accept);
qRegisterMetaType<FMPPayWait::Type>("FMPPayWait::Type");
//setStyleSheet("QWidget#mainWdg{background:rgba(110,110,110,0.5)}");
}
FMPPayWait::~FMPPayWait()
{
delete ui;
}
void FMPPayWait::SetContent(FMPPayWait::Type type, const QString &msg)
{
switch (type) {
case FMPPayWait::SUCCESS:
ui->btn_confirm->setVisible(true);
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/loading.png) center no-repeat;}");
break;
case FMPPayWait::ERROR:
ui->btn_confirm->setVisible(true);
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/fmclient-icon_payment_fail.png) center no-repeat;}");
break;
case FMPPayWait::LOADING:
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/loading.png) center no-repeat;}");
ui->btn_confirm->setVisible(false);
break;
default:
ui->btn_confirm->setVisible(true);
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/loading.png) center no-repeat;}");
break;
}
ui->label_msg->setText(msg);
}
#ifndef WAITDIALOG_H
#define WAITDIALOG_H
#include <QDialog>
namespace Ui {
class FMPPayWait;
}
class FMPPayWait : public QDialog
{
Q_OBJECT
public:
explicit FMPPayWait(QWidget *parent = 0);
~FMPPayWait();
typedef enum
{
SUCCESS=0,
ERROR,
LOADING
}Type;
void SetContent(FMPPayWait::Type type, const QString& msg);
private:
Ui::FMPPayWait *ui;
};
#endif // WAITDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FMPPayWait</class>
<widget class="QDialog" name="FMPPayWait">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>508</width>
<height>561</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">#FMPPayWait
{
opacity: 223;
background-color: rgb(148, 148, 148, 0);
}
#label_logo {
background: url(:/img/loading.png) no-repeat center;
}</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="mainWdg" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>182</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>344</width>
<height>222</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>344</width>
<height>222</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#widget
{
background-color: rgb(255, 255, 255);
border-radius:8px;
opacity:0;
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_logo">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_msg">
<property name="minimumSize">
<size>
<width>161</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>-1</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">#label_msg
{
color: rgb(100, 100, 100);
font: 22px &quot;微软雅黑&quot;;
}</string>
</property>
<property name="text">
<string>支付中...</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>57</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_confirm">
<property name="minimumSize">
<size>
<width>121</width>
<height>62</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>62</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#btn_confirm
{
font: normal 26px &quot;微软雅黑&quot;;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
background-color: rgb(93, 144, 236);
color: rgb(255, 255, 255);
}</string>
</property>
<property name="text">
<string>确认</string>
</property>
</widget>
</item>
</layout>
<zorder>verticalSpacer</zorder>
<zorder>verticalSpacer_2</zorder>
<zorder>btn_confirm</zorder>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>181</height>
</size>
</property>
</spacer>
</item>
</layout>
<zorder>verticalSpacer_4</zorder>
<zorder>verticalSpacer_3</zorder>
<zorder></zorder>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include <fmp_logger_i.h>
#include "fmp_pe_handlers.h"
#include "fmp_epay.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPePay *epay)
: FMPePayEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"
+ QString::number(ctx->getPlugin()->getPluginId()), epay),
_ctx(ctx)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
}
void FMPStartEventHandler::handleEvent(const ctkEvent &event)
{
if (_epay) {
if (event.getProperty(FMP_PROPKEY_AGREED).toBool()) {
// _epay->UpgradeOldPlugins(event.getProperty(FMP_PROPKEY_PID_LIST).toList());
_epay->Pay();
}
else {
FMP_WARN_CTX(_ctx) << "Refused start request" << event.getTopic();
}
}
else {
FMP_DEBUG_CTX(_ctx) << "No handler instance for event" << event.getTopic();
}
}
FMPNetWorkEventHandler::FMPNetWorkEventHandler(ctkPluginContext *ctx, FMPePay *epay)
: FMPePayEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_ACK_START "/"
+ QString::number(ctx->getPlugin()->getPluginId()), epay),
_ctx(ctx)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
}
void FMPNetWorkEventHandler::handleEvent(const ctkEvent &event)
{
if (_epay) {
if (event.getProperty(FMP_PROPKEY_AGREED).toBool()) {
_epay->Pay();
}
else {
FMP_WARN_CTX(_ctx) << "Refused start request" << event.getTopic();
}
}
else {
FMP_DEBUG_CTX(_ctx) << "No handler instance for event" << event.getTopic();
}
}
#ifndef FMP_MANAGER_EVENT_HANDLERS_H
#define FMP_MANAGER_EVENT_HANDLERS_H
#include <QObject>
#include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h>
class FMPePay;
class FMPePayEventHandler : public ctkEventHandler
{
public:
explicit FMPePayEventHandler(const QString &topic, FMPePay *epay) : _epay(epay), _topic(topic) {}
protected:
FMPePay* _epay;
const QString _topic;
};
/**
* 升级事件处理类
* @brief The FMPUpgradeEventHandler class
*/
class FMPStartEventHandler : public QObject, public FMPePayEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPePay *epay);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
/**
* 升级事件处理类(网络)
* @brief TheNetWorkFMPUpgradeEventHandler class
*/
class FMPNetWorkEventHandler : public QObject, public FMPePayEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPNetWorkEventHandler(ctkPluginContext *ctx, FMPePay *epay);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
#endif // FMP_MANAGER_EVENT_HANDLERS_H
Plugin-SymbolicName: fmp.epay
Plugin-Version: 0.1.0
Plugin-Name: fmp.epay
Plugin-Copyright: Freemud Ltd. Copyright (C) 2014-2017
Plugin-Vendor: Freemud
<RCC>
<qresource prefix="/fmp.epay/META-INF">
<file>MANIFEST.MF</file>
</qresource>
</RCC>
File added
<RCC>
<qresource prefix="/">
<file>img/fmclient-icon_payment_back.png</file>
<file>img/fmclient-icon_payment_delete.png</file>
<file>img/fmclient-icon_payment_fail.png</file>
<file>img/fmclient-icon_payment_s1.png</file>
<file>img/fmclient-icon_payment_s2.png</file>
<file>img/fmclient-icon_payment_success.png</file>
<file>img/fmclient-icon_payment_t1.png</file>
<file>img/fmclient-icon_payment_t2.png</file>
<file>img/fm-icon_close_02.png</file>
<file>img/loading.png</file>
<file>img/check0.png</file>
<file>img/check1.png</file>
<file>img/dlt01.png</file>
<file>img/dlt02.png</file>
<file>img/dot01.png</file>
<file>img/dot02.png</file>
</qresource>
</RCC>
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by fmproxy_service.rc
// ¶һĬֵ
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
#ifndef _VERSION_H_
#define _VERSION_H_
#define VER_MAJOR 0
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD 35
//! Convert version numbers to string
#define _STR(S) #S
#define STR(S) _STR(S)
#define _MAK_VER(maj, min, rev, build) STR(##maj.##min.##rev.##build\0)
#define MAK_VER(maj, min, rev, build) _MAK_VER(maj, min, rev, build)
//! Resource version infomation
#define RES_FILE_VER VER_MAJOR,VER_MINOR,VER_REVISION,VER_BUILD
#define RES_PRODUCT_VER VER_MAJOR,VER_MINOR,VER_REVISION,VER_BUILD
#define RES_STR_FILE_VER MAK_VER(VER_MAJOR, VER_MINOR, VER_REVISION, VER_BUILD)
#define RES_STR_PRODUCT_VER MAK_VER(VER_MAJOR, VER_MINOR, VER_REVISION, VER_BUILD)
#define RES_COMPANY_NAME "上海非码网络科技有限公司\0"
#define RES_COPYRIGHT "Freemud Ltd. Copyright (C) 2014-2017\0"
#define RES_FILE_DESC "fmp.epay\0"
#define RES_INTER_NAME "fmp.epay\0"
#define RES_FILE_NAME "fmp.epay\0"
#define RES_PRODUCT_NAME "fmp.epay\0"
#define RES_FILE_EXT "*\0"
#endif //!_VERSION_H_
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