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

@rexerwang/wechat-sdk

v0.1.6

Published

Manager Wechat(Weixin) jssdk, wrapper of offical sdk library. Provide vue/nuxt plugin for easy use.

Downloads

21

Readme

Manager Wechat(Weixin) jssdk, wrapper of offical sdk library. Provide vue/nuxt plugin for easy use.

Install

npm i @rexerwang/wechat-sdk
yarn add @rexerwang/wechat-sdk

Intro

为了方便的使用和管理微信JSSDK,针对jsapi(wx)做轻量封装。 提供SDKManager对官方库(jweixin.js)按版本号异步加载,可方便切换和升级SDK版本。并提供多个CDN源,方便加载失败后fallback。

针对接口调用,提供Promisify和正常方式两种方法:

  • Promisify: SDKManager.invoke(api, args)
  • 正常方式: SDKManager.invokeStrict(api, args)

针对异常,提供WechatError统一异常类管理wechat/error.js,额外包含code错误状态码,res微信接口返回数据。

针对微信分享,提供SDKManager.setupShareData,对新老版本接口做兼容处理,可放心使用(优先使用老版本接口)。

Usage

options

配置项见:wechat/options.js

// 1. 获取(只读)
console.log(SDKManager.options)

// 2. 更新(merge操作)
SDKManager.options = customOptions

// 3. 指定JSDK版本
SDKManger.options = { version:'1.4.0' }

初始化

  1. wechat.require(version?)
  2. wechat.config(config, jsApiList?)

调用接口

const wechat = new SDKManager()

// 异步方式调用(Promisify)
wechat.invoke('api_name', api_args)
  .then(res => {
    // 调用成功
  })
  .catch(error => {
    // 调用失败,或用户取消

    // 用户取消
    if(error.code === WechatError.ERR_CANCELLED) {
      // error.res
    }

    // 调用失败
    else if(error.code === WechatError.ERR_FAILURE) {
      // error.message
    }

    // 其他错误
    // WechatError.ERR_SDK_MISS 缺失JSSDK
    // WechatError.ERR_SDK_INACTIVE JSSDK未注册
    // WechatError.ERR_API_INACTIVE 接口未注册
    // ...

  })


// 正常方式
wechat.invokeStrict('api_name', {
  ...api_args,
  susscess(res){},
  cancel(res){},
  fail(rs){},
})

另外,提供常用接口别名方法(alias):

  • 显示所有非基础按钮: wechat.showAllNonBaseMenuItem
  • 隐藏所有非基础按钮: wechat.hideAllNonBaseMenuItem
  • 自定义“分享给朋友”及“分享到QQ”按钮的分享内容(1.4.0): wechat.updateAppMessageShareData
  • 自定义“分享到朋友圈”及“分享到QQ空间”按钮的分享内容(1.4.0): wechat.updateTimelineShareData
  • 获取“分享给朋友”按钮点击状态及自定义分享内容: wechat.onMenuShareAppMessage
  • 获取“分享到朋友圈”按钮点击状态及自定义分享内容: wechat.onMenuShareTimeline

其他方法

  • 统一配置微信分享信息(好友和朋友圈): wechat.setupShareData(config1, config2)
  • 仅显示微信分享相关菜单: wechat.showShareMenuOnly()
  • 检查SDK状态:wechat._checkSdkStatus()
  • 检查接口状态: wechat._checkApiStatus(api)

其他

WechatError

MenuItem