Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OTWebSocketHub
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李福茂
OTWebSocketHub
Commits
d77cbb16
Commit
d77cbb16
authored
Jun 08, 2021
by
Maodashu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加api请求授权机制
parent
73f7f358
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
ApiService.cs
OTWebSocket.API/Services/ApiService.cs
+6
-1
No files found.
OTWebSocket.API/Services/ApiService.cs
View file @
d77cbb16
...
...
@@ -19,6 +19,7 @@ namespace OTWebSocket.API.Services
{
public
class
ApiService
{
private
readonly
string
psw
;
private
readonly
string
_apiBaseUrl
;
private
readonly
ILogger
<
ApiService
>
_logger
;
private
readonly
HttpClient
_httpClient
;
...
...
@@ -27,6 +28,7 @@ namespace OTWebSocket.API.Services
_apiBaseUrl
=
options
.
Value
.
ApiBaseUrl
;
_logger
=
logger
;
_httpClient
=
new
HttpClient
();
psw
=
"nixiaode"
;
}
public
async
Task
<
List
<
AccountInfo
>>
GetKeyList
()
...
...
@@ -35,6 +37,7 @@ namespace OTWebSocket.API.Services
List
<
AccountInfo
>
ret
=
null
;
string
endpoint
=
$"/key"
;
HttpRequestMessage
req
=
new
HttpRequestMessage
(
HttpMethod
.
Get
,
_apiBaseUrl
+
endpoint
);
req
.
Headers
.
Add
(
"Authorization"
,
psw
);
HttpResponseMessage
resp
=
await
_httpClient
.
SendAsync
(
req
);
string
content
=
await
resp
.
Content
.
ReadAsStringAsync
();
_logger
.
Debug
(
$"[请求账户列表] API返回:
{
content
}
"
);
...
...
@@ -82,7 +85,7 @@ namespace OTWebSocket.API.Services
{
"ot_symbol"
,
ot_symbol
}
};
HttpRequestMessage
req
=
new
HttpRequestMessage
(
HttpMethod
.
Post
,
_apiBaseUrl
+
endpoint
);
req
.
Headers
.
Add
(
"Authorization"
,
psw
);
req
.
Content
=
new
StringContent
(
payload
.
ToString
(),
Encoding
.
UTF8
,
"application/json"
);
HttpResponseMessage
resp
=
await
_httpClient
.
SendAsync
(
req
);
string
content
=
await
resp
.
Content
.
ReadAsStringAsync
();
...
...
@@ -120,6 +123,7 @@ namespace OTWebSocket.API.Services
string
endpoint
=
$"/mao/mongo/query/
{
orderId
}
"
;
HttpRequestMessage
req
=
new
HttpRequestMessage
(
HttpMethod
.
Get
,
_apiBaseUrl
+
endpoint
);
req
.
Headers
.
Add
(
"Authorization"
,
psw
);
HttpResponseMessage
resp
=
await
_httpClient
.
SendAsync
(
req
);
string
content
=
await
resp
.
Content
.
ReadAsStringAsync
();
_logger
.
Debug
(
$"[请求MongoDB订单信息] API返回:
{
content
}
"
);
...
...
@@ -149,6 +153,7 @@ namespace OTWebSocket.API.Services
string
endpoint
=
$"/mao/mongo/update/
{
order
.
OrderId
}
"
;
JObject
payload
=
JObject
.
FromObject
(
order
);
HttpRequestMessage
req
=
new
HttpRequestMessage
(
HttpMethod
.
Put
,
_apiBaseUrl
+
endpoint
);
req
.
Headers
.
Add
(
"Authorization"
,
psw
);
req
.
Content
=
new
StringContent
(
payload
.
ToString
(),
Encoding
.
UTF8
,
"application/json"
);
HttpResponseMessage
resp
=
await
_httpClient
.
SendAsync
(
req
);
string
content
=
await
resp
.
Content
.
ReadAsStringAsync
();
...
...
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