{"id":27154967,"url":"https://github.com/coajs/coa-wx-mp","last_synced_at":"2025-04-08T18:56:37.679Z","repository":{"id":43885046,"uuid":"399466592","full_name":"coajs/coa-wx-mp","owner":"coajs","description":"一个超简单的微信公众号SDK for Node.js","archived":false,"fork":false,"pushed_at":"2023-07-19T03:54:17.000Z","size":195,"stargazers_count":1,"open_issues_count":5,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-25T16:54:00.718Z","etag":null,"topics":["coa","coa-wx","coa-wx-mp","coajs","mp","wx","wx-mp"],"latest_commit_sha":null,"homepage":"https://npmjs.com/coa-wx-mp","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coajs.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}},"created_at":"2021-08-24T13:00:51.000Z","updated_at":"2022-11-28T12:20:36.000Z","dependencies_parsed_at":"2023-01-22T00:16:15.235Z","dependency_job_id":null,"html_url":"https://github.com/coajs/coa-wx-mp","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-wx-mp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-wx-mp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-wx-mp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-wx-mp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coajs","download_url":"https://codeload.github.com/coajs/coa-wx-mp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247909160,"owners_count":21016478,"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":["coa","coa-wx","coa-wx-mp","coajs","mp","wx","wx-mp"],"created_at":"2025-04-08T18:56:37.216Z","updated_at":"2025-04-08T18:56:37.665Z","avatar_url":"https://github.com/coajs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# coa-wx-mp\n\n一个超简单的微信公众号 SDK for Node.js\n\n## 特征\n\n根据日常实际项目使用情况：\n\n- 覆盖了常用使用场景\n- 统一了异步表现形式，全部返回 Promise\n- 内置类型引用，无需额外查看文档，开箱即用，IDE 友好\n\n## 快速开始\n\n### 安装\n\n```shell\nyarn add coa-wx-mp\n```\n\n### 直接使用\n\n```typescript\nimport { WxMpBin, WxMpSnsService } from 'coa-wx-mp'\n\n// 公众号配置\nconst config = {\n  appId: 'wxe4fe827f00000000',\n  secret: '04277da11000000000000000ddc25c063',\n}\n\n// 初始化Bin实例\nconst bin = new WxMpBin(config)\n\n// 根据Bin实例，初始化一个服务\nconst service = new WxMpSnsService(bin)\n\n// 从前端获取一个code\nconst code = 'XXXXXXXXX'\n\n// 调用服务 获取Token\nconst { accessToken, openid } = await service.getOAuthToken(code)\n\nconsole.log({ accessToken, openid })\n\n// 调用服务 获取用户信息\nconst { nickname, unionid } = await service.getUserInfo(accessToken, openid)\n\nconsole.log({ nickname, unionid })\n```\n\n### 记录错误信息\n\n```typescript\nimport { WxMpBin, WxMpSnsService } from 'coa-wx-mp'\n\n// 自定义bin实例\nclass MyWxMpBin extends WxMpBin {\n  // 自定义请求异常的事件\n  onRequestError(error, res) {\n    // 在这里记录错误\n    console.log(error)\n    console.log(res)\n  }\n}\n\n// 初始化自定义的Bin实例\nconst myBin = new MyWxMpBin(config)\n\n// 根据自定义的Bin实例，初始化一个服务\nconst service = new WxMpSnsService(myBin)\n\n// 从前端获取一个code\nconst code = 'XXXXXXXXX'\n\n// 调用服务 获取Token\nconst { accessToken, openid } = await service.getOAuthToken(code)\n\n// 错误地调用服务 获取Token\nconst { accessToken, openid } = await service.getOAuthToken() // onRequestError 会记录这条错误信息\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoajs%2Fcoa-wx-mp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoajs%2Fcoa-wx-mp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoajs%2Fcoa-wx-mp/lists"}