Skip to content

verifySign

回调签名验证

使用示例

ts
import { WechatService } from 'nest-wxpay'

@Injectable()
export class Controller {
  constructor(private readonly wechatService: WechatService) {}

  @Post('callback')
  async callback(
    @Body() body: PayCallbackResponse,
    @Headers() headers: Record<string, string>
  ): Promise<> {
    const timestamp = headers['Wechatpay-Timestamp']
    const nonce = headers['Wechatpay-Nonce']
    const signature = headers['Wechatpay-Signature']
    const result = await this.wechatService.verifySign({
      nonce,
      signature,
      timestamp,
      requestBody: JSON.stringify(body)
    })
    console.log(`验证结果 => ${result}`)
  }
}

参数解析

PayCallbackResource

字段名类型是否必填用途
algorithmstring对开启结果数据进行加密的加密算法,目前只支持AEAD_AES_256_GCM
ciphertextstringBase64编码后的开启/停用结果数据密文
associated_datastring附加数据
original_typestring原始回调类型,为transaction
noncestring加密使用的随机串

PayCallbackResponse

字段名类型是否必填用途
idstring通知的唯一ID
create_timestring通知创建的时间,遵循rfc3339标准格式
event_typestring通知的类型,支付成功通知的类型为TRANSACTION.SUCCESS
resource_typestring通知的资源数据类型,支付成功通知为encrypt-resource
resourcePayCallbackResource通知资源数据

响应参数

boolean