Gathering detailed insights and metrics for yp-wx-payment
Gathering detailed insights and metrics for yp-wx-payment
Gathering detailed insights and metrics for yp-wx-payment
Gathering detailed insights and metrics for yp-wx-payment
npm install yp-wx-payment
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
中间件
- 支付结果通知, 退款结果通知获取前端支付参数
- 支持JSSDK, WeixinJSBridge, 小程序, APP微信支付
刷卡支付
扫码支付
微信红包
企业付款
微信对帐单下载
- 支持数据格式化nodejs >= 8.3.0
因涉及金额等敏感问题, API和中间件并没有对数据字段做类型转换
微信返回值XML做JSON转换之后的字段均为字符串类型, 请自行转换后再进行数据运算
'1' + 0 = '10'
微信支付中传入的金额单位为分
API和中间件均对所有错误进行了处理, 统一通过error返回, 包括:
网络类错误
- 网络中断, 连接超时等微信返回值检验错误
- 微信返回值非法(伪造请求等, 可能性非常低)业务逻辑错误
- 订单重复, 退款金额大于支付金额等其它错误
- 应传参数未传入等未出错时正常返回为JSON格式数据
downloadBill
下载对帐单, 返回值为字符串文本1npm i tenpay 2 3# 如已安装旧版, 重新安装最新版 4npm i tenpay@latest
1const tenpay = require('tenpay'); 2const config = { 3 appid: '公众号ID', 4 mchid: '微信商户号', 5 partnerKey: '微信支付安全密钥', 6 pfx: require('fs').readFileSync('证书文件路径'), 7 notify_url: '支付回调网址', 8 spbill_create_ip: 'IP地址' 9}; 10const api = new tenpay(config); 11 12// init调用: 用于多帐号省略new关键字, tenpay.init(config)返回一个新的实例对象 13await tenpay.init(config).some_api();
appid
- 公众号ID(必填)mchid
- 微信商户号(必填)partnerKey
- 微信支付安全密钥(必填, 在微信商户管理界面获取)pfx
- 证书文件(选填, 在微信商户管理界面获取)
notify_url
- 支付结果通知回调地址(选填)
spbill_create_ip
- IP地址(选填)
127.0.0.1
pay<支付结果通知, 默认>
refund<退款结果通知>
nativePay<扫码支付模式一回调>
1app.use(bodyParser.text({type: '*/xml'})); 2 3router.post('/xxx', api.middlewareForExpress('pay'), (req, res) => { 4 let info = req.weixin; 5 6 // 业务逻辑... 7 8 // 回复成功消息 9 res.reply(); 10 // 回复错误消息 11 // res.reply('错误信息'); 12});
1app.use(bodyParser({ 2 enableTypes: ['json', 'form', 'text'], 3 extendTypes: { 4 text: ['text/xml', 'application/xml'] 5 } 6})); 7 8router.post('/xxx', api.middleware('refund'), async ctx => { 9 let info = ctx.request.weixin; 10 11 // 业务逻辑... 12 13 // 回复成功消息 14 ctx.reply(); 15 // 回复错误消息 16 // ctx.reply('错误信息'); 17});
appid
mchid
1let result = await api.getPayParams({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: 100, 5 openid: '付款用户的openid' 6});
trade_type
- JSAPI1// 该方法需先调用api.unifiedOrder统一下单, 获取prepay_id; 2let result = await api.getPayParamsByPrepay({ 3 prepay_id: '预支付会话标识' 4});
1let result = await api.getAppParams({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: 100 5});
trade_type
- APP1// 该方法需先调用api.unifiedOrder统一下单<注意传入trade_type: 'APP'>, 获取prepay_id; 2let result = await api.getAppParamsByPrepay({ 3 prepay_id: '预支付会话标识' 4});
1let result = await api.micropay({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: 100, 5 auth_code: '1234567890123' 6});
1let result = await api.unifiedOrder({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: 100, 5 openid: '用户openid' 6});
trade_type
- JSAPInotify_url
- 默认为初始化时传入的值或空spbill_create_ip
- 默认为初始化时传入的值或127.0.0.1
1let result = await api.orderQuery({ 2 // transaction_id, out_trade_no 二选一 3 // transaction_id: '微信的订单号', 4 out_trade_no: '商户内部订单号' 5});
1let result = await api.reverse({ 2 // transaction_id, out_trade_no 二选一 3 // transaction_id: '微信的订单号', 4 out_trade_no: '商户内部订单号' 5});
1let result = await api.closeOrder({ 2 out_trade_no: '商户内部订单号' 3});
1let result = await api.refund({ 2 // transaction_id, out_trade_no 二选一 3 // transaction_id: '微信的订单号', 4 out_trade_no: '商户内部订单号', 5 out_refund_no: '商户内部退款单号', 6 total_fee: 100, 7 refund_fee: 100 8});
op_user_id
- 默认为商户号(此字段在小程序支付文档中出现)1let result = await api.refundQuery({ 2 // 以下参数 四选一 3 // transaction_id: '微信的订单号', 4 // out_trade_no: '商户内部订单号', 5 // out_refund_no: '商户内部退款单号', 6 refund_id: '微信退款单号' 7});
1/** 2 * 新增一个format参数(默认: false), 用于自动转化帐单为json格式 3 * json.total_title: 统计数据的标题数组 - ["总交易单数","总交易额","总退款金额", ...], 4 * json.total_data: 统计数据的数组 - ["3", "88.00", "0.00", ...], 5 * json.list_title: 详细数据的标题数组 - ["交易时间","公众账号ID","商户号", ...], 6 * json.list_data: 详细数据的二维数据 - [["2017-12-26 19:20:39","wx12345", "12345", ...], ...] 7 */ 8let result = await api.downloadBill({ 9 bill_date: '账单的日期' 10}, true);
bill_type
- ALLformat
- false1let result = await api.transfers({ 2 partner_trade_no: '商户内部付款订单号', 3 openid: '用户openid', 4 re_user_name: '用户真实姓名', 5 amount: 100, 6 desc: '企业付款描述信息' 7});
check_name
- OPTION_CHECKspbill_create_ip
- 默认为初始化时传入的值或127.0.0.1
1let result = await api.transfersQuery({ 2 partner_trade_no: '商户内部付款订单号' 3});
1let result = await api.sendRedpack({ 2 // mch_billno, mch_autono 二选一 3 // mch_billno: '商户内部付款订单号', 4 mch_autono: '10位当日唯一数字', 5 send_name: '商户名称', 6 re_openid: '用户openid', 7 total_amount: <付款金额(分)>, 8 wishing: '红包祝福语', 9 act_name: '活动名称', 10 remark: '备注信息' 11});
mch_billno
- 商户内部订单号(传入则mch_autono失效)mch_autono
- 当日10位唯一数字, 用于自动处理商户内部订单号逻辑total_num
- 1client_ip
- 默认为初始化时的spbill_create_ip参数值或127.0.0.1
scene_id
- 空, 当红包金额大于2元
时必传(微信文档说明为200元, 实测为2元)1let result = await api.sendGroupRedpack({ 2 // mch_billno, mch_autono 二选一 3 // mch_billno: '商户内部付款订单号', 4 mch_autono: '10位当日唯一数字', 5 send_name: '商户名称', 6 re_openid: '种子用户openid', 7 total_amount: <付款金额(分)>, 8 wishing: '红包祝福语', 9 act_name: '活动名称', 10 remark: '备注信息' 11});
mch_billno
- 商户内部订单号(传入则mch_autono失效)mch_autono
- 当日10位唯一数字, 用于自动处理商户内部订单号逻辑total_num
- 3, 分裂红包要求值为3~20之间amt_type
- ALL_RANDscene_id
- 空, 当红包金额大于2元
时必传(文档中未说明)1api.redpackQuery({ 2 mch_billno: '商户内部付款订单号' 3});
bill_type
- MCHTNo vulnerabilities found.
No security vulnerabilities found.