1 Star 0 Fork 0

方跃明/node-wechat-pay

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

node-wechat

Wechat Pay v3 Node.js SDK.

Install

yarn add @axolo/node-wechat-pay

API

For more usage please issue.

constructor(config = {})

params

config required description
appId yes wechat pay appid
mchId yes wechat pay mchid
mchCert yes wehcat pay merchant certificate
mchCertKey yes wehcat pay merchant certificate private key
mchCertSn yes wechat pay merchant certificate serial number
apiV3Key yes wechat pay api v3 secret key
notifyUrl yes Wechat Pay Notify callback url
notifySuccess Wechat Pay Notify need response { code: 'SUCCESS' } event types
platformCert wehcat pay platform certificate
currency default is CNY
appType mp = miniprogram
http HTTP Client, default is built-in axios instance
error class of Error, default is WechatPayError
logger function of logger, default is console
cache default is {}, it is reserved

return

Object of WechatPay Node.js SDK instance.

http(config)

http client for request wechat pay API.

params

param required description
config yes config of axios

return

Promise of wechat pay result as axios response.

nonceStr()

return

String of nonce_str, random string.

timeStamp()

return

String of timestamp, unix timestamp second.

payRequest(payPackage, signType = 'RSA')

params

param required description
payPackage yes package of wechat pay, like prepay_id=***
signType signType of wechat pay, default is RSA

return

Object of wechat pay payment request

prop description
appId wehcat pay appid
timeStamp timestamp, seconds
nonceStr nonce string
package package of wechat pay, like prepay_id=***
paySign base64 signature
signType signType of wechat pay, like RSA

notify(data)

params

param required description
data yes Wechat Pay Notify request body

return

Object of Wechat Pay Notify decrypt resource with response suggestion.

prop description
resource decrytp resource
response response suggestion. like { code: 'SUCCESS' }

Example

const fs = require('fs');
const WechatPay = require('@axolo/node-wechat-pay');

const wechatPay = new WechatPay({
  appType: 'mp',
  appId: 'wechat_pay_appid',
  mchId: 'wechat_pay_mchid',
  mchCertSn: 'wechat_pay_mch_cert_serial_no',
  mchCertKey: fs.readFileSync('wehcat_pay_mch_cert_private_key.pem'),
  mchCert: fs.readFileSync('wehcat_pay_mch_cert.pem'),
  apiV3Key: 'wechat_pay_api_v3_secret',
  notifyUrl: 'https://url-of-wechat-pay-notify',
});

wechatPay.http.get('/v3/certificates').then(res => {
  wechatPay.logger.log(res.data);
}).catch(err => {
  wechatPay.logger.error(err);
});

Test

yarn test

TODO

  • support upload
  • test

Yueming Fang

MIT License Copyright (c) 2021 Yueming Fang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Wechat pay v3 SDK Node.js SDK. expand collapse
MIT
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/axolo/node-wechat-pay.git
git@gitee.com:axolo/node-wechat-pay.git
axolo
node-wechat-pay
node-wechat-pay
master

Search