参数签名
安全支付
简单代码示例:
import crypto from 'crypto';
import { URL } from 'url';
// Configuration - replace with your actual values
const originalUrl = 'https://cashier.blockatm.com?apiKey=pck_payment_my3T68cbuIXf1x3QOEbWtFEfcJPxeBr8wTewDVM¤cyCode=eth&walletAddress=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae';
const secretKey = 'sck_QOoPSlHDSsgXYeNyTP2i0ug1HKLRjHw9Ug7mCc1Q0';
// Process URL and parameters
const urlObj = new URL(originalUrl);
const params = urlObj.searchParams;
// URL encode all parameter values
params.forEach((v, k) => params.set(k, encodeURIComponent(v)));
// Generate signature using HMAC-SHA256
const signature = crypto.createHmac('sha256', secretKey)
.update(params.toString())
.digest('hex');
// Append signature to URL
urlObj.searchParams.set('signature', signature);
console.log('Signed URL:\n' + urlObj.toString());签名示例:
Last updated