Commit 5e7e920b by 李定达

1.添加请求道response的转换

parent a0e84269
build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug/
build-sbkpay-Desktop_Qt_5_5_1_MSVC2010_32bit-Debug/
......@@ -126,6 +126,26 @@ public:
}
static void SetString(void *beginptr, int size, const QString &in)
{
char buf[MAX_CHILED_LEN] = { 0 };
char tmpbuf[MAX_CHILED_LEN] = { 0 };
memset(beginptr, ' ', size);
if(in.isEmpty())
return ;
strcpy(buf, in.toUtf8().data());
int len = UTF8ToGBK((unsigned char *)buf, (unsigned char *)tmpbuf, MAX_CHILED_LEN);
strncpy((char *)beginptr, tmpbuf, len - 1);
qDebug() << tmpbuf;
}
};
......
......@@ -3,7 +3,9 @@
#define MAX_BUF_LEN 25600
#define MAX_CHILED_LEN 256
#define MAX_PRINT_LEN 4096
#define PRINT_FILE_NAME "print.txt"
#define USERCONFIG_NAME "config.ini"
#define ENCODE_FIRST "encode/first"
......@@ -23,6 +25,13 @@
#define JSON_KEY_TRANSAMOUNT "transAmount"
#define JSON_KEY_REFUNDAMOUT "refundAmount"
//response
#define JSON_KEY_MESSAGE "message"
#define JSON_KEY_STATUSCODE "statusCode"
#define JSON_KEY_FMID "fmId"
#define JSON_KEY_EXT "ext"
#define JSON_KEY_PRINT "print"
#define JSON_KEY_UNAMOUNT "undiscountAmount"
//array products
......
......@@ -10,6 +10,7 @@
#include <QJsonParseError>
#include <QJsonDocument>
//接受pos的请求转化为json
class JsonFactory
{
public:
......
......@@ -4,9 +4,70 @@
#include "control.h"
#include "global.h"
#include "QsLog.h"
#include "requestmodel.h"
#include "fmtool.h"
#include "rspfactory.h"
#include <QDir>
#include <QApplication>
void TestSetString()
{
AlipayResponse repon;
FMTool::SetString(repon.ResponseMsg, 40, QString("傻逼"));
}
void TestSetPinter()
{
AlipayResponse repon;
QJsonObject obj, json;
obj.insert("print", "为了宽宏大量分开打女生短发设计开发");
json.insert("ext", obj);
RspFactory::SetPinter(repon, json);
qDebug() << "lalal";
}
void TestGetResPonseJson()
{
AlipayResponse repon;
QJsonObject obj, json;
obj.insert("print", "为了宽宏大量分开打女生短发设计开发");
json.insert("ext", obj);
json.insert("fmId", "asdashdgajshdg11111111111111111");
json.insert("statusCode", 100);
json.insert("message", "哇哈哈");
RspFactory::GetResPonseJson(pay, repon, json);
qDebug() << "lalal";
json.insert("statusCode", 204);
json.insert("message", "哇哈哈有毒");
RspFactory::GetResPonseJson(refund, repon, json);
qDebug() << "lalal";
}
void TestGetResPonseWithError()
{
AlipayResponse repon;
RspFactory::GetResPonseWithError(repon, "201", "山茶花");
qDebug() << "lalal";
}
int main(int argc, char *argv[])
{
......@@ -28,8 +89,20 @@ int main(int argc, char *argv[])
QsLogging::DestinationPtr consleDest(QsLogging::DestinationFactory::MakeDebugOutputDestination());
logger.addDestination(consleDest);
//pass
TestSetString();
//pass
TestGetResPonseWithError();
//pass
TestSetPinter();
//pass
TestGetResPonseJson();
Control control;
char as[] = "ak10dh171300000000000 *#dhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
char b[MAX_BUF_LEN] = {0};
......
......@@ -23,7 +23,7 @@ struct EFTItem
struct AlipayResponse
{
char ResponseCode[2]; //返回码。
char ResponseCode[3]; //返回码
char ResponseMsg[40]; //返回文字信息
char Amount[12]; //订单金额(与wxpayRequest.Amount一致)
char SettleNum[6]; //
......@@ -31,7 +31,7 @@ struct AlipayResponse
char TerminalID[8]; //
char TransDate[8]; //交易日期
char TransTime [6]; //交易时间
char CardTraceNo[64]; //订单号
char CardTraceNo[64]; //订单号(非码交易号)
char NeedPrint[2]; //是否打印小票. 00:表示打印小票, 01:表示不打印小票
char EFTprintFileName[200]; //打印文件路径.
char MD5_CHECK_CODE [32]; //
......
#ifndef RSPFACTORY
#define RSPFACTORY
#include "requestmodel.h"
#include "global.h"
#include "fmtool.h"
#include <QFile>
#include <QJsonObject>
#include <QApplication>
class RspFactory
{
public:
static bool GetResPonseJson(ReqType type, AlipayResponse &response, const QJsonObject &json)
{
if(json.isEmpty())
return false;
memset(&response, ' ', sizeof(response));
if(type == pay)
return GetPayResponse(response, json);
if(type == refund)
return GetRefundResponse(response, json);
if(type == endday)
return GetDayEndResponse(response, json);
if(type == againprint)
return GetAgainPrinteResponse(response, json);
if(type == find)
return GetFindResponse(response, json);
return false;
}
static bool GetResPonseWithError(AlipayResponse &response, QString errorcode, QString message)
{
if(errorcode.isEmpty() || message.isEmpty())
return false;
memset(&response, ' ', sizeof(response));
FMTool::SetString(response.ResponseCode, 3, errorcode);
FMTool::SetString(response.ResponseMsg, 3, message);
return true;
}
#ifndef FM_TEST
private:
#endif
static bool GetPayResponse(AlipayResponse &response, const QJsonObject &json)
{
FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
FMTool::SetString(response.ResponseMsg, 40, json[JSON_KEY_MESSAGE].toString());
FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
FMTool::SetString(response.NeedPrint, 2, QString("01"));
if(json[JSON_KEY_STATUSCODE].toInt() == 100)
return SetPinter(response, json);
return true;
}
static bool GetRefundResponse(AlipayResponse &response, const QJsonObject &json)
{
FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
FMTool::SetString(response.ResponseMsg, 40, json[JSON_KEY_MESSAGE].toString());
FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
FMTool::SetString(response.NeedPrint, 2, QString("01"));
if(json[JSON_KEY_STATUSCODE].toInt() == 100)
return SetPinter(response, json);
return true;
}
static bool GetDayEndResponse(AlipayResponse &response, const QJsonObject &json)
{
return false;
}
static bool GetAgainPrinteResponse(AlipayResponse &response, const QJsonObject &json)
{
return false;
}
static bool GetFindResponse(AlipayResponse &response, const QJsonObject &json)
{
return false;
}
static bool SetPinter(AlipayResponse &response, const QJsonObject &json)
{
if(!json.contains(JSON_KEY_EXT) || !json[JSON_KEY_EXT].isObject())
return false;
FMTool::SetString(response.NeedPrint, 2, QString("01"));
QJsonObject obj = json[JSON_KEY_EXT].toObject();
QString str = obj[JSON_KEY_PRINT].toString();
QFile file(qApp->applicationDirPath() + "/" + PRINT_FILE_NAME);
FMTool::SetString(response.EFTprintFileName, 200, QString(qApp->applicationDirPath() + "/" + PRINT_FILE_NAME));
file.open(QFile::WriteOnly);
if(!file.isOpen())
return false;
char buf[MAX_PRINT_LEN] = { 0 };
FMTool::SetString(buf, str.toUtf8().length(), str);
file.write(buf);
file.flush();
file.close();
return true;
}
};
#endif // RSPFACTORY
......@@ -31,7 +31,8 @@ HEADERS += hostwidget.h \
fmerror.h \
fmtool.h \
jsonfactory.h \
labelstimer.h
labelstimer.h \
rspfactory.h
FORMS += hostwidget.ui
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2017-08-10T10:02:51. -->
<!-- Written by QtCreator 3.5.1, 2017-08-11T14:08:55. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
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