mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-02 03:40:26 +00:00
修复Post通知验签时间戳缺失 by xiaoyuanhost
This commit is contained in:
parent
dcb645a4b2
commit
c6448e6a6e
@ -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();
|
||||
|
@ -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)
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user