@@ -9,7 +9,7 @@ import camelcaseKeys from 'camelcase-keys';
99import snakeCaseKeys from 'snakecase-keys' ;
1010import { Stream as SSEStream } from 'sse-decoder' ;
1111import { AlipayFormStream } from './AlipayFormStream.js' ;
12- import type { AlipaySdkConfig } from './types.js' ;
12+ import type { AlipaySdkConfig , AlipaySdkSignType } from './types.js' ;
1313import { AlipayFormData } from './form.js' ;
1414import {
1515 sign , ALIPAY_ALGORITHM_MAPPING , decamelize , createRequestId , readableToBytes ,
@@ -732,7 +732,7 @@ export class AlipaySdk {
732732 }
733733
734734 // 消息验签
735- private notifyRSACheck ( signArgs : { [ key : string ] : any } , signStr : string , signType : 'RSA' | 'RSA2' , raw ?: boolean ) {
735+ private notifyRSACheck ( signArgs : { [ key : string ] : any } , signStr : string , signType : AlipaySdkSignType , raw ?: boolean ) {
736736 const signContent = Object . keys ( signArgs ) . sort ( ) . filter ( val => val )
737737 . map ( key => {
738738 let value = signArgs [ key ] ;
@@ -748,10 +748,7 @@ export class AlipaySdk {
748748 return `${ key } =${ decodeURIComponent ( value ) } ` ;
749749 } )
750750 . join ( '&' ) ;
751-
752- const verifier = createVerify ( ALIPAY_ALGORITHM_MAPPING [ signType ] ) ;
753-
754- return verifier . update ( signContent , 'utf8' ) . verify ( this . config . alipayPublicKey , signStr , 'base64' ) ;
751+ return this . rsaCheck ( signContent , signStr , signType ) ;
755752 }
756753
757754 /**
@@ -1024,4 +1021,14 @@ export class AlipaySdk {
10241021 aesDecrypt ( encryptedText : string ) {
10251022 return aesDecryptText ( encryptedText , this . config . encryptKey ) ;
10261023 }
1024+
1025+ /**
1026+ * 对指定内容进行验签
1027+ *
1028+ * 如对前端返回的报文进行验签 https://opendocs.alipay.com/common/02mse3#AES%20%E8%A7%A3%E5%AF%86%E5%87%BD%E6%95%B0
1029+ */
1030+ rsaCheck ( signContent : string , sign : string , signType : AlipaySdkSignType = 'RSA2' ) {
1031+ const verifier = createVerify ( ALIPAY_ALGORITHM_MAPPING [ signType ] ) ;
1032+ return verifier . update ( signContent , 'utf-8' ) . verify ( this . config . alipayPublicKey , sign , 'base64' ) ;
1033+ }
10271034}
0 commit comments