修复Post通知验签时间戳缺失 by xiaoyuanhost

This commit is contained in:
pppscn 2021-03-03 14:49:32 +08:00
parent dcb645a4b2
commit c6448e6a6e
2 changed files with 7 additions and 6 deletions

View File

@ -49,7 +49,8 @@ public class SenderWebNotifyMsg {
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
String sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8");
Log.i(TAG, "sign:" + sign);
builder.addFormDataPart("content", content);
builder.addFormDataPart("timestamp", String.valueOf(timestamp));
builder.addFormDataPart("sign", sign);
}
RequestBody body = builder.build();

View File

@ -13,13 +13,15 @@ https://api.sl.allmything.com/api/msg/pushMsg?token=p9EM2K4Po01UIJr3sISbRmBFYWCH
| ---- | ---- | ---- |
| from | string | 来源手机号 |
| content | string | 短信内容 |
| timestamp | string | 当前时间戳单位是毫秒建议验证与请求调用时间误差不能超过1小时防止重放欺骗 |
| sign | string | 当设置secret时生成的sign签名用于发送端校验规则见下方sign校验规则 |
* sign部分参考借鉴了[阿里钉钉群机器人的sign生成](https://developers.dingtalk.com/document/app/custom-robot-access)
### sign校验规则
把timestamp+"\n"+密钥当做签名字符串使用HmacSHA256算法计算签名然后进行Base64 encode最后再把签名参数再进行urlEncode得到最终的签名需要使用UTF-8字符集
| 参数 | 说明 |
| ---- | ---- |
| timestamp | 当前时间戳单位是毫秒与请求调用时间误差不能超过1小时 |
| timestamp | 当前时间戳,单位是毫秒,(建议验证与请求调用时间误差不能超过1小时,防止重放欺骗) |
| secret | 密钥web通知设置页面secret |
示例:
@ -48,7 +50,7 @@ public class Test {
```
```python
#python 3.8
#python 3.8
import time
import hmac
import hashlib
@ -66,7 +68,7 @@ print(timestamp)
print(sign)
```
```python
```python
#python 2.7
import time
import hmac
@ -85,5 +87,3 @@ print(timestamp)
print(sign)
```