npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xtx-wechat

v1.1.1

Published

wechat payment, oauth for nodejs

Downloads

6

Readme

xtx-wechat

参考资料

  • 集成微信支付,用户认证,h5 页面支付功能 for nodejs
  • https://github.com/JasonBoy/wechat-jssdk/blob/master/test/JSSDK.test.js
  • https://github.com/perzy/co-wechat-payment
  • https://pay.weixin.qq.com/wiki/doc/api/jsapi.php
  • http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html

构造支付函数

  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);