Installations
npm install weixin-pay
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
4.1.1
NPM Version
2.14.4
Score
66.9
Supply Chain
90.8
Quality
71.2
Maintenance
50
Vulnerability
97.3
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
tvrcgo
Download Statistics
Total Downloads
43,485
Last Day
8
Last Week
45
Last Month
164
Last Year
1,943
GitHub Statistics
920 Stars
18 Commits
241 Forks
56 Watching
2 Branches
1 Contributors
Bundle Size
828.77 kB
Minified
217.34 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.7
Package Id
weixin-pay@1.1.7
Size
5.01 kB
NPM Version
2.14.4
Node Version
4.1.1
Total Downloads
Cumulative downloads
Total Downloads
43,485
Last day
100%
8
Compared to previous day
Last week
80%
45
Compared to previous week
Last month
-1.2%
164
Compared to previous month
Last year
-14.1%
1,943
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
weixin-pay
微信支付 for node.js
Installation
npm install weixin-pay
Usage
创建统一支付订单
1var WXPay = require('weixin-pay'); 2 3var wxpay = WXPay({ 4 appid: 'xxxxxxxx', 5 mch_id: '1234567890', 6 partner_key: 'xxxxxxxxxxxxxxxxx', //微信商户平台API密钥 7 pfx: fs.readFileSync('./wxpay_cert.p12'), //微信商户平台证书 8}); 9 10wxpay.createUnifiedOrder({ 11 body: '扫码支付测试', 12 out_trade_no: '20140703'+Math.random().toString().substr(2, 10), 13 total_fee: 1, 14 spbill_create_ip: '192.168.2.210', 15 notify_url: 'http://wxpay_notify_url', 16 trade_type: 'NATIVE', 17 product_id: '1234567890' 18}, function(err, result){ 19 console.log(result); 20});
查询订单
1// 通过微信订单号查
2wxpay.queryOrder({ transaction_id:"xxxxxx" }, function(err, order){
3 console.log(order);
4});
5
6// 通过商户订单号查
7wxpay.queryOrder({ out_trade_no:"xxxxxx" }, function(err, order){
8 console.log(order);
9});
关闭订单
1wxpay.closeOrder({ out_trade_no:"xxxxxx"}, function(err, result){ 2 console.log(result); 3});
退款接口
1var params = { 2 appid: 'xxxxxxxx', 3 mch_id: '1234567890', 4 op_user_id: '商户号即可', 5 out_refund_no: '20140703'+Math.random().toString().substr(2, 10), 6 total_fee: '1', //原支付金额 7 refund_fee: '1', //退款金额 8 transaction_id: '微信订单号' 9}; 10 11wxpay.refund(params, function(err, result){ 12 console.log('refund', arguments); 13});
原生支付 (NATIVE)
模式一
提供一个生成支付二维码链接的函数,把url生成二维码给用户扫。
1var url = wxpay.createMerchantPrepayUrl({ product_id: '123456' });
商户后台收到微信的回调之后,调用 createUnifiedOrder() 生成预支付交易单,将结果的XML数据返回给微信。
模式二
直接调用 createUnifiedOrder() 函数生成预支付交易单,将结果中的 code_url 生成二维码给用户扫。
公众号支付 (JS API)
生成JS API支付参数,发给页面
1wxpay.getBrandWCPayRequestParams({ 2 openid: '微信用户 openid', 3 body: '公众号支付测试', 4 detail: '公众号支付测试', 5 out_trade_no: '20150331'+Math.random().toString().substr(2, 10), 6 total_fee: 1, 7 spbill_create_ip: '192.168.2.210', 8 notify_url: 'http://wxpay_notify_url' 9}, function(err, result){ 10 // in express 11 res.render('wxpay/jsapi', { payargs:result }) 12});
网页调用参数(以ejs为例)
1WeixinJSBridge.invoke( 2 "getBrandWCPayRequest", <%-JSON.stringify(payargs)%>, function(res){ 3 if(res.err_msg == "get_brand_wcpay_request:ok" ) { 4 // success 5 } 6});
中间件
商户服务端处理微信的回调(express为例)
1// 原生支付回调
2router.use('/wxpay/native/callback', wxpay.useWXCallback(function(msg, req, res, next){
3 // msg: 微信回调发送的数据
4}));
5
6// 支付结果异步通知
7router.use('/wxpay/notify', wxpay.useWXCallback(function(msg, req, res, next){
8 // 处理商户业务逻辑
9
10 // res.success() 向微信返回处理成功信息,res.fail()返回失败信息。
11 res.success();
12}));
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 1/17 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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3.5
/10
Last Scanned on 2025-01-13
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