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

wx-sdk-promisify

v1.1.2

Published

weixin jssdk promisify

Downloads

8

Readme

wx-sdk-promisify

介绍

封装微信jssdk,让其支持promise,并且让每个方法在wx.ready之后再执行。

API

  • register
/**
 * 注册签名
 * @param {string} signatureUrl 获取微信签名的URL地址
 * @param {string} appid  企业号或公众号唯一标识
 * @param {array}  jsApiList 需要调用的API,如: jsApiList = ['getNetworkType', 'previewImage']
 * @param {bool}   debug    true: 微信会alert出API调用情况
 */
wx.register({signatureUrl, appid, jsApiList, debug: true })

/**
 * signatureUrl: 获取签名接口介绍 [get接口]
 * @return {json}
 * {
 *  code: 0, //  normal response
 *  errorMsg: '',
 *  data: {
 *      timestamp,  // 获取signature的timestamp
 *      nonceStr,   // 获取signature的noncestr
 *      signature,  // signature
 *  }
 * }
 */
  • wx 其他API正常调用,返回promise

使用方式

import wx from 'wx-sdk-promisify'
const domain = 'http://domain/signature'
const agentid = 1000001
const appid = 'testappid'
const url = location.href.split('#')[0]
const signatureUrl = `${domain}?appid=${appid}&agentid=${agentid}&url=${url}`
const jsApiList = ['getNetworkType', 'previewImage']
wx.register({signatureUrl, appid, jsApiList, debug: true })

const testWx = async () => {
  const {networkType} = await wx.getNetworkType()
  await wx.previewImage({current, urls})
}
textWx()

比较

  • example1
// before
wx.ready(function() {
  wx.getNetworkType({
      success: function (res) {
          var networkType = res.networkType; // 返回网络类型2g,3g,4g,wifi
          //...
      }
  });
})

// promisify
const {networkType} = await wx.getNetworkType()
  • example2
// before
wx.ready(function() {
  wx.previewImage({
    current: '', // 当前显示图片的http链接
    urls: [] // 需要预览的图片http链接列表
  });
})

// promisify
await wx.previewImage({current, urls})

Build Setup

  • develop: make dev
  • build: make build
  • publish: make publish

附录

微信开发文档

  • 公众号: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
  • 企业微信: https://work.weixin.qq.com/api/doc#10029

API list

其中注释掉的部分是微信官方 js-sdk 暂未支持的方法

  'checkJsApi',
  'openEnterpriseChat',
  'onMenuShareAppMessage',
  // 'onMenuShareWechat',
  'chooseImage',
  'uploadImage',
  'downloadImage',
  'stopRecord',
  'onVoicePlayEnd',
  'uploadVoice',
  'downloadVoice',
  'getNetworkType',
  'getLocation',
  'scanQRCode',
  'onVoiceRecordEnd',
  // 'selectEnterpriseContact',
  'startRecord',
  'playVoice',
  'pauseVoice',
  'stopVoice',
  'previewImage',
  // 'previewFile',
  'openLocation',
  // 'onHistoryBack',
  'hideOptionMenu',
  'showOptionMenu',
  'hideMenuItems',
  'showMenuItems',
  'hideAllNonBaseMenuItem',
  'showAllNonBaseMenuItem',
  'closeWindow',
  // 'chooseInvoice'