cjson调用的实例 c++

主类中文定义

#include <QtGui/QApplication>
#include <QTextCodec>
	QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
	QTextCodec::setCodecForLocale(QTextCodec::codecForLocale());
	QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());

宏定义:

enum dll_error_codes
{
	STATUS_OK = 1,   //成功状态
	DOG_NOTFOUND=-1, //加密狗不存在
	DOG_INVVCODE = -2, //加密狗论证失败
	DOG_SNERROR = -3, //加密狗序列号错误
	DOG_NOLOCAL =-4,  //非本机加密狗
	DOG_GETDTAERROR =-5,  //获取加密狗数据失败
	DOG_DATAERROR =-6,  //加密狗数据非法
	DOG_CDSCOMERROR =-7,  //服务器非本机加密狗硬盘序列号不匹配
	DOG_MACCOMERROR =-8,  //服务器非本机加密狗MAC不匹配
	DOG_STATEERROR =-9,  //加密狗使用状态错误
	DOG_STATECLOSE =-10, //加密狗禁用
	DOG_TOOLERROR =-11, //工具类型不匹配
	DOG_TIMESRROR =-12, //注册次数错误
	DOG_NOTIMES =-13, //注册次数不足,请重新注册
	DOG_VAILDATE =-14, //有效时间范围错误
	DOG_WRITEERROR =-15, //加密狗写入数据失败
	DOG_REPLACERERROR =-16, //注册时候拔出加密狗,更换了另外一个加密狗
	DOG_SERVERSN_ERROR =-17, //平台下发序列号与本机获取序列号不一致
	PC_TIMEERROR =-20,  //本机电脑时间不正确
	PC_DOGDATAERROR =-21, //获取本地磁盘与MAC失败
	PC_DOG_CDSCOMERROR =-22,//非本机加密狗硬盘序列号不匹配
	PC_DOG_MACCOMERROR =-23,//非本机加密狗硬盘序列号不匹配
	PC_REGDATA_ERROR =-24, //接收到的PC注册数据错误无法分割
	PC_REGTOOL_ERROR =-25, //平台注册类型不支持当前 工具
	PC_REGAUTH_NOERROR=-26, //授权码不存在
	PC_REGAUTH_CKERROR =-27, //授权码校验值错误
	PC_REGAUTH_STATEERROR =-28, //授权码状态错误
	PC_TOOL_TYPEERROR =-29, //工具类型不正确,不能大于99

	SERVER_DOG_NOREGISTER =-30, //服务器加密狗不存在
	SERVER_DOG_CKERROR =-31, //加密狗校验值错误
	SERVER_DOG_VENIDERROR =-32, //服务器加密狗VENID不匹配
	SERVER_DOG_DENIED =-33, //服务器禁用加密狗
	SERVER_DOG_DATAERROR =-34, //接收到服务器数据错误
	NET_PARM_ERROR =-40, //网络参数错误IP端口配置错误config配置错误
	NET_WSAS_ERROR =-41, //网络准备连接WSAStartup错误
	NET_CONN_ERROR =-42,  //网络连接错误
	NET_SEND_ERROR =-43,  //网络发送失败
	NET_READ_ERROR =-44,  //网络接收失败
	NET_DATA_INVALID =-45, //接收数据非法

	
	REG_OPEN_ERROR =-51, //打开注册表失败
	REG_DATA_ERROR =-52, //获取注册表信息失败
	REG_WIITE_ERROR =-53, //写入注册表信息失败

	COMMPORT_STATEERROR =-61,  //通讯口未打开
	COMMPORT_READERROR =-62,  //读取数据失败

	RSP_NO_TRAN	= -94,  //无此交易类型
	RSP_NO_PARSE=-95, //接收报文错误
	RSP_SYS_ERR =-96,  //系统错误
	DATABASE_ERROR  =-60,  //服务器数据库异常

	INIT_DENIED = -99, //动态库未初始化
 
};

调用动态库:
MinipaydllFunction.h

在这里插入代码片
// MinipaydllFunction.h: interface for the CMinipaydllFunction class.
//
//

#if !defined(AFX_MINIPAYDLLFUNCTION_H__6617657F_2139_4A1D_B647_604E4F16D86D__INCLUDED_)
#define AFX_MINIPAYDLLFUNCTION_H__6617657F_2139_4A1D_B647_604E4F16D86D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#include<windef.h>

#include <list>
#include <vector>
#include <iostream>
#include <Windows.h>
//初始化
#include "publicfunction.h"
//typedef list<FuWuQiData> LISTINTData;
typedef vector<FuWuQiData> LISTINTVector;
typedef int (__stdcall *InitDll)(int ttype,int &nTimes);
/************************************************************************/
/* 获取加密狗序列号                                                     */
/************************************************************************/
typedef int (__stdcall *GetDogInfo)(unsigned char *idinfo,unsigned char *veninfo);
/************************************************************************/
/* 注册加密狗                                                           */
/************************************************************************/
typedef int (__stdcall *RegIsterDog)(unsigned char *authcodeinfo,int &nTimes);


//打开通讯口
typedef bool (__stdcall *OpenDevice)(DWORD dwVid, DWORD dwPid,int commType);

//写入蓝牙名称
typedef int (__stdcall *WriteSerialNum)(byte CmdHead,byte CmdKey,char *sSerialNumber,char *Masterkey,int nIndex,int &nTimes);
//写入21号文件数据
typedef int (__stdcall *Write21SnMainKey)(char *sSerialNumber,char *Masterkey,char *MasterkeyCk);
//写入时间
typedef int (__stdcall *WriteDateTime)();

//次数递减
typedef int (__stdcall *ReduDogTimes)(int &nTimes);


//检查服务工具版本是否可用
typedef int (__stdcall *TkVersion)(char* appid, char *VerBuf,char* outBuffer);

//保存基本信息
typedef int (__stdcall *SaveBaseVersion)(char *VerBuf,int vsize,char *outBuf,int &outlen);

//保存入库基本信息
typedef int (__stdcall *SaveRkVersion)(char *VerBuf,int vsize,char *outBuf,int &outlen);



//查询基本信息
typedef int (__stdcall *SelectBaseVersion)(char *VerBuf,int vsize,char *outBuf,int &outlen);


//从终端读取设备基本信息
typedef int (__stdcall *ReadSnVersion)(char *outBuf,int &outlen);

//查询终端型号
typedef int (__stdcall *SelectModelInfo)(char *outBuf,int &outlen);

//查询终端颜色
typedef int (__stdcall *SelectProcColour)(char *outBuf,int &outlen);


//查询产品配置
typedef int (__stdcall *SelectProcName)(char *outBuf,int &outlen);


//联网查询发送网络心跳包
typedef int (__stdcall *Heartbeatpack)(char *outBuf,int &outlen);

typedef int (__stdcall *SelectSNAndTUSN)(char *TUSN,int &iErrCode,char *outBuf);

/发送SN号获取秘钥
typedef int (__stdcall *GetKeyToDevice)(char *VerBuf,int vsize,int &iErrCode,char *outBuf);

//发送确认信息
typedef int (__stdcall *InfoReportSever)(char *TUSN,char  *ERcode);下载成功返回0,失败返回0x01

//转加密
typedef int (__stdcall *TransEncry)(unsigned char *keybuf,int keylen,
									unsigned char *keybufck,int keycklen,
									unsigned char *ranbuf,int ranlen,
									unsigned char *okeybuf,int *okeylen,
									unsigned char *okeybufck,int *okeycklen,
									unsigned char *oranbuf,int *oranlen,
								    int *keymode,int *oindex);
typedef int (__stdcall *CheckSaftdog)(unsigned char *outdata,int &nTimes,int itype);
typedef int (__stdcall *UseSaftdog)(unsigned char *outdata,int &nTimes,int itype);
typedef int (__stdcall *GeneratePollCode2)(char *pollCode);
typedef int (__stdcall *RegerSaftdogTimes)(unsigned char *olddata,unsigned char *indata,unsigned char *erroutdata,int itype);
/获取售后维修数据
typedef int (__stdcall *ShouHouWeiXiu)(char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode);//
/获取售后维修数据明细
typedef int (__stdcall *ShouHouWeiXiuDetail)(char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode);
/上送数据到数据库
typedef int (__stdcall *ShouHouInforToSQL)(char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode);
/
typedef int (__stdcall *GetShouHouWeiXiuRecord)(char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode);

class CMinipaydllFunction  
{
public:
	CMinipaydllFunction();
	virtual ~CMinipaydllFunction();
	bool init();

public:	
	InitDll           m_InitDll;
	GetDogInfo		  m_GetDogInfo;
	RegIsterDog		  m_RegIsterDog;
	OpenDevice        m_OpenDevice;
	WriteSerialNum    m_WriteSerialNum;
	Write21SnMainKey  m_Write21SnMainKey;
	WriteDateTime     m_WriteDateTime;
	ReduDogTimes	  m_ReduDogTimes;
	TkVersion         m_TkVersion;
	SaveBaseVersion   m_SaveBaseVersion;
	SaveRkVersion     m_SaveRkVersion;
	SelectBaseVersion m_SelectBaseVersion;
	ReadSnVersion     m_ReadSnVersion;
	SelectModelInfo   m_SelectModelInfo;
	SelectProcColour  m_SelectProcColour;
//	SelectProcName    m_SelectProcName;
	Heartbeatpack     m_Heartbeatpack;
	SelectSNAndTUSN   m_SelectSNAndTUSN;
	GetKeyToDevice    m_GetKeyToDevice;
    InfoReportSever   m_InfoReportSever;
    TransEncry        m_TransEncry;
	ShouHouWeiXiu     m_ShouHouWeiXiu;
	ShouHouWeiXiuDetail m_ShouHouWeiXiuDetail;
	ShouHouInforToSQL m_ShouHouInforToSQL;
	GetShouHouWeiXiuRecord m_GetShouHouWeiXiuRecord;
	//调用加密狗注册
	CheckSaftdog      m_checkSaftdog;
	UseSaftdog m_useSaftdog;
	GeneratePollCode2 m_generatePollCode2;
	RegerSaftdogTimes m_RegerSaftdogTimes;

	
private:
	HMODULE m_hlib;
	HMODULE m_hTranslib;
	HMODULE m_hdoglib;
};

#endif // !defined(AFX_MINIPAYDLLFUNCTION_H__6617657F_2139_4A1D_B647_604E4F16D86D__INCLUDED_)

MinipaydllFunction.cpp

// MinipaydllFunction.cpp: implementation of the CMinipaydllFunction class.
//
//
#include "MinipaydllFunction.h"
#include <QMessageBox>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//
// Construction/Destruction
//
CMinipaydllFunction::CMinipaydllFunction()
{
	m_hlib = NULL;
//	m_hTranslib=NULL;
	init();
}

CMinipaydllFunction::~CMinipaydllFunction()
{
	
}

bool CMinipaydllFunction::init()
{
	 //QMessageBox::information(NULL, "Title", "调用开始", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
	m_hlib = LoadLibrary(L"minipaydll.dll");

	if (m_hlib != NULL)
	{
		//QMessageBox::information(NULL, "Title", "调用成功", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
		m_InitDll =(InitDll)GetProcAddress(m_hlib, "InitDll");
		m_GetDogInfo =(GetDogInfo)GetProcAddress(m_hlib, "GetDogInfo");
		m_RegIsterDog =(RegIsterDog)GetProcAddress(m_hlib, "RegIsterDog");	
		m_OpenDevice = (OpenDevice)GetProcAddress(m_hlib, "OpenDevice");
		m_WriteSerialNum = (WriteSerialNum)GetProcAddress(m_hlib, "WriteSerialNum");
		m_Write21SnMainKey = (Write21SnMainKey)GetProcAddress(m_hlib, "Write21SnMainKey");
		m_WriteDateTime = (WriteDateTime)GetProcAddress(m_hlib, "WriteDateTime");
		m_ReduDogTimes = (ReduDogTimes)GetProcAddress(m_hlib, "ReduDogTimes");	
		m_TkVersion = (TkVersion)GetProcAddress(m_hlib, "TkVersion");	
		m_SaveBaseVersion = (SaveBaseVersion)GetProcAddress(m_hlib, "SaveBaseVersion");
		m_SaveRkVersion = (SaveRkVersion)GetProcAddress(m_hlib, "SaveRkVersion");	
		m_SelectBaseVersion = (SelectBaseVersion)GetProcAddress(m_hlib, "SelectBaseVersion");
		m_ReadSnVersion = (ReadSnVersion)GetProcAddress(m_hlib, "ReadSnVersion");
		m_SelectModelInfo = (SelectModelInfo)GetProcAddress(m_hlib, "SelectModelInfo");
		m_SelectProcColour = (SelectProcColour)GetProcAddress(m_hlib, "SelectProcColour");
//		m_SelectProcName = (SelectProcName)GetProcAddress(m_hlib, "SelectProcName");
		m_Heartbeatpack = (Heartbeatpack)GetProcAddress(m_hlib, "Heartbeatpack");
		m_SelectSNAndTUSN = (SelectSNAndTUSN)GetProcAddress(m_hlib, "SelectSNAndTUSN");
		m_GetKeyToDevice = (GetKeyToDevice)GetProcAddress(m_hlib, "GetKeyToDevice");
		m_InfoReportSever = (InfoReportSever)GetProcAddress(m_hlib, "InfoReportSever");	
		m_ShouHouWeiXiu = (ShouHouWeiXiu)GetProcAddress(m_hlib, "ShouHouWeiXiu");
		m_ShouHouWeiXiuDetail = (ShouHouWeiXiuDetail)GetProcAddress(m_hlib, "ShouHouWeiXiuDetail");
		m_ShouHouInforToSQL =   (ShouHouInforToSQL)GetProcAddress(m_hlib, "ShouHouInforToSQL");
		m_GetShouHouWeiXiuRecord = (GetShouHouWeiXiuRecord)GetProcAddress(m_hlib,"GetShouHouWeiXiuRecord");	
		 //FreeLibrary(m_hlib);
	}
	else
	{
		return false;
	}

	m_hTranslib = LoadLibrary(L"secFunction.dll");
	if (m_hTranslib != NULL)
	{	
		m_TransEncry = (TransEncry)GetProcAddress(m_hTranslib, "TransEncry");
		
	}

	m_hdoglib= LoadLibrary(L"dog_minipaydll.dll");
	if (m_hdoglib != NULL)
	{
		m_checkSaftdog      = (CheckSaftdog)GetProcAddress(m_hdoglib, "CheckSaftdog");
		m_useSaftdog        = (UseSaftdog)GetProcAddress(m_hdoglib, "UseSaftdog");
		m_generatePollCode2 = (GeneratePollCode2)GetProcAddress(m_hdoglib, "GeneratePollCode2"); 
		m_RegerSaftdogTimes = (RegerSaftdogTimes)GetProcAddress(m_hdoglib, "RegerSaftdogTimes");
	}
	else
	{
		return false;
	}
	
	return true;
}

主类函数.h

#ifndef SHOUHOUTOOL_H
#define SHOUHOUTOOL_H

#include "json/cJSON.h"
#include "json/minipay_code.h"
#include "MinipaydllFunction.h"
#include <QtGui/QDialog>
#include "ui_shouhoutool.h"
#include <QMessageBox>
#include <QMenu>
#include <QSettings>
#include <QtCore/QtCore>
#include <QDebug>
#include <QStandardItemModel>
#include <QListWidgetItem>
#include <QListWidget>

#include "inputsn.h"

class ShouHouTool : public QDialog
{
	Q_OBJECT

public:
	ShouHouTool(QWidget *parent = 0, Qt::WFlags flags = 0);
	~ShouHouTool();
	void InitPara();
	CMinipaydllFunction *g_minipaydllFunction;
	QString m_qstrfatherJieDian;
	LISTINTVector  list1;
	LISTINTVector m_vecmain;
	LISTINTVector m_vecmini;
	QString  m_qstrMain;
	QString  m_qstrmini;
	int m_recordtableLine;
	void objconnect();
	void addconfigini();
	bool bjudcomb;
	int ShouHouWeiXiuDeal( char *VerBuf,int vsize,char *outBuf,int &outlen,LISTINTVector &listvector);
	int ShouHouWeiXiuDetailDeal( char *VerBuf,int vsize,int errcode);
	int GetShouHouWeiXiuRecord( char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode);
	static DWORD WINAPI ReadVersion(LPVOID pParam);//发送线程


private slots:
	void on_exit();
	void slotLoadList(int);
	void SendToSQL();
	void getPadIds();
	/*按钮添加*/
	void onbutaddtoDetailInformation();//
	void startThread();
private:
	Ui::ShouHouToolClass ui;
	void mousePressEvent (QMouseEvent * event );
};

#endif // SHOUHOUTOOL_H

主函数.cpp

#include "shouhoutool.h"

ShouHouTool::ShouHouTool(QWidget *parent, Qt::WFlags flags)
	: QDialog(parent, flags)
{
	 ui.setupUi(this);
	 g_minipaydllFunction=new CMinipaydllFunction();
	 objconnect();
	 //addconfigini();		
}

ShouHouTool::~ShouHouTool()
{
	delete[] g_minipaydllFunction;
}

void ShouHouTool::addconfigini()
{
	QString ininame="";
	char tempbuf[1024]={0};
    char* tempname=NULL;
    QString iniFilePath = "/../config.ini"; 
	iniFilePath = QCoreApplication::applicationDirPath() + "/Config.ini";
    QSettings settings(iniFilePath,QSettings::IniFormat);    
    QString G1_fileName = settings.value("Setting/FactoryName").toString();    
   // ui.lineEdit_factory->setText(G1_fileName);
}

void ShouHouTool::objconnect()
{
	//connect(ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(on_lineEdit_sendNew()));//没有QString,一调用就会死
	connect(ui.pushButton_getInfo,SIGNAL(clicked()), this, SLOT(startThread()));//添加
	//connect(ui.tableWidget,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(deleteCurrentLine(QPoint)));
	return;
}
void ShouHouTool::InitPara()
{
	//ui.lineEdit->setStyleSheet(	normalStyle);
}

void ShouHouTool::on_exit()
{
	  QApplication* app;
      app->exit(0);
}

void ShouHouTool::slotLoadList(int i)
{

	char ch[1024]={0};
	char  outBuf[1024]={0x00};
	int   outlen=0;
	int   iErrCode=0;
	cJSON *rootdata;
	rootdata=cJSON_CreateObject();
	cJSON_AddStringToObject(rootdata,"info","");
	char *jsonBuf=cJSON_PrintUnformatted(rootdata);
	int result = g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);
	if(iErrCode!=0)
	{
	   QString qstrmessage=outBuf;
	   QMessageBox::warning(this,tr("Warning"),qstrmessage);
	   return ;
	}
	return;
}

void ShouHouTool::SendToSQL()
{
	cJSON *rootdata;
	rootdata=cJSON_CreateObject();
	/*
    cJSON_AddStringToObject(rootdata,"FAC_ID","");
    cJSON_AddStringToObject(rootdata,"MIDDLE_CODE","");
    cJSON_AddStringToObject(rootdata,"SERIAL_NO","");
    cJSON_AddStringToObject(rootdata,"FAULT_CLASS","");
	cJSON_AddStringToObject(rootdata,"FAULT_CAUSE","");
	cJSON_AddStringToObject(rootdata,"RETEST_FAILURE","");
	cJSON_AddStringToObject(rootdata,"FAULT_NUM","");
	cJSON_AddStringToObject(rootdata,"FAULT_LOCATION","");
	cJSON_AddStringToObject(rootdata,"REWORK_REP_TIMES","");
	cJSON_AddStringToObject(rootdata,"ABILITY","");
	cJSON_AddStringToObject(rootdata,"PROCESSING_METHOD","");
	cJSON_AddStringToObject(rootdata,"TESTER_CODE","");
	cJSON_AddStringToObject(rootdata,"MAINTENANCE_PER_CODE","");
	cJSON_AddStringToObject(rootdata,"STATE","");
	cJSON_AddStringToObject(rootdata,"INPUT_TIME","");
	cJSON_AddStringToObject(rootdata,"COMPLEITION_TIME","");
	cJSON_AddStringToObject(rootdata,"MAINT_DETAILS","");
	*/
	//
	QString qstrmain="";
	QString qstrmini="";
	QString str ="";
	QString strmini ="";

	QMessageBox::warning(this,tr("Warning"),qstrmain);
	char main[50]={0};
    QByteArray ba = qstrmain.toLocal8Bit();
    memcpy(main,ba.data(),ba.size()+1);
	cJSON_AddStringToObject(rootdata,"FAULT_CLASS",main);

	char mini[50]={0};
    ba = qstrmini.toLocal8Bit();
    memcpy(mini,ba.data(),ba.size()+1);
	cJSON_AddStringToObject(rootdata,"FAULT_CAUSE",mini);
	int aa=0;
	FuWuQiData fad;
	char senddata[1024]={0};
	//memcpy(senddata,);
	char *jsonBuf=cJSON_PrintUnformatted(rootdata);
	char  outBuf[1024]={0x00};
	int   outlen=0;
	int   iErrCode=-1;
	QMessageBox::warning(this,tr("Warning"),tr("开始发数据"));
	int result = g_minipaydllFunction->m_ShouHouInforToSQL(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);
	if(iErrCode==0){
		QMessageBox::warning(this,tr("Warning"),tr("数据发完"));
	}
	return;
}

void ShouHouTool::mousePressEvent ( QMouseEvent * event )
{

	//QMessageBox::warning(this,tr("Warning"),tr("鼠标操作"));
}
void ShouHouTool::getPadIds()
{
	QMessageBox::warning(this,tr("Warning"),tr("父类调用成功"));
}

void ShouHouTool::onbutaddtoDetailInformation()
{
    char outValue[2048]={0x00};
	byte outTemp[512]={0x00};
	int iErrCode=-1;
	int outlen=0;
	cJSON *MBSInformation;
	cJSON *arrayItem;
	MBSInformation=cJSON_CreateObject();
	cJSON_AddStringToObject(MBSInformation,"SERIAL_NO","0000290220068442");
	cJSON_AddStringToObject(MBSInformation,"Position_number","");
	cJSON_AddStringToObject(MBSInformation,"MIDDLE_CODE","");
	cJSON_AddStringToObject(MBSInformation,"TOOLS_INFO"  ,"");
	cJSON_AddStringToObject(MBSInformation,"TOOLS_ALIAS" ,"");
	char *jsonBuf=cJSON_PrintUnformatted(MBSInformation);
	int result=g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outValue,outlen,iErrCode);
	if(result==STATUS_OK)
	{
	    ShouHouWeiXiuDetailDeal( outValue,outlen,iErrCode);
	}else{
	  
	  ui.textEditInfor->setText("获取服务器数据失败");
	}
	cJSON_Delete(MBSInformation);
	return ;
}



int  ShouHouTool::ShouHouWeiXiuDeal( char *VerBuf,int vsize,char *outBuf,int &outlen,LISTINTVector &listvector)
{
	char outValue[2048]={0x00};
	char outTemp[512]={0x00};
   	QString strTemp="";	
	listvector.clear();
	int  olen=0;
	int  nlen=0;	
	char*MySQLConnet=("服务器连接异常");  
	cJSON *MBSInformation;
	cJSON *object;
	MBSInformation=cJSON_CreateObject();	      
	if (outValue[0] ==0x00)
	{		
		outlen=0x00;
		nlen = ((VerBuf[1] << 8) & 0xFF00);
		nlen |= VerBuf[2] & 0xFF; 
		memcpy(outTemp,VerBuf+3,nlen);
		MBSInformation=cJSON_Parse((char *)outTemp); 				
		cJSON *arrayItem = cJSON_GetObjectItem(MBSInformation,"FAULT_CODE");
		char data[1024]={0};
		if (arrayItem >0)
		{
			strTemp =arrayItem->valuestring;	
			int inum=cJSON_GetArraySize(arrayItem);
			cJSON*item;
			for(int i=0;i<inum;i++) 
			{
				FuWuQiData fw;
				memset(fw.datafwq,0x00,sizeof(fw.datafwq));
				object=cJSON_GetArrayItem(arrayItem,i);
				item=cJSON_GetObjectItem(object,"id");
				memcpy((char*)(LPCTSTR)fw.id,item->valuestring,strlen(item->valuestring));
				item=cJSON_GetObjectItem(object,"text");
				memcpy((char*)(LPCTSTR)fw.datafwq,item->valuestring,strlen(item->valuestring));				    	 
				listvector.push_back(fw);
			}
		}
		
	}	
	cJSON_Delete(MBSInformation);
	return 0;
}


void ShouHouTool::startThread()
{
	DWORD m_dwOpThreadID;			//线程ID
	HANDLE m_hOpThread;			//发送线程句柄
	m_hOpThread = CreateThread(NULL,0,ReadVersion,this,0,&m_dwOpThreadID);

}

DWORD WINAPI ShouHouTool::ReadVersion(LPVOID pParam)
{

	ShouHouTool* dlg = (ShouHouTool*)pParam;
	dlg->onbutaddtoDetailInformation();
	return 0;
}

int  ShouHouTool::ShouHouWeiXiuDetailDeal( char *VerBuf,int vsize,int iEEcode)
{
	char outValue[2048]={0x00};
	char outTemp[1024]={0x00};
   	QString strTemp="";	
	int  olen=0;
	int  nlen=0;	
	QString strid="",strFAC_ID="",strMIDDLE_CODE="";
	QString strSERIAL_NO="",strFAULT_CLASS="", strFAULT_CAUSE="",strRETEST_FAILURE="";
	QString strFAULT_NUM="",strFAULT_LOCATION="", strREWORK_REP_TIMES="",strABILITY="";      
    QString strPROCESSING_METHOD="",strTESTER_CODE="",strMAINTENANCE_PER_CODE="",strSTATE="",strINPUT_TIME="",strCOMPLEITION_TIME="";
    QString strMAINT_DETAILS="",  strCREATE_USER_NAME="",strCREATE_DATE_TIME="",strUPDATE_USER_NAME="",strUPDATE_DATE_TIME="";
	cJSON *MBSInformation,*arrayItem;
	MBSInformation=cJSON_CreateObject();	      
	if (VerBuf[0] ==0x00 && olen > 0)
	{							
		nlen = ((VerBuf[1] << 8) & 0xFF00);
		nlen |= VerBuf[2] & 0xFF; 
		memcpy(outTemp,VerBuf+3,nlen);
		if (nlen >0)
		{
			MBSInformation=cJSON_Parse((char *)outTemp); 	
			 arrayItem = cJSON_GetObjectItem(MBSInformation,"ID");
			if (arrayItem >0)
			{
				strid =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAC_ID");
			if (arrayItem >0)
			{
				strFAC_ID =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"MIDDLE_CODE");
			if (arrayItem >0)
			{
				strMIDDLE_CODE =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"SERIAL_NO");
			if (arrayItem >0)
			{
				strSERIAL_NO =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CLASS");
			if (arrayItem >0)
			{
				strFAULT_CLASS =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CAUSE");
			if (arrayItem >0)
			{
				strFAULT_CAUSE =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"RETEST_FAILURE");
			if (arrayItem >0)
			{
				strRETEST_FAILURE =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_NUM");
			if (arrayItem >0)
			{
				strFAULT_NUM =arrayItem->valuestring;
			}

			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_LOCATION");
			if (arrayItem >0)
			{
				strFAULT_LOCATION =arrayItem->valuestring;
			}

			arrayItem =cJSON_GetObjectItem (MBSInformation,"REWORK_REP_TIMES");
			if (arrayItem >0)
			{
				strREWORK_REP_TIMES =arrayItem->valuestring;
			}
			arrayItem =cJSON_GetObjectItem (MBSInformation,"ABILITY");
			if (arrayItem >0)
			{
				strABILITY =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"PROCESSING_METHOD");
			if (arrayItem >0)
			{
				strPROCESSING_METHOD =arrayItem->valuestring;
			}
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"TESTER_CODE");
			if (arrayItem >0)
			{
				strTESTER_CODE =arrayItem->valuestring;
			}
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINTENANCE_PER_CODE");
			if (arrayItem >0)
			{
				strMAINTENANCE_PER_CODE =arrayItem->valuestring;
			}
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"STATE");
			if (arrayItem >0)
			{
				strSTATE =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"INPUT_TIME");
			if (arrayItem >0)
			{
				strINPUT_TIME =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"COMPLEITION_TIME");
			if (arrayItem >0)
			{
				strCOMPLEITION_TIME =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINT_DETAILS");
			if (arrayItem >0)
			{
				strMAINT_DETAILS =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_USER_NAME");
			if (arrayItem >0)
			{
				strCREATE_USER_NAME =arrayItem->valuestring;
			}
						
			arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_DATE_TIME");
			if (arrayItem >0)
			{
				strCREATE_DATE_TIME =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_USER_NAME");
			if (arrayItem >0)
			{
				strUPDATE_USER_NAME =arrayItem->valuestring;
			}
											
			arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_DATE_TIME");
			if (arrayItem >0)
			{
				strUPDATE_DATE_TIME =arrayItem->valuestring;
			}
            //		
			strTemp =strMIDDLE_CODE+"|"+strSERIAL_NO+"|"+strFAULT_CLASS+"|"+strFAULT_CAUSE+"|"+strRETEST_FAILURE+"|"+strFAULT_NUM+"|"+
					strFAULT_LOCATION+"|"+strREWORK_REP_TIMES+"|"+strABILITY+"|"+strPROCESSING_METHOD+"|"+
					strTESTER_CODE+"|"+strMAINTENANCE_PER_CODE+"|"+strINPUT_TIME+"|"+strCOMPLEITION_TIME+"|"+strMAINT_DETAILS+"|"+
					strCREATE_USER_NAME+"|"+strCREATE_DATE_TIME+"|"+
					strUPDATE_USER_NAME+"|"+strUPDATE_DATE_TIME;
			ui.textEditInfor->setText(strTemp);
	
		}
		else
		{
			///
			ui.textEditInfor->setText("无法解析到数据");

		}	
	}
	else 
	{		
			nlen = ((VerBuf[1] << 8) & 0xFF00);
			nlen |= VerBuf[2] & 0xFF; 
			memcpy(outTemp,VerBuf+3,nlen);
			MBSInformation=cJSON_Parse((char *)outTemp); 			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"msg");
			if (arrayItem >0)
			{
				strTemp =arrayItem->valuestring;
			}
			ui.textEditInfor->setText(strTemp);
	}	
	cJSON_Delete(MBSInformation);
	return 0;
}

 int  ShouHouTool::GetShouHouWeiXiuRecord( char *VerBuf,int vsize,char *outBuf,int &outlen,int &iErrCode)
{
	char outValue[2048]={0x00};
	byte outTemp[512]={0x00};
   	QString strTemp="";	
	QString strid="",strFAC_ID="",strMIDDLE_CODE="";

	QString strSERIAL_NO="",strFAULT_CLASS="", strFAULT_CAUSE="",strRETEST_FAILURE="";
	QString strFAULT_NUM="",strFAULT_LOCATION="", strREWORK_REP_TIMES="",strABILITY="";      
    QString strPROCESSING_METHOD="",strTESTER_CODE="",strMAINTENANCE_PER_CODE="",strSTATE="",strINPUT_TIME="",strCOMPLEITION_TIME="";
    QString strMAINT_DETAILS="",  strCREATE_USER_NAME="",strCREATE_DATE_TIME="",strUPDATE_USER_NAME="",strUPDATE_DATE_TIME="";
 
	cJSON *MBSInformation;
	cJSON *arrayItem;
	MBSInformation=cJSON_CreateObject();
	cJSON_AddStringToObject(MBSInformation,"TUSN","");
	cJSON_AddStringToObject(MBSInformation,"Position_number","");
	cJSON_AddStringToObject(MBSInformation,"order_number","");
	cJSON_AddStringToObject(MBSInformation,"TOOLS_INFO"  ,"");
	cJSON_AddStringToObject(MBSInformation,"TOOLS_ALIAS" ,"");
	char *jsonBuf=cJSON_PrintUnformatted(MBSInformation);
	g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);
	int  olen=0;
	int  nlen=0;	
	char*MySQLConnet=("服务器连接异常");  
	g_minipaydllFunction->m_GetShouHouWeiXiuRecord(jsonBuf,strlen(jsonBuf),outBuf,outlen,iErrCode);
	iErrCode=VerBuf[0]&0xff;
	if (VerBuf[0] ==0x00 && olen > 0)
	{							
		nlen = ((VerBuf[1] << 8) & 0xFF00);
		nlen |= VerBuf[2] & 0xFF; 
		memcpy(outTemp,VerBuf+3,nlen);
		if (nlen >0)
		{
			MBSInformation=cJSON_Parse((char *)outTemp); 	
			cJSON* arrayItem = cJSON_GetObjectItem(MBSInformation,"ID");
			if (arrayItem >0)
			{
				strid =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAC_ID");
			if (arrayItem >0)
			{
				strFAC_ID =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"MIDDLE_CODE");
			if (arrayItem >0)
			{
				strMIDDLE_CODE =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"SERIAL_NO");
			if (arrayItem >0)
			{
				strSERIAL_NO =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CLASS");
			if (arrayItem >0)
			{
				strFAULT_CLASS =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_CAUSE");
			if (arrayItem >0)
			{
				strFAULT_CAUSE =arrayItem->valuestring;
			}
			///
			arrayItem =cJSON_GetObjectItem (MBSInformation,"RETEST_FAILURE");
			if (arrayItem >0)
			{
				strRETEST_FAILURE =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_NUM");
			if (arrayItem >0)
			{
				strFAULT_NUM =arrayItem->valuestring;
			}

			arrayItem =cJSON_GetObjectItem (MBSInformation,"FAULT_LOCATION");
			if (arrayItem >0)
			{
				strFAULT_LOCATION =arrayItem->valuestring;
			}

			arrayItem =cJSON_GetObjectItem (MBSInformation,"REWORK_REP_TIMES");
			if (arrayItem >0)
			{
				strREWORK_REP_TIMES =arrayItem->valuestring;
			}
			arrayItem =cJSON_GetObjectItem (MBSInformation,"ABILITY");
			if (arrayItem >0)
			{
				strABILITY =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"PROCESSING_METHOD");
			if (arrayItem >0)
			{
				strPROCESSING_METHOD =arrayItem->valuestring;
			}
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"TESTER_CODE");
			if (arrayItem >0)
			{
				strTESTER_CODE =arrayItem->valuestring;
			}
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINTENANCE_PER_CODE");
			if (arrayItem >0)
			{
				strMAINTENANCE_PER_CODE =arrayItem->valuestring;
			}
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"STATE");
			if (arrayItem >0)
			{
				strSTATE =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"INPUT_TIME");
			if (arrayItem >0)
			{
				strINPUT_TIME =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"COMPLEITION_TIME");
			if (arrayItem >0)
			{
				strCOMPLEITION_TIME =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"MAINT_DETAILS");
			if (arrayItem >0)
			{
				strMAINT_DETAILS =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_USER_NAME");
			if (arrayItem >0)
			{
				strCREATE_USER_NAME =arrayItem->valuestring;
			}
						
			arrayItem =cJSON_GetObjectItem (MBSInformation,"CREATE_DATE_TIME");
			if (arrayItem >0)
			{
				strCREATE_DATE_TIME =arrayItem->valuestring;
			}
							
			arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_USER_NAME");
			if (arrayItem >0)
			{
				strUPDATE_USER_NAME =arrayItem->valuestring;
			}
											
			arrayItem =cJSON_GetObjectItem (MBSInformation,"UPDATE_DATE_TIME");
			if (arrayItem >0)
			{
				strUPDATE_DATE_TIME =arrayItem->valuestring;
			}
            //		
			strTemp =strMIDDLE_CODE+"|"+strSERIAL_NO+"|"+strFAULT_CLASS+"|"+strFAULT_CAUSE+"|"+strRETEST_FAILURE+"|"+strFAULT_NUM+"|"+
					strFAULT_LOCATION+"|"+strREWORK_REP_TIMES+"|"+strABILITY+"|"+strPROCESSING_METHOD+"|"+
					strTESTER_CODE+"|"+strMAINTENANCE_PER_CODE+"|"+strINPUT_TIME+"|"+strCOMPLEITION_TIME+"|"+strMAINT_DETAILS+"|"+
					strCREATE_USER_NAME+"|"+strCREATE_DATE_TIME+"|"+
					strUPDATE_USER_NAME+"|"+strUPDATE_DATE_TIME;
			ui.textEditInfor->setText(strTemp);
	
		}
		else
		{
			///
			nlen = ((outValue[1] << 8) & 0xFF00);
			nlen |= outValue[2] & 0xFF; 
			memcpy(outTemp,outValue+3,nlen);
			MBSInformation=cJSON_Parse((char *)outTemp); 	
			
			arrayItem =cJSON_GetObjectItem (MBSInformation,"msg");
			if (arrayItem >0)
			{
				strTemp =arrayItem->valuestring;
			}
			ui.textEditInfor->setText(strTemp);
		}	
	}
	else 
	{	
		iErrCode =-1;
		memcpy((char*)outBuf,MySQLConnet,strlen(MySQLConnet));
	}	
	cJSON_Delete(MBSInformation);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

物联网小镇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值