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

miniapp3rd

v1.0.0-alpha18

Published

小程序第三方平台快速搭建模块

Downloads

4

Readme

小程序第三方平台插件

由于单平台拥有多使用方会造成混乱且主体限制,单独部署平台的成本又较高,权衡利弊,故转为采用插件化的形式对接。

引入插件

npm i miniapp3rd --save
import miniapp3rd, { Miniapp3rd, MiniappType } from 'miniapp3rd'

使用方法

初始化

miniapp3rd.init(options)

options 如下表格,详细的字段类型和方法参数及返回值可以查看类型声明。

| 选项 | 描述 | | --- | --- | | 微信小程序第三方平台配置 | | | WEMINIAPP.appId | APPID | | WEMINIAPP.appSecret | APPSECRET | | WEMINIAPP.messageToken | 消息校验Token | | WEMINIAPP.encodingAESKey | 消息加解密Key | | WEMINIAPP.oldEncodingAESKey | 消息加解密Key(旧),第一次填写时跟 encodingAESKey 填同一个值,后续消息加解密Key有更新时,把旧的填到该字段 | | 百度小程序第三方平台配置 | | | BDMINIAPP.clientOriginalId | id,数字字符串 | | BDMINIAPP.clientId | key | | BDMINIAPP.appSecret | secret | | BDMINIAPP.messageToken | 消息加解密Token | | BDMINIAPP.encodingAESKey | 消息加解密key | | BDMINIAPP.oldEncodingAESKey | 参照 WEMINIAPP.oldEncodingAESKey | | 下列 Register / Accessor 类方法的第一个参数均为 miniappType | | | ticketRegister | 票据注册器 | | ticketAccessor | 票据访问器,返回票据 | | accessTokenRegister | 令牌注册器 | | accessTokenAccessor | 令牌访问器,返回 { accessToken, expiresIn, updatedAt } | | authorizerAccessTokenRegister | 小程序接口调用令牌注册器 | | authorizerAccessTokenAccessor | 小程序接口调用令牌访问器 | | 其他 | | | logger | 日志,不传则不会打印日志,使用到的 Level:debug、info、warn、error、fatal |

实现接口

授权事件接收

第三方平台会通过你配置的授权事件接收 URL向你推送授权事件,收到请求先转送给插件处理:

miniapp3rd.oauth(miniappType: MiniappType, query: any, body: any)

如上,body 要提供未经处理的原始 body。如果是授权事件是票据推送类型,插件内部通过 ticketRegister 存储票据,方法不会返回什么东西,如果是小程序授权、取消授权、更新授权等类型,则会返回解密后的事件内容交给你去处理。

消息事件接收

第三方平台会通过你配置的消息与事件接收 URL向你推送消息和事件,收到请求先转送给插件处理:

miniapp3rd.message(miniappType: MiniappType, query: any, body: any, authorizerAppId?: AuthorizerAppId)

如上,body 要提供未经处理的原始 body,authorizerAppId 是微信小程序第三方平台必需的。插件处理后返回解密后的消息和事件内容交给你去处理。

授权

miniapp3rd.getAuthLogin(miniappType: MiniappType, redirectUri: string, authType: number | string = 3, bizAppId?: string)

redirectUri 是授权成功后,跳转到的页面,实际实现可以是一个接口去处理授权结果,处理完后展示 HTML 页面。百度小程序第三方平台只需要 redirectUri 参数。

注意:授权页需要从你配置的授权发起页域名上的页面进行跳转!

另外是微信独有的 getAuthBind,在移动端链接快速授权:

miniapp3rd.getAuthBind (miniappType: MiniappType, redirectUri: string, authType: number | string = 3, bizAppId?: string)

接口开发

获取小程序接口调用令牌:

miniapp3rd.getAuthorizerAccessToken(miniappType: MiniappType, authorizerAppId: AuthorizerAppId)

该方法会自动通过 authorizerAccessTokenAccessor 去获取小程序的接口调用令牌,如果过期则用 refreshToken 去刷新并通过 authorizerAccessTokenRegister 存回去。

手头有了小程序接口调用令牌,就可以去调用接口了:

miniapp3rd.weminiappOpenapi.request
miniapp3rd.bdminiappOpenapi.request

后续

后续可能会提供部分代开发接口的统一调用方法来代替调用 request。


this.ctx.request.rawBody

获取授权码的链接必须是配置里的授权发起页域名下的链接

收到 ticket 返回纯字符串 success