合单下单
使用合单支付接口,用户只输入一次密码,即可完成多个订单的支付。目前最多一次可支持10笔订单进行合单支付。用合单下单api在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再按扫码、JSAPI、APP、H5等不同场景生成交易串调起支付。 官方合单支付文档
js
const { Formatter, Hash } = require('wechatpay-axios-plugin')
// 合单 NATIVE 支付场景
wxpay.v2.pay.combinedorder.post({
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign_type,
combine_out_trade_no,
spbill_create_ip,
time_start,
time_expire,
notify_url,
trade_type: 'NATIVE',
product_id,
sub_order_list,
})
.then(
({
data: {
return_code,
return_msg,
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign,
result_code,
err_code,
err_code_des,
trade_type,
code_url,
},
}) => ({
code_url,
})
)
// 合单 JSAPI 支付场景
wxpay.v2.pay.combinedorder.post({
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign_type,
combine_out_trade_no,
spbill_create_ip,
time_start,
time_expire,
notify_url,
trade_type: 'JSAPI',
combine_openid,
sub_order_list,
})
.then(
({
data: {
return_code,
return_msg,
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign,
result_code,
err_code,
err_code_des,
trade_type,
prepay_id,
},
}) => {
const nonceStr = Formatter.nonce();
const timeStamp = '' + Formatter.timestamp();
const packageStr = 'prepay_id=' + prepay_id;
const signType = previousSignType;
return {
appId,
timeStamp,
nonceStr,
package: packageStr,
signType,
paySign: Hash.sign(
signType,
{ appId, timeStamp, nonceStr, package: packageStr, signType },
apiv2Secret
)
}
}
)
// 合单 APP 支付场景
wxpay.v2.pay.combinedorder.post({
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign_type,
combine_out_trade_no,
spbill_create_ip,
time_start,
time_expire,
notify_url,
trade_type: 'APP',
scene_info,
sub_order_list,
})
.then(
({
data: {
return_code,
return_msg,
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign,
result_code,
err_code,
err_code_des,
trade_type,
prepay_id: prepayid,
},
}) => {
const noncestr = Formatter.nonce();
const timestamp = '' + Formatter.timestamp();
const packageStr = 'Sign=WXPay';
const signType = previousSignType || 'MD5';
return {
appid,
partnerid,
prepayid,
package: packageStr,
timestamp,
noncestr,
sign: Hash.sign(
signType,
{ appid, partnerid, prepayid, package: packageStr, timestamp, noncestr },
apiv2Secret
)
}
}
)
// 合单 MWEB 支付场景
wxpay.v2.pay.combinedorder.post({
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign_type,
combine_out_trade_no,
spbill_create_ip,
time_start,
time_expire,
notify_url,
trade_type: 'MWEB',
scene_info,
sub_order_list,
})
.then(
({
data: {
return_code,
return_msg,
combine_appid,
combine_mch_id,
device_info,
nonce_str,
sign,
result_code,
err_code,
err_code_des,
trade_type,
mweb_url,
},
}) => ({
mweb_url,
})
)