Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

willin/mp-sdk

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

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

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Contributors 2

  •  
  •  
Morty Proxy This is a proxified and sanitized view of the page, visit original site.