問題:
https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE-Node-Manager/interface.html#id225
當呼叫下面的介面報錯,以下是官方的檔案,
新增私鑰用戶
11.1.1 傳輸協議規范
- 網路傳輸協議:使用HTTP協議
- 請求地址:/user/userInfo
- 請求方式:POST
- 請求頭:Content-type: application/json
- 回傳格式:JSON
11.1.2 請求引數
1)入參表
|
序號 |
輸入引數 |
型別 |
可為空 |
備注 |
|
1 |
userName |
string |
否 |
用戶名稱 |
|
2 |
description |
string |
是 |
備注 |
|
3 |
groupId |
Int |
否 |
所屬群組 |
2)入參示例
http://127.0.0.1:5001//WeBASE-Node-Manager/user/userInfo
{ "groupId": "300001", "description": "密鑰擁有者", "userName": "user1" }
11.1.3 回傳引數
1)出參表
|
序號 |
輸出引數 |
型別 |
備注 |
|
|
1 |
code |
Int |
否 |
回傳碼,0:成功 其它:失敗 |
|
2 |
message |
String |
否 |
描述 |
|
3 |
data |
object |
是 |
回傳資訊物體(成功時不為空) |
|
3.1 |
userId |
int |
否 |
用戶編號 |
|
3.2 |
userName |
string |
否 |
用戶名稱 |
|
3.3 |
groupId |
int |
否 |
所屬群組編號 |
|
3.4 |
description |
String |
是 |
備注 |
|
3.5 |
userStatus |
int |
否 |
狀態(1-正常 2-停用) 默認1 |
|
3.6 |
publicKey |
String |
否 |
公鑰資訊 |
|
3.7 |
address |
String |
是 |
在鏈上位置的hash |
|
3.8 |
hasPk |
Int |
否 |
是否擁有私鑰資訊(1-擁有,2-不擁有) |
|
3.9 |
createTime |
LocalDateTime |
否 |
創建時間 |
|
3.10 |
modifyTime |
LocalDateTime |
否 |
修改時間 |
2)出參示例
- 成功:
{ "code": 0, "message": "success", "data": { "userId": 700007, "userName": "asdfvw", "groupId": 300001, "publicKey": "0x4189fdacff55fb99172e015e1adc360777bee6682fcc975238aabf144fbf610a3057fd4b5", "userStatus": 1, "userType": 1, "address": "0x40ec3c20b5178401ae14ad8ce9c9f94fa5ebb86a", "hasPk": 1, "description": "sda", "createTime": "2019-03-15 18:00:27", "modifyTime": "2019-03-15 18:00:27" } }
- 失敗:
{ "code": 102000, "message": "system exception", "data": {} }
我們正常呼叫發現報錯:
{
"code": 202014,
"message": "user already exists",
"data": null
}
解決方案:
抓取webase登錄的包如下:
POST http://192.168.119.129:5000/mgr/WeBASE-Node-Manager/account/login?checkCode=ypqw HTTP/1.1
Host: 192.168.119.129:5000
Connection: keep-alive
Content-Length: 89
Accept: application/json, text/plain, */*
Origin: http://192.168.119.129:5000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
token: 6604a4b3e9268978d26eb9fef16401d34f3cc25e985f4967dd2f06d12c21eb65
Content-Type: application/x-www-form-urlencoded
Referer: http://192.168.119.129:5000/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: __guid=52830440.4353789523233634000.1599636751383.38; monitor_count=5
account=admin&accountPwd=5fef526bd3b7b26001f826f469250cb954299a0169a46d11ac37a263a9ab6ab5
HTTP/1.1 200
Server: nginx/1.14.2
Date: Wed, 09 Sep 2020 09:08:14 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 169
Connection: keep-alive
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Set-Cookie: JSESSIONID=2C7B692F335CE6BCBA8281A6F3F0AFAD; Path=/WeBASE-Node-Manager; HttpOnly
X-Frame-Options: SAMEORIGIN
{"code":0,"message":"success","data":{"accountStatus":2,"roleName":"admin","account":"admin","token":"fb50e4bbaa0e370692e35ea8b3d9f2da92aa03b9335b6a26be2297de12ee7619"}}
這里我發現有2種方式可以去呼叫需要登錄之后的介面比如上述的介面
1.JSESSIONID=2C7B692F335CE6BCBA8281A6F3F0AFAD 把登錄的這個cookie帶入介面請求
2.頭資訊中帶Authorization Token Tokenfb50e4bbaa0e370692e35ea8b3d9f2da92aa03b9335b6a26be2297de12ee7619
如下圖所示:

成功解決問題!
關于應用中的呼叫問題:
呼叫這個介面需要頭資訊中帶token ,這個token的獲取需要登錄,而登錄需要有驗證碼,我在應用中怎么去不需要人為的操作就能獲取這個token?我想到幾個方法?
1.模擬登錄破解圖形驗證碼
2.修改原始碼新增一個不需要驗證碼的登錄介面
3.登錄后定時去訪問一個WeBASE-Node-Manager下的介面,讓token不失效
官方回復:
有關閉登錄驗證的配置,可以看下yml,把security配置改成false
具體詳細的操作如下:


但是會存在問題,
security為false 后 webase登錄頁 就登錄不進去了!

官方解釋:
設為false之后,可以直接呼叫Get介面,但是post介面會因為springboot的PreAuthorized特性導致不可用
如果又webase和相關介面都想用的可以參考:
1.模擬登錄破解圖形驗證碼
2.修改原始碼新增一個不需要驗證碼的登錄介面
3.登錄后定時去訪問一個WeBASE-Node-Manager下的介面,讓token不失效
這個3個方案 第2個最靠譜,建議采用,后續官方會增加一個驗證碼配置,下圖為證:

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/4678.html
標籤:其他
上一篇:2020年最新螞蟻金服Java面經:HashMap+多執行緒+快取+中間件(含答案)
下一篇:Android 11正式版發布!
