Gathering detailed insights and metrics for tenpay-mr
Gathering detailed insights and metrics for tenpay-mr
Gathering detailed insights and metrics for tenpay-mr
Gathering detailed insights and metrics for tenpay-mr
npm install tenpay-mr
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.2
Supply Chain
97.1
Quality
72.6
Maintenance
50
Vulnerability
98.9
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,109 Stars
180 Commits
191 Forks
29 Watchers
1 Branches
4 Contributors
Updated on Jun 23, 2025
Latest Version
2.1.20
Package Id
tenpay-mr@2.1.20
Unpacked Size
47.03 kB
Size
11.77 kB
File Count
9
NPM Version
8.19.2
Node Version
18.12.1
Published on
Feb 18, 2023
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
通知类中间件
- 支付结果通知, 退款结果通知前端支付支持
- 支持JSAPI, WeixinJSBridge, 小程序, APP, H5支付模式支持
- 付款码/公众号/小程序/APP/H5/扫码支付支付工具支持
- 微信红包, 企业付款(支持付款到零钱和银行卡)营销功能支持
- 微信代金券对帐账单支持
- 支持微信对帐单, 微信资金帐单服务商模式支持
- 所有api均可自行传入sub_appid, sub_mch_id微信支付仿真测试系统
- 支持沙盒模式, 用于完成支付验收流程QQ群:157964097,使用疑问,开发,贡献代码请加群。
nodejs >= 8.3.0
因涉及金额等敏感问题, API和中间件并没有对数据字段做类型转换
微信返回值XML做JSON转换之后的字段均为字符串类型, 请自行转换后再进行数据运算
'1' + 0 = '10'
微信支付中传入的金额单位为分
API和中间件均对所有错误进行了处理, 统一通过error返回, 包括:
网络类错误
- 网络中断, 连接超时等微信返回值检验错误
- 微信返回值非法(伪造请求等, 可能性非常低)业务逻辑错误
- 订单重复, 退款金额大于支付金额等其它错误
- 应传参数未传入等未出错时正常返回为JSON格式数据
downloadBill
和downloadFundflow
下载的帐单返回值为字符串文本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 certificate: {key: 'string', cert: 'string'} //选填,certificate比pfx优先 10}; 11// 方式一 12const api = new tenpay(config); 13// 方式二 14const api = tenpay.init(config); 15 16// 调试模式(传入第二个参数为true, 可在控制台输出数据) 17const api = new tenpay(config, true); 18 19// 沙盒模式(用于微信支付验收) 20const sandboxAPI = await tenpay.sandbox(config);
appid
- 公众号ID(必填)mchid
- 微信商户号(必填)partnerKey
- 微信支付安全密钥(必填, 在微信商户管理界面获取)certificate
- 证书文件(选填, 在微信商户管理界面获取, 优先级比pfx高)
pfx
- 证书文件(选填, 在微信商户管理界面获取)
notify_url
- 支付结果通知回调地址(选填)
refund_url
- 退款结果通知回调地址(选填)
spbill_create_ip
- IP地址(选填)
127.0.0.1
pay<支付结果通知, 默认>
refund<退款结果通知>
nativePay<扫码支付模式一回调>
1app.use(bodyParser.text({type: '*/xml'})); 2 3// 支付结果通知/退款结果通知 4router.post('/xxx', api.middlewareForExpress('pay'), (req, res) => { 5 let info = req.weixin; 6 7 // 业务逻辑... 8 9 // 回复消息(参数为空回复成功, 传值则为错误消息) 10 res.reply('错误消息' || ''); 11}); 12 13// 扫码支付模式一回调 14router.post('/xxx', api.middlewareForExpress('nativePay'), (req, res) => { 15 let info = req.weixin; 16 17 // 业务逻辑和统一下单获取prepay_id... 18 19 // 响应成功或失败(第二个可选参数为输出错误信息) 20 res.replyNative(prepay_id, err_msg); 21});
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 // 扫码支付模式一模式 17 ctx.replyNative(prepay_id); 18});
appid
mchid
1let result = await api.getPayParams({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: '订单金额(分)', 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: '订单金额(分)' 5});
trade_type
- APP1// 该方法需先调用api.unifiedOrder统一下单<注意传入trade_type: 'APP'>, 获取prepay_id; 2let result = await api.getAppParamsByPrepay({ 3 prepay_id: '预支付会话标识' 4});
1let result = await api.getNativeUrl({ 2 product_id: '商品ID' 3});
1// 使用统一下单API可直接获取code_url, 需自行生成二维码图片 2let {prepay_id, code_url} = await api.unifiedOrder({ 3 out_trade_no: '商户内部订单号', 4 body: '商品简单描述', 5 total_fee: '订单金额(分)', 6 openid: '用户openid', 7 trade_type: 'NATIVE', 8 product_id: '商品id' 9});
1let result = await api.micropay({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: '订单金额(分)', 5 auth_code: '授权码' 6});
1let result = await api.unifiedOrder({ 2 out_trade_no: '商户内部订单号', 3 body: '商品简单描述', 4 total_fee: '订单金额(分)', 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: '订单金额(分)', 7 refund_fee: '退款金额(分)' 8});
op_user_id
- 默认为商户号(此字段在小程序支付文档中出现)notify_url
- 默认为初始化时传入的refund_url, 无此参数则使用商户后台配置的退款通知地址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
- false1/** 2 * 新增一个format参数(默认: false), 用于自动转化帐单为json格式 3 * json.total_title: 统计数据的标题数组 - ["资金流水总笔数","收入笔数","收入金额", ...], 4 * json.total_data: 统计数据的数组 - ["20.0", "17.0", "0.35", ...], 5 * json.list_title: 详细数据的标题数组 - ["记账时间","微信支付业务单号","资金流水单号", ...], 6 * json.list_data: 详细数据的二维数据 - [["2018-02-01 04:21:23","12345", "12345", ...], ...] 7 */ 8let result = await api.downloadFundflow({ 9 bill_date: '账单日期' 10}, true);
account_type
- Basicformat
- false1let result = await api.sendCoupon({ 2 coupon_stock_id: '代金券批次id', 3 partner_trade_no: '商户单据号', 4 openid: '用户openid' 5});
1let result = await api.queryCouponStock({ 2 coupon_stock_id: '代金券批次id' 3});
1let result = await api.queryCouponInfo({ 2 coupon_id: '代金券id', 3 openid: '用户openid', 4 stock_id: '批次号' 5});
1let result = await api.transfers({ 2 partner_trade_no: '商户内部付款订单号', 3 openid: '用户openid', 4 re_user_name: '用户真实姓名', 5 amount: '付款金额(分)', 6 desc: '企业付款描述信息' 7});
check_name
- FORCE_CHECKspbill_create_ip
- 默认为初始化时传入的值或127.0.0.1
1let result = await api.transfersQuery({ 2 partner_trade_no: '商户内部付款订单号' 3});
1let result = await api.payBank({ 2 partner_trade_no: '商户内部付款订单号', 3 bank_code: '收款方开户行', 4 enc_bank_no: '收款方银行卡号', 5 enc_true_name: '收款方用户名', 6 amount: '付款金额(分)', 7 desc: '企业付款到银行卡描述信息' 8});
1let result = await api.queryBank({ 2 partner_trade_no: '商户内部付款订单号' 3});
1let result = await api.sendRedpack({ 2 // mch_billno, mch_autono 二选一 3 // mch_billno: '商户内部付款订单号', 4 mch_autono: '10位当日唯一数字, 用于自动生成mch_billno', 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位当日唯一数字, 用于自动生成mch_billno', 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.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More