idea http client 自动签名
使用签名 HTTP Client 的加密库 crypto
获取 token 后 全局变量中
### 获取 token
GET {{host}}/api/getBtzhDocApi?apikey=xxxx&userid=xxxx
userid: xxx
user-user-agent: JAVA
Content-Type: application/x-www-form-urlencoded
Accept: application/json
> {%
client.global.set("auth_token", response.body.data.token);
client.log(client.global.get("auth_token"));
%}
签名在发送请求之前
< {%
const originalText = "{encodeFlag=0&ofdStr=U0dWc2JHOHNJRmR2Y214a0lRPT0=&sealid=xxxx&signConfigJson={\"stampedPages\":\"2\",\"x\":\"140\",\"y\":\"250\"}}@xxxx";
const signature = crypto.md5().updateWithText(originalText)
.digest().toHex();
client.log('signature: ' + signature)
request.variables.set("signature", signature)
%}
POST {{host}}/ythptdzzz/api/xxx/xxx
userid: xxx
token: {{auth_token}}
sig: {{signature}}
user-user-agent: JAVA x-b3-traceid x-b3-spanid x-b3-parentspanid
Content-Type: application/x-www-form-urlencoded
encodeFlag=0&ofdStr=U0dWc2JHOHNJRmR2Y214a0lRPT0=&sealid=xxx&signConfigJson={"stampedPages":"2","x":"140","y":"250"}
自动crypto
< {%
const signature = crypto.hmac.sha256()
.withTextSecret(request.environment.get("secret"))
.updateWithText(request.body.tryGetSubstituted())
.digest().toHex();
request.variables.set("signature", signature)
const hash = crypto.sha256()
.updateWithText(request.body.tryGetSubstituted())
.digest().toHex();
request.variables.set("hash", hash)
%}
POST https://httpbin.org/post
X-My-Signature: {{signature}}
X-My-Hash: {{hash}}
Content-Type: application/json
{
"prop": "value"
}
sha1
< {%
const timestamp = 1723097694
const appKey ='123456'
const appSecret ='123456'
const signRaw = `${appKey}${appSecret}${timestamp}`;
const signature = crypto.sha1().updateWithText(signRaw).digest().toHex()
request.variables.set("sign", signature)
request.variables.set("time_stamp", signature)
// request.variables.set("timestamp", timestamp)
%}
POST https://httpbin.org/post
timestamp: {{time_stamp}}
appkey: 123456
sgin: {{sign}}
Content-Type: application/json
{
"prop": "value"
}
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17570670.html