Skip to content

Commit 4b8df0e

Browse files
committed
feat: 新增 checkNotifySignV2
默认不对 value 进行 decode closes #45
1 parent 8a2b2bd commit 4b8df0e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,21 @@ const queryObj = {
282282
const signResult = sdk.checkNotifySign(queryObj);
283283
```
284284

285+
如果遇到验签失败,请尝试使用 `checkNotifySignV2()` 方法代替,它默认不会对 value 进行 decode
286+
https://github.com/alipay/alipay-sdk-nodejs-all/issues/45 场景问题。
287+
288+
```ts
289+
const postData = {
290+
sign_type: 'RSA2',
291+
sign: 'QfTb8tqE1BMhS5qAn.....',
292+
gmt_create: '2019-08-15 15:56:22',
293+
other_biz_field: '....',
294+
}
295+
296+
// true | false
297+
const signResult = sdk.checkNotifySignV2(postData);
298+
```
299+
285300
## alipay-sdk v3 到 v4 的升级说明
286301

287302
从 v3 到 v4 有以下不兼容变更,请参考示例代码进行更新
@@ -437,6 +452,16 @@ curl 方式调用支付宝 [API v3 协议](https://opendocs.alipay.com/open-v3/0
437452
| bizContent | 业务请求参数 | `object` ||
438453
| needEncrypt | 自动 AES 加解密 | `boolean` ||
439454

455+
### alipaySdk.checkNotifySignV2(postData)
456+
457+
通知验签,默认不会对 value 进行 decode
458+
459+
**Returns**: `Boolean` - 是否验签成功
460+
461+
| Param | Type | Description |
462+
| --- | --- | --- |
463+
| postData | `JSON` | 服务端的消息内容 |
464+
440465
### alipaySdk.checkNotifySign(postData, raw)
441466

442467
通知验签

src/alipay.ts

+11
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,17 @@ export class AlipaySdk {
784784
}
785785
}
786786

787+
/**
788+
* 通知验签,不对 value 进行 decode
789+
* @param {JSON} postData 服务端的消息内容
790+
* @return { Boolean } 验签是否成功
791+
*/
792+
public checkNotifySignV2(postData: any) {
793+
// 修复常见问题 https://github.com/alipay/alipay-sdk-nodejs-all/issues/45
794+
// 由于要保持 checkNotifySign 方法兼容性,所以新增一个 checkNotifySignV2 代替
795+
return this.checkNotifySign(postData, true);
796+
}
797+
787798
/**
788799
* 通知验签
789800
* @param {JSON} postData 服务端的消息内容

test/alipay.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ describe('test/alipay.test.ts', () => {
735735
});
736736
});
737737

738-
describe('checkNotifySign', () => {
738+
describe('checkNotifySign(), checkNotifySignV2()', () => {
739739
let sdk: AlipaySdk;
740740
beforeEach(() => {
741741
sdk = new AlipaySdk({
@@ -835,6 +835,7 @@ describe('test/alipay.test.ts', () => {
835835
point_amount: '0.00',
836836
};
837837
assert.equal(sdk.checkNotifySign(postData), true);
838+
assert.equal(sdk.checkNotifySignV2(postData), true);
838839
});
839840

840841
it('verify fail', () => {

0 commit comments

Comments
 (0)