聚合支付
该支付接通-友商-扫呗-代码示例
const paydata = req.body;
let data = {
"pay_ver": "201",
"pay_type": "000",
"service_id": "016",
"merchant_no": "87*******46",
"terminal_id": "14*****00",
"terminal_trace": 支付交易号,
"notify_url": `成功回调地址`,
"terminal_time":
"total_fee": 支付金额,
"order_body": `订单说明`,
"attach": `附加数据`,
"repeated_trace": "0",
"timeout_express": "7200",
};
let sortedKeys = Object.keys(data).sort();
let signString = '';
for (let key of sortedKeys) {
if (key !== 'key_sign') {
signString += `${key}=${data[key]}&`;
}
}
const accessToken = 'b7651bdc627048b2ab4ebac9724a29d2';
signString += `access_token=${accessToken}`;
const md5 = crypto.createHash('md5');
data.key_sign = md5.update(signString, 'utf8').digest('hex');
axios.post('https://pay.lcsw.cn/lcsw/pay/open/qrpay', data)
.then(response => {
qrcode.toFile(`./images/moneyimg/${paydata.moneyname}.png`, response.data.qr_url, {
errorCorrectionLevel: 'H',
type: 'png',
scale: 10,
}, function (error) {
if (error) {
console.error('生成二维码失败:', error);
} else {
console.log('二维码已生成');
fs.readFile(`./images/moneyimg/${paydata.moneyname}.png`, function (error, data) {
if (error) {
console.error('读取二维码失败:', error);
} else {
const base64Data = data.toString('base64');
res.send(base64Data);
fs.unlink(`./images/moneyimg/${paydata.moneyname}.png`, function (error) {
if (error) {
console.error('删除二维码失败:', error);
} else {
console.log('二维码已删除');
}
});
}
});
}
});
})
.catch(error => {
console.error(error);
});
友商支付-扫呗