Gathering detailed insights and metrics for @tg1518/weixin-pay
Gathering detailed insights and metrics for @tg1518/weixin-pay
npm install @tg1518/weixin-pay
Typescript
Module System
Node Version
NPM Version
64.1
Supply Chain
90.8
Quality
71.5
Maintenance
50
Vulnerability
97.3
License
JavaScript (100%)
Total Downloads
658
Last Day
1
Last Week
1
Last Month
7
Last Year
103
21 Commits
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.1.9
Package Id
@tg1518/weixin-pay@1.1.9
Unpacked Size
13.20 kB
Size
5.25 kB
File Count
12
NPM Version
8.19.2
Node Version
16.18.0
Publised On
07 Jul 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-75%
1
Compared to previous week
Last month
-36.4%
7
Compared to previous month
Last year
-69.5%
103
Compared to previous year
微信支付 for node.js
npm install @tg1518/weixin-pay
创建统一支付订单
1var WXPay = require('@tg1518/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.
No security vulnerabilities found.