{"id":15509748,"url":"https://github.com/willin/mp-sdk","last_synced_at":"2025-04-23T02:51:04.056Z","repository":{"id":34924283,"uuid":"191372210","full_name":"willin/mp-sdk","owner":"willin","description":"微信小程序服务器端SDK。Wechat Mini Program (mp) Serverside SDK","archived":false,"fork":false,"pushed_at":"2023-07-12T00:02:22.000Z","size":321,"stargazers_count":11,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T17:41:55.687Z","etag":null,"topics":["mini-program","mp","sdk","wechat"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mp-sdk","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"willin","custom":"https://afdian.net/@willin"}},"created_at":"2019-06-11T12:59:02.000Z","updated_at":"2025-02-04T08:30:14.000Z","dependencies_parsed_at":"2022-08-08T03:00:29.210Z","dependency_job_id":null,"html_url":"https://github.com/willin/mp-sdk","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":0.368421052631579,"last_synced_commit":"8c14e9c9a3881639e129e04e61c92dd7287631f5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fmp-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fmp-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fmp-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willin%2Fmp-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willin","download_url":"https://codeload.github.com/willin/mp-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249693369,"owners_count":21311475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mini-program","mp","sdk","wechat"],"created_at":"2024-10-02T09:43:40.265Z","updated_at":"2025-04-23T02:51:04.034Z","avatar_url":"https://github.com/willin.png","language":"JavaScript","funding_links":["https://github.com/sponsors/willin","https://afdian.net/@willin"],"categories":["JavaScript"],"sub_categories":[],"readme":"# mp-sdk\n\n比官方SDK更好用的微信小程序服务器端SDK。\n\n\u003e 已经疯狂得不能用代码行数（总计`89`行，包含空行和debug）来衡量该项目了，代码仅有 `1,310`字节（净化后）。\n\n[![github](https://img.shields.io/github/followers/willin.svg?style=social\u0026label=Followers)](https://github.com/willin) [![npm](https://img.shields.io/npm/v/mp-sdk.svg)](https://npmjs.org/package/mp-sdk) [![npm](https://img.shields.io/npm/dm/mp-sdk.svg)](https://npmjs.org/package/mp-sdk) [![npm](https://img.shields.io/npm/dt/mp-sdk.svg)](https://npmjs.org/package/mp-sdk) [![codebeat badge](https://codebeat.co/badges/dcda6ad6-46a4-4178-900a-aaf9ea056321)](https://codebeat.co/projects/github-com-willin-mp-sdk-master)\n\nMinimum, Flexible, Scalable.\n\n支持Lazy Require。\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [安装使用](#%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8)\n  - [基本使用示例](#%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B)\n  - [二维码处理示例](#%E4%BA%8C%E7%BB%B4%E7%A0%81%E5%A4%84%E7%90%86%E7%A4%BA%E4%BE%8B)\n  - [解密示例](#%E8%A7%A3%E5%AF%86%E7%A4%BA%E4%BE%8B)\n- [参考文档](#%E5%8F%82%E8%80%83%E6%96%87%E6%A1%A3)\n- [相关项目推荐](#%E7%9B%B8%E5%85%B3%E9%A1%B9%E7%9B%AE%E6%8E%A8%E8%8D%90)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## 安装使用\n\n```bash\nyarn add mp-sdk\n# 或\nnpm i --save mp-sdk\n```\n\n### 基本使用示例\n\n```js\nconst sdk = require('mp-sdk');\n\nconst cloud = sdk('appid', 'secret');\n\n// appid、secret、access_token、grant_type 4个字段可以忽略不写\ncloud.auth.code2Session({\n  js_code: 'js_code'\n}).then(result =\u003e {\n  // code here\n});\n```\n\n### 二维码处理示例\n\n```js\nconst sdk = require('mp-sdk');\nconst fs = require('fs');\n\nconst cloud = sdk('appid', 'secret');\n\ncloud.wxacode.getUnlimited({\n  scene: 'test',\n  path: 'page/index?foo=bar'\n}).then((d) =\u003e {\n  fs.writeFileSync('1.png', d);\n});\n```\n\n### 解密示例\n\n本SDK中加入解密方法 `.crypto.decryptData`。\n\n传入一个对象，包含以下三个参数：\n\n- sessionKey： 登录会话的凭证\n- encryptedData： 密文数据\n- iv：初始化向量\n\n以上三个字段均为必须，在微信开发者文档中也有具体的说明。\n\n```js\nconst sdk = require('mp-sdk');\nconst cloud = sdk('appid', 'secret');\n\n// 注意： 该方法并不放回 Promise 而是直接返回解密结果。\nconst result = cloud.crypto.decryptData({\n  sessionKey: 'xxx',\n  encryptedData: 'xxx',\n  iv: 'xxx'\n});\n\nconsole.log(result);\n// 可能结果如下： watermark 对象用作校验，具体请参考文档\n// {\n//   phoneNumber: 'xxxx',\n//   purePhoneNumber: 'xxx',\n//   countryCode: 'xxxx',\n//   watermark: { timestamp: 1560502778, appid: 'wxc0783c8b8bfef8d3' }\n// }\n```\n\n## 参考文档\n\n- 接口文档： https://developers.weixin.qq.com/miniprogram/dev/api-backend/\n- 登录（sessionKey获取）： https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html\n- 数据加密解密： https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html\n- 小程序端授权： https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html\n\n## 相关项目推荐\n\n- 阿里云SDK： https://github.com/willin/waliyun\n- 腾讯云SDK： https://github.com/willin/wqcloud\n- 网易云音乐SDK： https://github.com/willin/wnm\n- Rescuetime SDK： https://github.com/willin/wrescuetime\n\n## License\n\nApache 2.0\n\n\u003cimg width=\"483\" alt=\"donate\" src=\"https://user-images.githubusercontent.com/1890238/59274374-cd594300-8c8c-11e9-8ee8-fe9be4b49cdb.png\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillin%2Fmp-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillin%2Fmp-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillin%2Fmp-sdk/lists"}