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

mp-sdk-rojer

v0.2.2

Published

微信小程序服务器端SDK。Wechat Mini Program (mp) Serverside SDK

Downloads

10

Readme

mp-sdk-rojer

比官方 SDK 更好用的微信小程序服务器端 SDK。

已经疯狂得不能用代码行数(总计89行,包含空行和 debug)来衡量该项目了,代码仅有 1,310字节(净化后)。

github npm npm npm

Minimum, Flexible, Scalable.

支持 Lazy Require。

安装使用

yarn add mp-sdk-rojer
# 或
npm i --save mp-sdk-rojer

基本使用示例

const sdk = require("mp-sdk-rojer");

const cloud = sdk("appid", "secret");

// appid、secret、access_token、grant_type 4个字段可以忽略不写
cloud.auth
  .code2Session({
    js_code: "js_code"
  })
  .then(result => {
    // code here
  });

二维码处理示例

const sdk = require("mp-sdk-rojer");
const fs = require("fs");

const cloud = sdk("appid", "secret");

cloud.wxacode
  .getUnlimited({
    scene: "test",
    path: "page/index?foo=bar"
  })
  .then(d => {
    fs.writeFileSync("1.png", d);
  });

解密示例

本 SDK 中加入解密方法 .crypto.decryptData

传入一个对象,包含以下三个参数:

  • sessionKey: 登录会话的凭证
  • encryptedData: 密文数据
  • iv:初始化向量

以上三个字段均为必须,在微信开发者文档中也有具体的说明。

const sdk = require("mp-sdk-rojer");
const cloud = sdk(
  "appid",
  "secret",
  async () => {
    return {}; // 这里你应该返回 token
  },
  async value => {
    // 这里你应该保存 token
  }
);

// 注意: 该方法并不放回 Promise 而是直接返回解密结果。
const result = cloud.crypto.decryptData({
  sessionKey: "xxx",
  encryptedData: "xxx",
  iv: "xxx"
});

console.log(result);
// 可能结果如下: watermark 对象用作校验,具体请参考文档
// {
//   phoneNumber: 'xxxx',
//   purePhoneNumber: 'xxx',
//   countryCode: 'xxxx',
//   watermark: { timestamp: 1560502778, appid: 'wxc0783c8b8bfef8d3' }
// }

参考文档

  • 接口文档: https://developers.weixin.qq.com/miniprogram/dev/api-backend/
  • 登录(sessionKey 获取): https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html
  • 数据加密解密: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
  • 小程序端授权: https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html

相关项目推荐

  • 阿里云 SDK: https://github.com/willin/waliyun
  • 腾讯云 SDK: https://github.com/willin/wqcloud
  • 网易云音乐 SDK: https://github.com/willin/wnm
  • Rescuetime SDK: https://github.com/willin/wrescuetime

License

Apache 2.0