xtx-wechat
wechat payment, oauth for nodejs
Last updated a year ago by achilles.ye .
ISC · Repository · Bugs · Original npm · Tarball
$ cnpm install xtx-wechat 
SYNC missed versions from official npm registry.

xtx-wechat

参考资料

构造支付函数

  const WxPay = require('WxPay');

  let wxpay = new WxPay({
    appid: 'appid',
    mch_id: 'mch_id',
    key: 'key',
    notify_url: 'notify_url',
    //设置商户证书 (退款需要)
    apiclient_key: 'apiclient_key',
    apiclient_cert: 'apiclient_cert'

  }, function* (ticket) {
    //缓存ticket jssdk 支付
  }, function* (openid) {
    //获取ticket
  });

创建订单( 统一下单)

  let result = yield wxpay.createUnifiedOrder({
    body: 'body',
    total_fee: 1,
    out_trade_no: 'out_trade_no'
  });

微信用户认证

  const OAuth = require('OAuth');

  let wechat_oauth = new OAuth({
      appid: 'appid',
      secret: 'secret'
    },
    function* (openid, data) {
      //access_token 缓存
    },
    function* (openid) {
      //从缓存中获取 access_token
    },
    function* (data) {
      //公众号 access_token 缓存
    },
    function* () {
      //从缓存中获取公众号 access_token
    });

  //获取code
  let url = wechat_oauth.getOAuthorizeURL(redirect_uri);
  //根据code 获取token
  wechat_oauth.getAccessToken(code);
  //刷新token
  wechat_oauth.refreshAccessToken(refresh_access_token);

h5 页面调用支付 (jssdk)

//获取公众可token
let public_token = yield wechat_oauth.getPublicAccessToken();
//获取ticket
let result_ticket = yield wxpay.getTicket(public_token.access_token);
//公共配置参数
let config = yield wxpay.getConfig(url, result_ticket.ticket);
//创建支付订单
let order = yield wxpay.createUnifiedOrder({
  out_trade_no: 'out_trade_no',
  body: '测试支付',
  trade_type: 'JSAPI',
  total_fee: 1
});
//支付配置参数
let wx_choose_pay = yield wxpay.chooseWXPay(order.xml.prepay_id);

订单管理

//订单查询
yield wxpay.orderquery(out_trade_no);
//关闭订单
yield wxpay.closeorder(out_trade_no);
//退款
yield wxpay.refund(out_trade_no);
//退款查询
yield wxpay.refundquery(out_trade_no);
//回调签名验证
yield wxpay.verifySign(return_body, sign);
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |