公众账号ID
仿真模式开关
密钥
测试用验签密钥
商户号
证书
拼接路径
签约,解约结果通知
router.post("/wechatpay/notify/contract", (req, res) => {
getXMLBody(req, options).then(data => {
pay
.contractNotify(data, async parsedData => {
if (!pay.verifySign(parsedData)) {
// 签名校验失败
}
if (parsedData.result_code === "FAIL") {
// 业务逻辑失败
}
// ...
return {
return_code: "SUCCESS",
return_msg: "OK"
};
})
.then(returnData => {
res.set("Content-Type", "application/xml; charset=utf-8");
res.end(returnData);
});
});
});
支付中签约
pay.contractOrder({
contract_mchid: "1223816102",
contract_appid: "wx426a3015555a46be",
out_trade_no: "1217752501201407033233368018",
body: "腾讯充值中心-QQ会员充值",
notify_url: "https://example.com/wechatpay/notify",
total_fee: 888,
spbill_create_ip: "8.8.8.8",
plan_id: 12535,
contract_code: "100000",
request_serial: 1000,
contract_display_account: "微信代扣",
contract_notify_url: "https://example.com/wechatpay/pap/notify"
});
生成 FetchOptions 数据
申请解约
pay.deleteContract({
contract_id: "120061098828009406",
contract_termination_remark: "解约原因"
});
pay.deleteContract({
plan_id: "123",
contract_code: "1023658866",
contract_termination_remark: "解约原因"
});
下载对账单
pay.downloadBill({
bill_date: "20140603",
bill_type: "ALL"
})
纯签约
pay.entrust({
plan_id: "12535",
contract_code: "100000",
request_serial: 1000,
contract_display_account: "微信代扣",
notify_url: "https://example.com/wechatpay/notify/contract"
});
获取私钥
查询订单
pay.papOrderQuery({
transaction_id: '1009660380201506130728806387'
})
pay.papOrderQuery({
out_trade_no: '120061098828009406'
})
申请扣款
pay.papPayApply({
body: "水电代扣",
out_trade_no: "1217752501201407033233368018",
total_fee: 888,
spbill_create_ip: "8.8.8.8",
notify_url: "https://example.com/wechatpay/pap/notify",
contract_id: "Wx15463511252015071056489715"
});
扣款结果通知
router.post("/wechatpay/notify/refund", (req, res) => {
getXMLBody(req, options).then(data => {
pay
.papPayNotify(data, async parsedData => {
if (!pay.verifySign(parsedData)) {
// 签名校验失败
}
if (parsedData.result_code === "FAIL") {
// 业务逻辑失败
}
// ...
return {
return_code: "SUCCESS",
return_msg: "OK"
};
})
.then(returnData => {
res.set("Content-Type", "application/xml; charset=utf-8");
res.end(returnData);
});
});
});
查询签约关系
pay.queryContract({
contract_id: "120061098828009406"
});
pay.queryContract({
plan_id: 123,
contract_code: "1023658866"
});
申请退款
pay.refund({
out_trade_no: '1217752501201407033233368018',
out_refund_no: '1217752501201407033233368019',
total_fee: 100,
refund_fee: 80
})
查询退款
pay.refundQuery({
transaction_id: '1009660380201506130728806387'
})
pay.refundQuery({
out_trade_no: '120061098828009406'
})
仿真模式开关
校验 sign
Generated using TypeDoc
APP签约
const pay = new AppEntrust({ appId: "wxb80e5bddb2d804f3", key: "6Q9VX4N3WTBM9G9XBL7H1L9PB9ANHLY7", mchId: "1434712502", pfx: fs.readFileSync(path.resolve(__dirname, "cert.p12")) });
https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_1&index=1