Gathering detailed insights and metrics for weixin-pay
Gathering detailed insights and metrics for weixin-pay
npm install weixin-pay
Typescript
Module System
Node Version
NPM Version
66.9
Supply Chain
90.8
Quality
71.2
Maintenance
50
Vulnerability
97.3
License
JavaScript (100%)
Total Downloads
43,360
Last Day
5
Last Week
39
Last Month
171
Last Year
1,889
920 Stars
18 Commits
241 Forks
56 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
Last day
-28.6%
5
Compared to previous day
Last week
5.4%
39
Compared to previous week
Last month
-1.2%
171
Compared to previous month
Last year
-17.6%
1,889
Compared to previous year
微信支付 for node.js
npm install weixin-pay
创建统一支付订单
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});
提供一个生成支付二维码链接的函数,把url生成二维码给用户扫。
1var url = wxpay.createMerchantPrepayUrl({ product_id: '123456' });
商户后台收到微信的回调之后,调用 createUnifiedOrder() 生成预支付交易单,将结果的XML数据返回给微信。
直接调用 createUnifiedOrder() 函数生成预支付交易单,将结果中的 code_url 生成二维码给用户扫。
生成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
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
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-06
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