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

miniprogram-authorize-x

v1.0.2

Published

微信小程序授权组件

Downloads

2

Readme

小程序授权管理组件

开发背景:小程序1.3.0之后版本,需要用户主动点击按钮触发授权弹框; 详情查看官方文档 实现策略:在页面添加此组件,会在用户未授权的状态下自动显示,已授权则不会显示

NPM

npm install miniprogram-authorize-x -save

// 注:并在开发者工具中,选择工具 => 构建npm

Example

// 在.json内
"usingComponents": {
  "authorize": "miniprogram-authorize-x"
}

// 在.wxml内
<view>
    <authorize apiUrl="{{apiUrl}}" getUnionid="{{getUnionid}}" bind:authorizeSuccessCFn="authorizeSuccessPFn" bind:authorizeFailCFn="authorizeFailPFn"></authorize>
</view>

// 在.js内
Page({
     data: {
       apiUrl: "https://1v1-activity.xueba100.com/onebook/code",
       getUnionid: true,
       // 用户先前授权过,可以直接从storage获取
       userInfo: wx.getStorageSync('userInfo'), // 用户数据,包含昵称、图像、城市等
       hasUserInfo: wx.getStorageSync('hasUserInfo'), // 类型:Boolean, 用户授权状态,此状态同 userInfo 一样,一旦获取永久保存于storage内
       openid: wx.getStorageSync('openid'),
       unionid: wx.getStorageSync('unionid')
     },
     // 授权成功回调函数
     authorizeSuccessPFn: function () {
       this.setData({
         userInfo: wx.getStorageSync('userInfo'),
         hasUserInfo: wx.getStorageSync('hasUserInfo'),
         openid: wx.getStorageSync('openid'),
         unionid: wx.getStorageSync('unionid')
       });
       console.log('success')
     },
     // 授权失败回调函数
     authorizeFailPFn: function () {
       console.log('fail')
     }
   });

Api

参数

| Name | Type | Default | Description | |-----------------------------|-------------|--------------|--------------------------------------------------------------------| | apiUrl | String | | 获取openid或者unionid接口地址,注意:getUnionid必须为true才可以 | | getUnionid | Boolean | false | 是否需要获取openid 或者 unionid,注意:apiUrl必须为true才可以 | | authorizeSuccessCFn | Function | | 授权成功回调 | | authorizeFailCFn | Function | | 授权失败回调 |

其他说明

1、微信小程序获取openid 不需要用户授权,wx.login获取code之后,可以直接去腾讯服务器换取openid; 2、微信小程序获取unionid 需要用户授权,授权之后获取 密钥encryptedData 和 iv,然后去腾讯服务器换取 unionid; 3、获取图像、昵称、城市、性别之类数据,授权即可拿到,无需再去腾讯服务器获取