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

ztsafe-wx

v1.0.23

Published

weixin

Downloads

6

Readme

主要功能介绍

微信模块

  1. 获取登录需要的openid
  2. 用户授权后,验证用户信息
  3. 获取access_token
  4. 生成普通带小程序logo的二维码
  5. 生成用户自定义logo的二维码
  6. 发送模板信息

服务端业务常用模块

  1. 服务端生成用户的token
  2. 服务端解析token,得到userid

使用说明

安装

npm install ztsafe-wx

全局引用

const {user,token,qrcode,message} = require('ztsafe-wx');

使用示例

getOpenid

功能介绍:获取用户唯一凭证的openid和session_key
参数介绍
js_code:前端调用wx.login传过来的
secret:小程序密钥
appid:小程序appid
使用示例:
user.getOpenid(
  {
    js_code: 'xxxxxxxxxxxxxx',
    secret: 'xxxxxxxxxxxxxx',
    appid: 'xxxxxxxxxxxxxxxxxxx'
  }
)
返回值:
  成功时返回:{
    openid:'xxxxxxxxxxxxxxx',
    session_key:'xxxxxxxxxxxxxx'
  }
  失败时返回:null

checkUser

功能介绍:用户授权后,验证用户信息
参数介绍
  session_key:'xxxxxxxxxxxx'  //会话密钥 session_key,在getOpenid中可获得,建议保存
  rawData:'xxxxxxxxxxxxxx',
  encryptedData:'xxxxxxxxxx'
  iv:'xxxxxxxxxxxx'      // rawData,encryptedData,iv均由前端传给服务端
  appid:小程序appid
  使用示例:
  user.checkUser(
    {
      session_key: 'xxxxxxxxxxxxxx',
      rawData: 'xxxxxxxxxxxxxx',
      encryptedData: 'xxxxxxxxxxxxxxxxxxx',
      iv:'xxxxxxxxxxxxxxxxxxx',
      appid:小程序appid
    }
  )
返回值:
  成功时返回:1
  失败时返回:0

getAccessToken

功能介绍:获取access_token
使用示例:
token.getAccessToken(appid,secret)
返回值:
  成功时返回:access_token
  失败时返回:null

sendTemplateMessage

功能介绍:定时发送模板信息
参数介绍
appid:小程序appid
secret:小程序密钥,
openid:用户openid,
template_id:模板id
page:打开推送跳转至的页面,
form_id:表单提交场景下,为 submit 事件带上的 formId,
data:模板内容
使用示例:
message.sendTemplateMessage(
  {
    appid:'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    secret:'xxxxxxxxxxxxxxxx',
    openid:'xxxxxxxxxxxxxxxxxxxxxxxxxx',
    template_id:'xxxxxxxxxxxxxx',
    page:'xxxxxxxxxxxxx',
    form_id:'xxxxxxxxxxxxx',
    data:{
    }
  }
)

getWxacode

功能介绍:生成普通的二维码
参数介绍:
page:跳转页面
scene:二维码需要携带的参数
width:二维码宽度
auto_color:是否自动配置线条颜色
line_color:二维码线条颜色
is_hyaline:二维码是否需要透明背景
imgDir:生成的二维码存方路径
fileName:生成的二维码文件名
使用示例:
qrcode.getWxacode{
  page:'pages/index',
  scene:'xxxxxxxxxxx',
  width:430,
  auto_color:false,
  line_color:{r:255,g:255,b:255},
  is_hyaline:false,
  imgDir:'xxxxxxxxxxxxx',
  fileName:'xxxx.png'
}

getUserWxacode

功能介绍:生成自定义logo的二维码
参数介绍:
srcImg:普通二维码文件路径
width:二维码宽度
logo:用户自定义的logo
使用示例:
qrcode.getUserWxacode{
  srcImg:'image/qrcode.png',
  width:430,
  logo:'image/logo.png'
}