Coder Social home page Coder Social logo

willin / mp-sdk Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 2.0 321 KB

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

Home Page: https://www.npmjs.com/package/mp-sdk

License: Apache License 2.0

JavaScript 100.00%
mp wechat sdk mini-program

mp-sdk's Introduction

mp-sdk

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

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

github npm npm npm codebeat badge

Minimum, Flexible, Scalable.

支持Lazy Require。

安装使用

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

基本使用示例

const sdk = require('mp-sdk');

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');
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');
const cloud = sdk('appid', 'secret');

// 注意: 该方法并不放回 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' }
// }

参考文档

相关项目推荐

License

Apache 2.0

donate

mp-sdk's People

Contributors

dependabot[bot] avatar willin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rojer95 yang100

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.