HGGitLab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
app
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
luoliangyi
app
Commits
048079a4
Commit
048079a4
authored
Apr 22, 2022
by
luoliangyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websdk:增加ofd、pdf、tiff和zip返回base64的功能
parent
7e3b95ca
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
220 additions
and
24 deletions
+220
-24
release/bin/windows/x86/HGWebService.exe
release/bin/windows/x86/HGWebService.exe
+0
-0
sdk/webservice/HttpUser.cpp
sdk/webservice/HttpUser.cpp
+109
-4
sdk/webservice/Manager.cpp
sdk/webservice/Manager.cpp
+102
-16
sdk/webservice/Manager.h
sdk/webservice/Manager.h
+9
-4
No files found.
release/bin/windows/x86/HGWebService.exe
View file @
048079a4
No preview for this file type
sdk/webservice/HttpUser.cpp
View file @
048079a4
...
...
@@ -303,35 +303,140 @@ void HttpUser::HandleCmd(const HttpCmdParam* param)
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
}
}
else
if
(
requestMethod
==
"POST"
&&
requestURIPath
==
"/WebScan/majorOfd"
)
{
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
majorOfdParam
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"formDataString"
);
std
::
string
devId
;
bool
isAuto
=
false
;
cJSON
*
json
=
cJSON_Parse
(
majorOfdParam
.
c_str
());
if
(
NULL
!=
json
)
{
devId
=
GetJsonStringValue
(
json
,
"pid"
);
isAuto
=
GetJsonBoolValue
(
json
,
"isAuto"
);
cJSON_Delete
(
json
);
}
std
::
string
imgBase64
;
GetManager
()
->
ExportOfd
(
devId
,
isAuto
,
imgBase64
);
char
*
result
=
new
char
[
imgBase64
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
imgBase64
.
c_str
());
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
delete
[]
result
;
}
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/majorOfdFile"
)
{
std
::
string
devId
=
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"pid"
);
bool
isAuto
=
(
"true"
==
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"isAuto"
)
?
true
:
false
);
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
GetManager
()
->
ExportOfdFile
(
&
data
,
&
size
);
GetManager
()
->
ExportOfdFile
(
devId
,
isAuto
,
&
data
,
&
size
);
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
data
,
size
,
"application/zip"
);
delete
[]
data
;
}
else
if
(
requestMethod
==
"POST"
&&
requestURIPath
==
"/WebScan/majorPdf"
)
{
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
majorOfdParam
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"formDataString"
);
std
::
string
devId
;
cJSON
*
json
=
cJSON_Parse
(
majorOfdParam
.
c_str
());
if
(
NULL
!=
json
)
{
devId
=
GetJsonStringValue
(
json
,
"pid"
);
cJSON_Delete
(
json
);
}
std
::
string
imgBase64
;
GetManager
()
->
ExportPdf
(
devId
,
imgBase64
);
char
*
result
=
new
char
[
imgBase64
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
imgBase64
.
c_str
());
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
delete
[]
result
;
}
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/majorPdfFile"
)
{
std
::
string
devId
=
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"pid"
);
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
GetManager
()
->
ExportPdfFile
(
&
data
,
&
size
);
GetManager
()
->
ExportPdfFile
(
devId
,
&
data
,
&
size
);
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
data
,
size
,
"application/pdf"
);
delete
[]
data
;
}
else
if
(
requestMethod
==
"POST"
&&
requestURIPath
==
"/WebScan/majorTiff"
)
{
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
string
imgBase64
;
GetManager
()
->
ExportTiff
(
devId
,
imgBase64
);
char
*
result
=
new
char
[
imgBase64
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
imgBase64
.
c_str
());
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
delete
[]
result
;
}
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/majorTiffFile"
)
{
std
::
string
devId
=
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"pid"
);
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
GetManager
()
->
ExportTiffFile
(
&
data
,
&
size
);
GetManager
()
->
ExportTiffFile
(
devId
,
&
data
,
&
size
);
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
data
,
size
,
"application/x-tif"
);
delete
[]
data
;
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/downLoadZip"
)
{
if
(
std
::
string
::
npos
!=
param
->
head
.
GetContentType
().
find
(
"application/x-www-form-urlencoded"
))
{
std
::
string
query
((
const
char
*
)
param
->
data
,
param
->
size
);
HttpPairs
uriQueryInfos
;
HttpHead
::
AnalysisURIQuery
(
query
.
c_str
(),
uriQueryInfos
);
std
::
string
devId
=
HttpHead
::
GetValue
(
uriQueryInfos
,
"pid"
);
std
::
string
imgBase64
;
GetManager
()
->
ExportZip
(
devId
,
imgBase64
);
char
*
result
=
new
char
[
imgBase64
.
size
()
+
256
];
sprintf
(
result
,
"{
\"
code
\"
:%d,
\"
msg
\"
:null,
\"
data
\"
:%s}"
,
200
,
imgBase64
.
c_str
());
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
(
const
HGByte
*
)
result
,
(
HGUInt
)
strlen
(
result
),
"application/json"
);
delete
[]
result
;
}
}
else
if
(
requestMethod
==
"GET"
&&
requestURIPath
==
"/WebScan/downLoadZipFile"
)
{
std
::
string
devId
=
HttpHead
::
GetValue
(
requestURIQueryInfos
,
"pid"
);
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
GetManager
()
->
ExportZipFile
(
&
data
,
&
size
);
GetManager
()
->
ExportZipFile
(
devId
,
&
data
,
&
size
);
SendResponse
(
requestHttpVersion
.
c_str
(),
200
,
"OK"
,
data
,
size
,
"application/zip"
);
delete
[]
data
;
}
...
...
sdk/webservice/Manager.cpp
View file @
048079a4
...
...
@@ -652,7 +652,27 @@ bool Manager::SetDevParam(const std::string& devId, const DevParam& devParam)
return
ret
;
}
bool
Manager
::
ExportOfdFile
(
HGByte
**
data
,
HGUInt
*
size
)
bool
Manager
::
ExportOfd
(
const
std
::
string
&
devId
,
bool
isAuto
,
std
::
string
&
imgBase64
)
{
imgBase64
.
clear
();
if
(
m_scanning
)
{
return
false
;
}
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
ExportOfdFile
(
devId
,
isAuto
,
&
data
,
&
size
);
if
(
NULL
!=
data
)
{
imgBase64
=
GetBase64
(
data
,
size
);
delete
[]
data
;
}
return
!
imgBase64
.
empty
();
}
bool
Manager
::
ExportOfdFile
(
const
std
::
string
&
devId
,
bool
isAuto
,
HGByte
**
data
,
HGUInt
*
size
)
{
*
data
=
NULL
;
*
size
=
0
;
...
...
@@ -661,9 +681,6 @@ bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
return
false
;
}
std
::
string
devId
;
GetCurDevId
(
devId
);
std
::
string
filePath
=
GetFilePath
(
devId
);
std
::
vector
<
std
::
string
>
fileNameList
=
GetFileNameList
(
devId
);
if
(
fileNameList
.
empty
())
...
...
@@ -708,7 +725,27 @@ bool Manager::ExportOfdFile(HGByte** data, HGUInt* size)
return
(
NULL
!=
*
data
);
}
bool
Manager
::
ExportPdfFile
(
HGByte
**
data
,
HGUInt
*
size
)
bool
Manager
::
ExportPdf
(
const
std
::
string
&
devId
,
std
::
string
&
imgBase64
)
{
imgBase64
.
clear
();
if
(
m_scanning
)
{
return
false
;
}
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
ExportPdfFile
(
devId
,
&
data
,
&
size
);
if
(
NULL
!=
data
)
{
imgBase64
=
GetBase64
(
data
,
size
);
delete
[]
data
;
}
return
!
imgBase64
.
empty
();
}
bool
Manager
::
ExportPdfFile
(
const
std
::
string
&
devId
,
HGByte
**
data
,
HGUInt
*
size
)
{
*
data
=
NULL
;
*
size
=
0
;
...
...
@@ -717,9 +754,6 @@ bool Manager::ExportPdfFile(HGByte** data, HGUInt* size)
return
false
;
}
std
::
string
devId
;
GetCurDevId
(
devId
);
std
::
string
filePath
=
GetFilePath
(
devId
);
std
::
vector
<
std
::
string
>
fileNameList
=
GetFileNameList
(
devId
);
if
(
fileNameList
.
empty
())
...
...
@@ -764,7 +798,27 @@ bool Manager::ExportPdfFile(HGByte** data, HGUInt* size)
return
(
NULL
!=
*
data
);
}
bool
Manager
::
ExportTiffFile
(
HGByte
**
data
,
HGUInt
*
size
)
bool
Manager
::
ExportTiff
(
const
std
::
string
&
devId
,
std
::
string
&
imgBase64
)
{
imgBase64
.
clear
();
if
(
m_scanning
)
{
return
false
;
}
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
ExportTiffFile
(
devId
,
&
data
,
&
size
);
if
(
NULL
!=
data
)
{
imgBase64
=
GetBase64
(
data
,
size
);
delete
[]
data
;
}
return
!
imgBase64
.
empty
();
}
bool
Manager
::
ExportTiffFile
(
const
std
::
string
&
devId
,
HGByte
**
data
,
HGUInt
*
size
)
{
*
data
=
NULL
;
*
size
=
0
;
...
...
@@ -773,9 +827,6 @@ bool Manager::ExportTiffFile(HGByte** data, HGUInt* size)
return
false
;
}
std
::
string
devId
;
GetCurDevId
(
devId
);
std
::
string
filePath
=
GetFilePath
(
devId
);
std
::
vector
<
std
::
string
>
fileNameList
=
GetFileNameList
(
devId
);
if
(
fileNameList
.
empty
())
...
...
@@ -820,7 +871,27 @@ bool Manager::ExportTiffFile(HGByte** data, HGUInt* size)
return
(
NULL
!=
*
data
);
}
bool
Manager
::
ExportZipFile
(
HGByte
**
data
,
HGUInt
*
size
)
bool
Manager
::
ExportZip
(
const
std
::
string
&
devId
,
std
::
string
&
imgBase64
)
{
imgBase64
.
clear
();
if
(
m_scanning
)
{
return
false
;
}
HGByte
*
data
=
NULL
;
HGUInt
size
=
0
;
ExportZipFile
(
devId
,
&
data
,
&
size
);
if
(
NULL
!=
data
)
{
imgBase64
=
GetBase64
(
data
,
size
);
delete
[]
data
;
}
return
!
imgBase64
.
empty
();
}
bool
Manager
::
ExportZipFile
(
const
std
::
string
&
devId
,
HGByte
**
data
,
HGUInt
*
size
)
{
*
data
=
NULL
;
*
size
=
0
;
...
...
@@ -829,9 +900,6 @@ bool Manager::ExportZipFile(HGByte** data, HGUInt* size)
return
false
;
}
std
::
string
devId
;
GetCurDevId
(
devId
);
std
::
string
filePath
=
GetFilePath
(
devId
);
std
::
vector
<
std
::
string
>
fileNameList
=
GetFileNameList
(
devId
);
if
(
fileNameList
.
empty
())
...
...
@@ -1376,6 +1444,24 @@ std::string Manager::GetBase64(HGImage image, HGUInt quality)
return
strBase64
;
}
std
::
string
Manager
::
GetBase64
(
const
HGByte
*
data
,
HGUInt
size
)
{
std
::
string
strBase64
;
if
(
NULL
!=
data
&&
0
!=
size
)
{
HGSize
base64Size
=
0
;
HGBase_Base64Encode
(
data
,
size
,
NULL
,
&
base64Size
);
uint8_t
*
base64
=
new
uint8_t
[
base64Size
+
1
];
HGBase_Base64Encode
(
data
,
size
,
base64
,
&
base64Size
);
base64
[
base64Size
]
=
0
;
strBase64
=
(
const
char
*
)
base64
;
delete
[]
base64
;
}
return
strBase64
;
}
std
::
string
Manager
::
GetBase64
(
const
std
::
string
&
fileName
)
{
std
::
string
strBase64
;
...
...
sdk/webservice/Manager.h
View file @
048079a4
...
...
@@ -113,13 +113,17 @@ public:
// 设置配置参数
bool
SetDevParam
(
const
std
::
string
&
devId
,
const
DevParam
&
devParam
);
// 生成OFD
bool
ExportOfdFile
(
HGByte
**
data
,
HGUInt
*
size
);
bool
ExportOfd
(
const
std
::
string
&
devId
,
bool
isAuto
,
std
::
string
&
imgBase64
);
bool
ExportOfdFile
(
const
std
::
string
&
devId
,
bool
isAuto
,
HGByte
**
data
,
HGUInt
*
size
);
// 生成PDF
bool
ExportPdfFile
(
HGByte
**
data
,
HGUInt
*
size
);
bool
ExportPdf
(
const
std
::
string
&
devId
,
std
::
string
&
imgBase64
);
bool
ExportPdfFile
(
const
std
::
string
&
devId
,
HGByte
**
data
,
HGUInt
*
size
);
// 生成TIFF
bool
ExportTiffFile
(
HGByte
**
data
,
HGUInt
*
size
);
bool
ExportTiff
(
const
std
::
string
&
devId
,
std
::
string
&
imgBase64
);
bool
ExportTiffFile
(
const
std
::
string
&
devId
,
HGByte
**
data
,
HGUInt
*
size
);
// 生成ZIP
bool
ExportZipFile
(
HGByte
**
data
,
HGUInt
*
size
);
bool
ExportZip
(
const
std
::
string
&
devId
,
std
::
string
&
imgBase64
);
bool
ExportZipFile
(
const
std
::
string
&
devId
,
HGByte
**
data
,
HGUInt
*
size
);
// 上传图像
bool
UploadImage
(
const
UploadParam
&
uploadParam
);
// 保存图片
...
...
@@ -153,6 +157,7 @@ private:
static
std
::
vector
<
std
::
string
>
GetFileNameList
(
const
std
::
string
&
devId
);
static
bool
SaveFileNameList
(
const
std
::
string
&
devId
,
const
std
::
vector
<
std
::
string
>&
fileNameList
);
static
std
::
string
GetBase64
(
HGImage
image
,
HGUInt
quality
);
static
std
::
string
GetBase64
(
const
HGByte
*
data
,
HGUInt
size
);
static
std
::
string
GetBase64
(
const
std
::
string
&
fileName
);
static
HGByte
*
GetBuffer
(
const
std
::
string
&
fileName
,
HGUInt
*
size
);
static
bool
SaveBase64
(
const
std
::
string
&
fileName
,
const
char
*
base64
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment