20210827补充源码上传(蓝凑云)
下载:https://pricexiao.lanzoui.com/in6hIt82jsb 密码:2wrt
C++BASE64源码
lib.h文件(弃用,更新的代码放在后面了)
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
bool is_readable(const std::string & file)
{
wchar_t szBuffer[1024*10];
OemToCharW(file.c_str(), szBuffer);
std::ifstream fichier(szBuffer);
return !fichier.fail();
}
// Base 64
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static const int bufferSize = 1024 * 10;
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len)
{
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (i = 0; (i < 4); i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i)
{
for (j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while ((i++ < 3))
ret += '=';
}
return ret;
}
std::string hex_string(std::string hexstr)
{
std::string str = "";
str.resize((hexstr.size() + 1) / 2);
for (size_t i = 0, j = 0; i < str.size(); i++, j++)
{
char at = '@';
str[i] = (hexstr[j] & at ? hexstr[j] + 9 : hexstr[j]) << 4, j++;
str[i] |= (hexstr[j] & at ? hexstr[j] + 9 : hexstr[j]) & 0xF;
}
return str;
}
std::string string_hex(std::string str, const bool capital = false)
{
std::string hexstr = "";
hexstr.resize(str.size() * 2);
static const char a = capital ? 0x40 : 0x60;
for (size_t i = 0; i < str.size(); i++)
{
char c = (str[i] >> 4) & 0xF;
hexstr[i * 2] = c > 9 ? (c - 9) | a : c | '0';
hexstr[i * 2 + 1] = (str[i] & 0xF) > 9 ? (str[i] - 9) & 0xF | a : str[i] & 0xF | '0';
}
return hexstr;
}
std::string char_to_string(char x[], int size_recv)
{
int num_car = 0;
int stop_while = size_recv;
std::string output = "";
while (stop_while > 0)
{
output += x[num_car];
if (num_car < size_recv) { num_car++; }
stop_while--;
}
return output;
}
std::string str_base64_encode(std::string str)
{
return base64_encode(reinterpret_cast<const unsigned char*>(str.c_str()), str.length());
}
std::string base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i == 4) {
for (i = 0; i < 4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++)
ret += char_array_3[i];
i = 0;
}
}
if (i) {
for (j = 0; j < i; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
}
return ret;
}
// Decode file
int decode_file_base64(std::string path_in, std::string path_out)
{
std::string path_file = path_in;
if (is_readable(path_file))
{
FILE *file_input;
FILE *file_output;
fopen_s(&file_input, path_file.c_str(), "ab+");
fopen_s(&file_output, path_out.c_str(), "ab+");
char buff_read[bufferSize];
if (file_input != NULL)
{
std::string str_encode_buff = "";
bool lb_read = true;
while (lb_read)
{
lb_read = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, sizeof(buff_read));
memset(buff_read, 0, sizeof(buff_read));
}
str_encode_buff = base64_decode(str_encode_buff);
fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
fclose(file_input);
fclose(file_output);
}
else{
return -1;
}
}
else{
return -2;
}
return 0;
}
int decode_string_base64_file(std::string path_in, std::string path_out)
{
std::string path_file = path_in;
//if (is_readable(path_file))
//{
//FILE *file_input;
FILE *file_output;
//fopen_s(&file_input, path_file.c_str(), "ab+");
fopen_s(&file_output, path_out.c_str(), "ab+");
//char buff_read[1];
if (!path_file.empty())
{
//std::string str_encode_buff = "";
//while (fread(buff_read, sizeof(buff_read), 1, file_input))
//{
//str_encode_buff += char_to_string(buff_read, sizeof(buff_read));
//memset(buff_read, 0, sizeof(buff_read));
//}
path_file = base64_decode(path_file);
fwrite(path_file.c_str(), strlen(string_hex(path_file).c_str()) / 2, 1, file_output);
//fclose(file_input);
fclose(file_output);
}
else{
return -1;
}
//}
return 0;
}
int encode_file_base64(std::string path_in, std::string path_out)
{
std::string path_file = path_in;
if (is_readable(path_file))
{
FILE *file_input;
FILE *file_output;
fopen_s(&file_input, path_file.c_str(), "ab+");
fopen_s(&file_output, path_out.c_str(), "ab+");
char buff_read[bufferSize];
if (file_input != NULL)
{
std::string str_encode_buff = "";
bool lb_read = true;
while (lb_read)
{
lb_read = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, sizeof(buff_read));
memset(buff_read, 0, sizeof(buff_read));
}
str_encode_buff = str_base64_encode(str_encode_buff);
fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
fclose(file_input);
fclose(file_output);
}
else{
return -1;
}
}
else{
return -2;
}
return 0;
}
int encode_file_base64_string(std::string path_in, OUT char* content)
{
std::string path_file = path_in;
if (is_readable(path_file))
{
FILE *file_input;
//FILE *file_output;
fopen_s(&file_input, path_file.c_str(), "ab+");
//fopen_s(&file_output, path_out.c_str(), "ab+");
char buff_read[bufferSize];
if (file_input != NULL)
{
std::string str_encode_buff = "";
bool lb_read = true;
while (lb_read)
{
lb_read = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, sizeof(buff_read));
memset(buff_read, 0, sizeof(buff_read));
}
str_encode_buff = str_base64_encode(str_encode_buff);
//fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
fclose(file_input);
//fclose(file_output);
strcpy_s(content, strlen(str_encode_buff.c_str()) + 1, str_encode_buff.c_str());
//strcpy(content, str_encode_buff.c_str);
//content = str_encode_buff;
}
else{
return -1;
}
}
else{
return -2;
}
return 0;
}
std::string encode_file_base64_string(std::string path_in)
{
std::string path_file = path_in;
std::string str_encode_buff = "";
if (is_readable(path_file))
{
FILE *file_input;
//FILE *file_output;
fopen_s(&file_input, path_file.c_str(), "ab+");
//fopen_s(&file_output, path_out.c_str(), "ab+");
char buff_read[bufferSize];
if (file_input != NULL)
{
bool lb_read = true;
while (lb_read)
{
lb_read = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, sizeof(buff_read));
memset(buff_read, 0, sizeof(buff_read));
}
str_encode_buff = str_base64_encode(str_encode_buff);
//fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
fclose(file_input);
//fclose(file_output);
str_encode_buff;
}
else{
str_encode_buff = "-1";
}
}
else{
str_encode_buff = "-2";
}
return str_encode_buff;
}
pbBase64Func.cpp文件
// pbBase64Func.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
#include "pbBase64Func.h"
int _stdcall filetoBase64(char* filePath, char* outPut){
return encode_file_base64(filePath, outPut);
}
int _stdcall base64ToFile(char* filePath, char* outPut){
return decode_file_base64(filePath, outPut);
}
int _stdcall filetoBase64ToString(char* filePath, OUT char* content){
return encode_file_base64_string(filePath, OUT content);
}
int _stdcall base64ContentToFile(char* content, char* outPut){
return decode_string_base64_file(content, outPut);
}
/*char* filetoBase64ToString2(char* filePath){
std::string str = encode_file_base64_string(filePath);
char * strc = new char[strlen(str.c_str()) + 1];
return strc;
}*/
pbBase64Func.h文件
#include "stdafx.h"
#include "lib.h"
#include <iostream>
#include <string>
extern "C" _declspec(dllexport) int _stdcall filetoBase64(char* filePath, char* outPut);
extern "C" _declspec(dllexport) int _stdcall base64ToFile(char* filePath, char* outPut);
extern "C" _declspec(dllexport) int _stdcall filetoBase64ToString(char* filePath, OUT char* content);
extern "C" _declspec(dllexport) int _stdcall base64ContentToFile(char* content, char* outPut);
//extern "C" _declspec(dllexport) char* _stdcall filetoBase64ToString2(char* filePath);
pbBase64Func.def文件
LIBRARY
EXPORTS
filetoBase64 @ 1
base64ToFile @ 2
filetoBase64ToString @ 3
base64ContentToFile @ 4
PB使用范例
//-----
String ls_pic1name,export_filename
If Getfilesavename("选择保存路径",ls_pic1name,export_filename,&
"zip","zip Files (*.zip),*.zip,"+ "jpg Files (*.jpg),*.jpg"+",bmp Files (*.bmp),*.bmp") <> 1 Then
is_filename = ''
return
Else
tab_1.tabpage_4.sle_4.text = ls_pic1name
is_filename = export_filename
End If
//-------
ls_filepath = sle_4.text
If FileExists(ls_filepath) Then
Else
messageBox('提示','你选择的文件不存在,请重新选择!')
return
End If
If isNUll(is_filename) or is_filename='' Then
messageBox('提示','请选择文件!')
return
End If
///------
Ls_outputpath = gs_rundir+'GXNNYB_BASE64TXT\'
If Not DirectoryExists ( Ls_outputpath ) Then
CreateDirectory ( Ls_outputpath )
End If
Ls_outputpath = Ls_outputpath +String(Now(),'YYYYMMDD') + '_BASE64_'+is_filename+'.TXT'
If FileExists(Ls_outputpath) Then
FileDelete(Ls_outputpath)//删除掉原先的文件
End if
//
ll_row = filetoBase64(ls_filepath,Ls_outputpath)//base64编码
If ll_row = 0 Then
//messageBox('提示','Base64编码文件成功!')
Else
messageBox('提示','Base64编码文件失败!【'+is_filename+'】')
return
End If
If wf_get_blob(Ls_outputpath,lb_base64String) = true then
else
messageBox('提示','读取失败!')
return
End If
获取到编码后的base64数据函数
//==============================================================================
// 函数: w_gxnnyb_tsxmba::wf_get_blob()
//------------------------------------------------------------------------------
// 描述:
//------------------------------------------------------------------------------
// 参数:
// string as_filepath
// ref blob ab_blob
//------------------------------------------------------------------------------
// 返回值: boolean
//------------------------------------------------------------------------------
// 作者: xyg 日期: 2019.12.12
//------------------------------------------------------------------------------
// 修改历史:
//
//------------------------------------------------------------------------------
// Copyright (c) 2000-2013 KingT Software Co., Ltd., All rights reserved.
//==============================================================================
string export_filename
integer li_FileNum, loops, i
long flen, bytes_read, new_pos,ll_filelen
blob b, tot_b
string str=''
// Set a wait cursor
//If Getfilesavename("选择保存路径",ls_pic1name,export_filename,&
//"zip","zip Files (*.zip),*.zip,"+ "jpg Files (*.jpg),*.jpg,"+"ALL Files (*.*),*.*") <> 1 Then return false
SetPointer(HourGlass!)
// Get the file length, and open the file
flen = FileLength(as_filepath)
ll_filelen = flen
li_FileNum = FileOpen(as_filepath,StreamMode!, Read!, LockRead!)
// Determine how many times to call FileRead
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
// Read the file
new_pos = 1
FOR i = 1 to loops
bytes_read = FileRead(li_FileNum, b)
Choose Case bytes_read
Case -100
Exit
Case 0
MessageBox('提示','读取文件出错!')
Return False
Case -1
MessageBox('提示','读取文件出错!')
Return False
End Choose
tot_b = tot_b + b
NEXT
FileClose(li_FileNum)
ab_blob = tot_b
Return true
PB外部函数声明(注意PB使用的时候不要system library,这个DLL只是代打工,不是正式员工,不然调用无响应,我还被坑了好久)
//function int filetoBase64ToString(string filePath, ref string content) library "pbBase64Func.dll"alias for "filetoBase64ToString"
//filePath:为base64加密文本路径 outPut:base64解密后的文件路径
function int base64ToFile(string filePath, string outPut) library "pbBase64Func.dll" alias for "base64ToFile"
//content:base64字符串 outPut:base64解密后的路径
function int base64ContentToFile(string content, string outPut) library "pbBase64Func.dll" alias for "base64ContentToFile"
//filePath:要加密的文件路径 output:转成base64后的编码字符串路径
function int filetoBase64(string filePath, string outPut) library "pbBase64Func.dll" alias for "filetoBase64"
lib.h 更新(2021-06-24更新 原先的有点问题重新改了下,base64编码出来后面会跟出许多\0)
#include <Windows.h>
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
#include "time.h"
bool is_readable(const std::string & file)
{
wchar_t szBuffer[1024];
OemToCharW(file.c_str(), szBuffer);
std::ifstream fichier(szBuffer);
return !fichier.fail();
}
long filesize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}
// Base 64
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len)
{
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (i = 0; (i < 4); i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i)
{
for (j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while ((i++ < 3))
ret += '=';
}
return ret;
}
std::string hex_string(std::string hexstr)
{
std::string str = "";
str.resize((hexstr.size() + 1) / 2);
for (size_t i = 0, j = 0; i < str.size(); i++, j++)
{
char at = '@';
str[i] = (hexstr[j] & at ? hexstr[j] + 9 : hexstr[j]) << 4, j++;
str[i] |= (hexstr[j] & at ? hexstr[j] + 9 : hexstr[j]) & 0xF;
}
return str;
}
std::string string_hex(std::string str, const bool capital = false)
{
std::string hexstr = "";
hexstr.resize(str.size() * 2);
static const char a = capital ? 0x40 : 0x60;
for (size_t i = 0; i < str.size(); i++)
{
char c = (str[i] >> 4) & 0xF;
hexstr[i * 2] = c > 9 ? (c - 9) | a : c | '0';
hexstr[i * 2 + 1] = (str[i] & 0xF) > 9 ? (str[i] - 9) & 0xF | a : str[i] & 0xF | '0';
}
return hexstr;
}
std::string char_to_string(char x[], int size_recv)
{
int num_car = 0;
int stop_while = size_recv;
std::string output = "";
while (stop_while > 0)
{
output += x[num_car];
/*if (x[num_car] == '\0')
break;*/
if (num_car < size_recv) { num_car++; }
stop_while--;
}
return output;
}
std::string str_base64_encode(std::string str)
{
return base64_encode(reinterpret_cast<const unsigned char*>(str.c_str()), str.length());
}
std::string base64_decode(std::string const& encoded_string) {
int in_len = encoded_string.size();
int i = 0;
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
char_array_4[i++] = encoded_string[in_]; in_++;
if (i == 4) {
for (i = 0; i < 4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; (i < 3); i++)
ret += char_array_3[i];
i = 0;
}
}
if (i) {
for (j = 0; j < i; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
}
return ret;
}
// Decode file
int decode_file_base64(std::string path_in, std::string path_out)
{
std::string path_file = path_in;
if (is_readable(path_file))
{
FILE *file_input;
FILE *file_output;
fopen_s(&file_input, path_file.c_str(), "ab+");
fopen_s(&file_output, path_out.c_str(), "ab+");
char buff_read[1024];
if (file_input != NULL)
{
long length = filesize(file_input);
std::string str_encode_buff = "";
size_t rtn = 1;
while (rtn)
{
rtn = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, min(sizeof(buff_read), length));
length = length - sizeof(buff_read);
memset(buff_read, 0, sizeof(buff_read));
}
str_encode_buff = base64_decode(str_encode_buff);
fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
fclose(file_input);
fclose(file_output);
}
delete[] buff_read;
}
return 0;
}
int encode_file_base64(std::string path_in, std::string path_out)
{
std::string path_file = path_in;
if (is_readable(path_file))
{
FILE *file_input;
FILE *file_output;
fopen_s(&file_input, path_file.c_str(), "ab+");
fopen_s(&file_output, path_out.c_str(), "ab+");
char buff_read[1024];
if (file_input != NULL)
{
std::string str_encode_buff = "";
size_t rtn = 1;
long length = filesize(file_input);
memset(buff_read, 0, sizeof(buff_read));
while (rtn)
{
rtn = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, min(sizeof(buff_read), length));
length = length - sizeof(buff_read);
memset(buff_read, 0, sizeof(buff_read));
}
str_encode_buff = str_base64_encode(str_encode_buff);
fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
fclose(file_input);
fclose(file_output);
}
delete[] buff_read;
}
return 0;
}
std::string getTime(){
time_t t = time(0);
char ch[64];
strftime(ch, sizeof(ch), "%Y-%m-%d %H-%M-%S %S", localtime(&t));
return std::string(ch) ;
}
int savelog(std::string as_content,std::string outLogPath){
if (outLogPath.empty()) return -1;
//return 0;
as_content = as_content + '\r'+'\n';
FILE *file_input;
//std::string path_in = "E:\\ProgramFile_xyg\\_Net_Program\\pbBase64Func\\KingTPowerBase64\\log\\20210623.log";
fopen_s(&file_input, outLogPath.c_str(), "ab+");
if (file_input != NULL){
std::string time = getTime()+":";
fwrite(time.c_str(), strlen(string_hex(time).c_str()) / 2, 1, file_input);
fwrite(as_content.c_str(), strlen(string_hex(as_content).c_str()) / 2, 1, file_input);
}
fclose(file_input);
return 0;
}
/*
int decode_jsonfile_base64(std::string path_in, std::string path_out, std::string jsonKey,std::string outlog){
savelog("path_in=" + path_in, outlog);
savelog("path_out=" + path_out, outlog);
savelog("jsonKey=" + jsonKey, outlog);
if (is_readable(path_in)){
FILE *file_input;
fopen_s(&file_input, path_in.c_str(), "ab+");
char buff_read[1024];
std::string str_encode_buff = "";
size_t rtn = 1;
long length = filesize(file_input);
memset(buff_read, 0, sizeof(buff_read));
savelog("decode_jsonfile_base64开始进入!", outlog);
if (file_input != NULL)
{
while (rtn)
{
rtn = fread(buff_read, sizeof(buff_read), 1, file_input);
str_encode_buff += char_to_string(buff_read, min(sizeof(buff_read), length));
length = length - sizeof(buff_read);
memset(buff_read, 0, sizeof(buff_read));
}
}
fclose(file_input);
delete[] buff_read;
savelog("file_input文件读取成功!", outlog);
JsonValue json = JsonParser::Parse(str_encode_buff.c_str());
savelog("Json实例化成功!", outlog);
unsigned int items = json.GetLength();
if (items <= 0) return -5;
bool lb_flags = false;
for (UINT i = 0, l = json.GetLength(); i < l; ++i)
{
JString name = json.GetName(i);
//JString type = json.Get(name)->GetType();
if (name.Equals(jsonKey.c_str())){
JString value = json.Get(name)->GetString();
str_encode_buff = value;
lb_flags = true;
break;
}
//Print("Name=[%-7s] Type=[%-7s] StringValue=\"%s\"", (char*)name, (char*)type, (char*)value);
}
savelog("Json取值结束!", outlog);
if (lb_flags == false) return -3;
savelog("Json取值成功!", outlog);
//读取完成进行base64解码
str_encode_buff = base64_decode(str_encode_buff);
savelog("Base64解码成功!", outlog);
FILE *file_output;
fopen_s(&file_output, path_out.c_str(), "ab+");
if (file_output != NULL){
fwrite(str_encode_buff.c_str(), strlen(string_hex(str_encode_buff).c_str()) / 2, 1, file_output);
}
fclose(file_output);
savelog("Base64解码后写入文件成功!", outlog);
//std::cout << "length=" + str_encode_buff.length() << std::endl;
}
else{
savelog("failure=", outlog);
return -1;
}
return 0;
}*/