From 6041ad9106123dfeec6d12b6b698fa9ea848a688 Mon Sep 17 00:00:00 2001 From: lext <937505373@qq.com> Date: Wed, 27 Apr 2016 10:13:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=81=E4=B8=9A=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 ++++++++++++++++ lib/wxpay.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d1d6c92..32630de 100644 --- a/README.md +++ b/README.md @@ -135,3 +135,19 @@ router.use('/wxpay/notify', wxpay.useWXCallback(function(msg, req, res, next){ res.success(); })); ``` + + +### 企业支付 + +```js +wxpay.transfer({ + partner_trade_no: '3123123123', // 订单号 + openid: 'openid', + amount: 100, // 分为单位 + desc: '描述', + spbill_create_ip: '192.168.2.210', // ip, + check_name: 'NO_CHECK', //默认为 NO_CHECK, 可不填 +}, function(err, result){ + console.log('transfer', arguments); +}); +``` diff --git a/lib/wxpay.js b/lib/wxpay.js index 969ac13..c2ff558 100644 --- a/lib/wxpay.js +++ b/lib/wxpay.js @@ -6,7 +6,7 @@ var md5 = require('MD5'); exports = module.exports = WXPay; function WXPay() { - + if (!(this instanceof WXPay)) { return new WXPay(arguments[0]); }; @@ -16,7 +16,7 @@ function WXPay() { }; WXPay.mix = function(){ - + switch (arguments.length) { case 1: var obj = arguments[0]; @@ -126,11 +126,11 @@ WXPay.mix('useWXCallback', function(fn){ }); }; }); - + WXPay.mix('queryOrder', function(query, fn){ - - if (!(query.transaction_id || query.out_trade_no)) { + + if (!(query.transaction_id || query.out_trade_no)) { fn(null, { return_code: 'FAIL', return_msg:'缺少参数' }); } @@ -169,7 +169,7 @@ WXPay.mix('closeOrder', function(order, fn){ WXPay.mix('refund',function(order, fn){ - if (!(order.transaction_id || order.out_refund_no)) { + if (!(order.transaction_id || order.out_refund_no)) { fn(null, { return_code: 'FAIL', return_msg:'缺少参数' }); } @@ -190,3 +190,25 @@ WXPay.mix('refund',function(order, fn){ }); }); + +WXPay.mix('transfer', function (opts, fn) { + opts.nonce_str = opts.nonce_str || util.generateNonceString(); + opts.check_name = opts.check_name || 'NO_CHECK'; + util.mix(opts, { + mch_appid: this.wxpayID.appid, + mchid: this.wxpayID.mch_id + }); + opts.sign = this.sign(opts); + + request({ + url: "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers", + method: 'POST', + body: util.buildXML(opts), + agentOptions: { + pfx: this.options.pfx, + passphrase: this.options.mch_id + } + }, function(err, response, body){ + util.parseXML(body, fn); + }); +});