|
- #include "stdafx.h"
- #include "JsonBusiness.h"
-
- using namespace std;
- using namespace Json;
-
-
-
- //
- ////建立对象函数
- //extern "C" __declspec(dllexport) void * __cdecl CreateJsonBusiness(const GUID & Guid, DWORD dwInterfaceVer)
- //{
- // //建立对象
- // CJsonBusiness * pJsonBusiness = NULL;
- // try
- // {
- // pJsonBusiness = new CJsonBusiness();
- // if (pJsonBusiness == NULL) throw TEXT("创建失败");
- // void * pObject = pJsonBusiness->QueryInterface(Guid, dwInterfaceVer);
- // if (pObject == NULL) throw TEXT("接口查询失败");
- // return pObject;
- // }
- // catch (...) {}
- //
- // //清理对象
- // SafeDelete(pJsonBusiness);
- // return NULL;
- //}
-
- CJsonBusiness::CJsonBusiness()
- {
- m_str = "";
- m_wMainCmd = 0;
- m_wSubCmd = 0;
- m_reader = m_ft;
- }
-
-
- CJsonBusiness::~CJsonBusiness()
- {
- m_root.clear();
- }
-
- void
- CJsonBusiness::Clear()
- {
- m_root.clear();
- m_wMainCmd = 0;
- m_wSubCmd = 0;
- }
-
- std::string
- CJsonBusiness::GetNullJson(VOID* pData)
- {
- m_root.clear();
- if (IsVaildPara(pData)){
- m_str = m_root.string_To_UTF8("", 4);
- }
- return m_str;
- }
-
- std::string
- CJsonBusiness::JsonWriteUTF_8(Value & root)
- {
- std::string str = "";
- str = m_fw.write(root);
-
- m_str = "";
- m_str=root.string_To_UTF8(str.c_str(), str.size());
-
- root.clear();
- return m_str;
- }
- void
- CJsonBusiness::Log(std::string str)
- {
- #ifdef _DEBUG
- WORD rsize = 0;
- TCHAR tString[1024] = L"";
- CString cstr;
-
- rsize = m_root.MByteToWChar(str.c_str(), tString, 1024);
- cstr.Format(L"主命令-子命令:%d-%d %s", m_wMainCmd, m_wSubCmd, tString);
- //提示消息
- CTraceService::TraceString(cstr, TraceLevel_Normal);
- #endif
- }
-
- void
- CJsonBusiness::Log(std::string str, const TCHAR* nStr)
- {
- #ifdef _DEBUG
- TCHAR tString[100000] = L"";
- CString cstr=L"";
- m_root.MByteToWChar(str.c_str(), tString, str.size()+1);
- cstr.Format(L"消息注释:%s,主命令-子命令:%d-%d %s", nStr, m_wMainCmd, m_wSubCmd, tString);
- //提示消息
- CTraceService::TraceString(cstr, TraceLevel_Normal);
- #endif
- }
-
- // 检验是否包含特殊字符
- bool
- CJsonBusiness::checkNumber(string str)
- {
- int badNum = 0;
-
- int size = str.length();
- if (size <= 0)
- return false;
-
- char* pStr = new char[size+1];
-
- strcpy(pStr, str.c_str());
- for (int i = 0; i < size; i++)
- {
- if (!(pStr[i] >= 48 && pStr[i] <= 57))//数字符号
- continue;
- if (ispunct(pStr[i]))
- {
- badNum++;
- }
- }
- delete[] pStr;
- pStr = NULL;
- bool res = true;
- if (badNum > 0)
- {
- res = false;
- }
- return res;
- }
-
- //闲聊分享战绩
- std::string CJsonBusiness::GetInfoJson(const DWORD GameID,const TCHAR WanFInfo[68],const std::string strTime,const std::string strMd5, DBR_GR_ClubRecordXianLiao FenXiangRecord)
- {
- if (IsVaildPara(&FenXiangRecord))
- {
- m_str = m_root.string_To_UTF8("1000", JSON_BUSINESS_ERROR_SIZE);
- return "";
- }
- if (FenXiangRecord.dwClubID == 0 || FenXiangRecord.dwTableID == 0)return "";
- TCHAR WanFTitle[68];
- CopyMemory(WanFTitle, WanFInfo, sizeof(WanFTitle));
- string str = "";
- m_root.clear();
- m_root.WCharToMByte(WanFTitle, str, CountArray(WanFTitle));//玩法内容
- m_root["Title"] = Value(str);
- m_root["ClubID"] = Value((INT)FenXiangRecord.dwClubID);
- m_root["GameID"] = Value((INT)GameID);
- m_root["Time"] = Value(strTime);
- m_root["Sign"] = Value(strMd5);
- Value rootPlayers;
- for (BYTE i = 0; i < FenXiangRecord.dwUserCount; i++)
- {
- str = "";
- rootPlayers.WCharToMByte(FenXiangRecord.Player[i].szImgHead, str, CountArray(FenXiangRecord.Player[i].szImgHead));
- rootPlayers["HeadImg"] = Value(str);
- str = "";
- rootPlayers.WCharToMByte(FenXiangRecord.Player[i].szName, str, CountArray(FenXiangRecord.Player[i].szName));
- rootPlayers["NickName"] = Value(str);
- rootPlayers["UserID"] = Value(FenXiangRecord.Player[i].userID);
- rootPlayers["GetScore"] = Value(FenXiangRecord.Player[i].gScore);
- m_root["Players"].append(Value(rootPlayers));
- }
- str = "";
- str = m_fw.write(m_root);
-
- m_str = m_root.string_To_UTF8(str.c_str(), str.size());
- m_root.clear();
- return m_str;
- }
-
- std::string
- CJsonBusiness::GetInfoJson(TCHAR* ptr, DWORD size) {
- if (IsVaildPara(ptr))
- {
- m_str = m_root.string_To_UTF8("1000", JSON_BUSINESS_ERROR_SIZE);
- return "";
- }
- TCHAR* pData = (TCHAR*)malloc(size * sizeof(TCHAR));
- ZeroMemory(pData, size * sizeof(TCHAR));
- CopyMemory(pData, ptr, size * sizeof(TCHAR));
- std::string str = "";
- m_root.WCharToMByte(pData, str, size * sizeof(TCHAR));
- if (MDM_GR_USER == m_wMainCmd)
- {
- switch (m_wSubCmd)
- {
- case SUB_GR_USER_GET_DINGDANLISTACK:
- m_root["reqzhifu"] = Value(str);
- break;
- case SUB_GR_USER_GET_BANGDINGACK:
- {
- CMD_GR_BangDingACK* ptr = (CMD_GR_BangDingACK*)pData;
- m_root["bRet"] = Value((BYTE)ptr->bRet);
- m_root["bLen"] = Value((BYTE)ptr->bLen);
- std::string strt = "";
- m_root.WCharToMByte(ptr->szText, strt, CountArray(ptr->szText) * sizeof(TCHAR));
- m_root["szText"] = Value(strt);
- break;
- }
- default:
- m_str = "";
- free((void*)pData);
- return m_str;
- }
-
- }
- m_str = JsonWriteUTF_8(m_root);
- free((void*)pData);
- pData = NULL;
- return m_str;
- }
|