Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加企业支付支持 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
```
34 changes: 28 additions & 6 deletions lib/wxpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var md5 = require('MD5');
exports = module.exports = WXPay;

function WXPay() {

if (!(this instanceof WXPay)) {
return new WXPay(arguments[0]);
};
Expand All @@ -16,7 +16,7 @@ function WXPay() {
};

WXPay.mix = function(){

switch (arguments.length) {
case 1:
var obj = arguments[0];
Expand Down Expand Up @@ -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:'缺少参数' });
}

Expand Down Expand Up @@ -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:'缺少参数' });
}

Expand All @@ -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);
});
});