Skip to content

ddnlink/egg-wechat

 
 

Repository files navigation

@ddn/egg-wechat

npm version

微信公众平台常规的后端服务,献给了不起的EggJS

本项目 fork 自 egg-mp,感谢原作者 unclexiao 的贡献。

特性

微信小程序

  • 小程序登录
  • 小程序授权
  • 小程序支付
  • 推送模板消息
  • 检测是否含有敏感词
  • 生成二维码/小程序码
  • 接入在线客服消息

微信服务号

  • 网页授权
  • 发送模板消息
  • 获取用户基础信息
  • 获取用户列表
  • 服务号网页支付
  • 前端调用JSSDK

微信开放平台 (第三方平台)

  • 获取 Component Access Token
  • 获取预授权码 (PreAuthCode)
  • 获取授权方信息 (QueryAuth)
  • 发送客服消息
  • 获取授权页 URL

安装

$ npm i @ddn/egg-wechat --save

启用插件

// {app_root}/config/plugin.js
exports.wechat = {
  enable: true,
  package: '@ddn/egg-wechat',
};

应用配置

// {app_root}/config/config.default.js
exports.wechat = {
  appId: '', // 公众平台应用编号
  appSecret: '', // 公众平台应用密钥
  mchId: '', // 商户平台商家编号
  apiKey: '', // 商户支付密钥
  notifyUrl: '', // 支付结果回调地址
  
  // 开放平台第三方平台配置
  componentAppId: '',
  componentAppSecret: '',
  componentToken: '',
  componentEncodingAESKey: '',
};

请查看 doc/CONFIG.md 获取更详细说明.

简单实例

小程序/公众号

async login() {
    const { ctx } = this;
    const { code } = ctx.request.query;
    // 注意命名空间变为 ctx.service.wechat.mp
    let res = await ctx.service.wechat.mp.login(code);
    // {
    //   session_key: "...",
    //   openid: "..."
    // };
}

开放平台 (Component)

async getAuthUrl() {
    const { ctx } = this;
    // 获取授权页 URL
    const url = await ctx.service.wechat.component.getOAuthDomainUrl();
    // ...
}

基础教程

  • 配置项如何找到?
  • 如何搭建环境?
  • 如何本地调试?
  • 登录与授权(获取用户信息)
  • 微信支付(小程序、服务号)
  • 推送消息(服务通知、模板消息)
  • 生成二维码(或小程序码)

问题与建议

请在这里向我提出问题

开源协议

MIT

About

EggJS插件:微信公众平台基本服务

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%