Gathering detailed insights and metrics for yl-wechat-pay
Gathering detailed insights and metrics for yl-wechat-pay
npm install yl-wechat-pay
Typescript
Module System
Node Version
NPM Version
68.2
Supply Chain
91.2
Quality
71.3
Maintenance
50
Vulnerability
97.3
License
Total Downloads
1,574
Last Day
1
Last Week
2
Last Month
9
Last Year
111
Minified
Minified + Gzipped
Latest Version
1.0.5
Package Id
yl-wechat-pay@1.0.5
Unpacked Size
17.07 kB
Size
6.49 kB
File Count
5
NPM Version
5.0.3
Node Version
8.1.3
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-66.7%
2
Compared to previous week
Last month
0%
9
Compared to previous month
Last year
-29.3%
111
Compared to previous year
5
南宁引力互动科技 微信支付 for Nodejs
1var Payment = require('wechat-pay').Payment; 2var initConfig = { 3 partnerKey: "<partnerkey>", 4 appId: "<appid>", 5 mchId: "<mchid>", 6 notifyUrl: "<notifyurl>", 7 pfx: fs.readFileSync("<location-of-your-apiclient-cert.p12>") 8}; 9var payment = new Payment(initConfig);
所有参数都不是必须的,不过这样配置最省事。实际调用时候的参数若有同名会覆盖。
1var order = { 2 body: '吮指原味鸡 * 1', 3 attach: '{"部位":"三角"}', 4 out_trade_no: 'kfc' + (+new Date), 5 total_fee: 10 * 100, 6 spbill_create_ip: req.ip, 7 openid: req.user.openid, 8 trade_type: 'JSAPI' 9}; 10 11payment.getBrandWCPayRequestParams(order, function(err, payargs){ 12 res.json(payargs); 13});
注:
支付授权目录
下前端通过
1WeixinJSBridge.invoke('getBrandWCPayRequest', payargs, function(res){ 2 if(res.err_msg == "get_brand_wcpay_request:ok"){ 3 alert("支付成功"); 4 // 这里可以跳转到订单完成页面向用户展示 5 }else{ 6 alert("支付失败,请重试"); 7 } 8});
来呼出微信的支付界面
1var middleware = require('wechat-pay').middleware; 2app.use('<notifyUrl>', middleware(initConfig).getNotify().done(function(message, req, res, next) { 3 var openid = message.openid; 4 var order_id = message.out_trade_no; 5 var attach = {}; 6 try{ 7 attach = JSON.parse(message.attach); 8 }catch(e){} 9 10 /** 11 * 查询订单,在自己系统里把订单标为已处理 12 * 如果订单之前已经处理过了直接返回成功 13 */ 14 res.reply('success'); 15 16 /** 17 * 有错误返回错误,不然微信会在一段时间里以一定频次请求你 18 * res.reply(new Error('...')) 19 */ 20}));
1payment.refund({ 2 out_trade_no: "kfc001", 3 out_refund_no: 'kfc001_refund', 4 total_fee: 10 * 100, 5 refund_fee: 10 * 100 6}, function(err, result){ 7 /** 8 * 微信收到正确的请求后会给用户退款提醒 9 * 这里一般不用处理,有需要的话有err的时候记录一下以便排查 10 */ 11});
1payment.downloadBill({ 2 bill_date: "20140913", 3 bill_type: "ALL" 4}, function(err, data){ 5 // 账单列表 6 var list = data.list; 7 // 账单统计信息 8 var stat = data.stat; 9});
在回调的Error上的以name做了区分,有需要可以拿来做判断
No vulnerabilities found.
No security vulnerabilities found.