1.0.19 • Published 5 years ago

egg-wx v1.0.19

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

egg-wx

NPM version

build status

Test coverage

David deps

npm download

Install

$ npm i egg-wx --save
$ npm install xml2js egg-redis --save

Usage

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

Configuration

// {app_root}/config/config.default.js
config.bodyParser = {
  extendTypes: {
    text: [ 'application/xml', 'text/xml', 'text/html' ],
  },
  enableTypes: [ 'text' ],
};

config.wx = {
  redisClient: '', // Set this if used Multi Clients
  redisPrefix: 'egg-wx',
  AppID: 'appid',
  AppSecret: 'app_secret',
  MiniAppID: 'mini_appid', // wechat mini program app id
  MiniAppSecret: 'mini_app_secret', // wechat mini program app secret
  token: 'egg-wx',
  EncodingAESKey: 'EncodingAESKey',
};

see https://mp.weixin.qq.com/wiki for more detail

Example

async index() {
    ctx.body = await app.wx.apiCommon.getAccessToken();
}

Classes

ApiCommon

微信基本接口,包含获取AccessToken

Kind: global class

apiCommon.getRedisCache() ⇒ object

返回Redis对象

Kind: instance method of ApiCommon
Returns: object - redis对象

apiCommon.getAccessToken(type = 'wx') ⇒ string

获取AccessToken,如果cache存在则直接读取chace

Kind: instance method of ApiCommon
Returns: string - AccessToken

ParamTypeDescription
typestring类型 默认wx-公众号,mini-小程序

apiCommon.getAccessTokenFromApi(type = 'wx') ⇒ string

通过微信接口获取AccessToken

Kind: instance method of ApiCommon
Returns: string - AccessToken

ParamTypeDescription
typestring类型 默认wx-公众号,mini-小程序

ApiCustom

客服接口

Kind: global class

apiCustom.post(data, type) ⇒ *

POST

Kind: instance method of ApiCustom
Returns: * - 返回信息

ParamTypeDefaultDescription
dataobjectpost数据
typestring"msg"请求类型 msg: 消息类请求

apiCustom.addCustomservice(email, nickname, password) ⇒ *

添加客服账号

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
emailstring邮箱
nicknamestring昵称
passwordstring密码

apiCustom.updateCustomservice(email, nickname, password) ⇒ *

修改客服账号

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
emailstring邮箱
nicknamestring昵称
passwordstring密码

apiCustom.deleteCustomservice(email) ⇒ *

删除客服账号

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
emailstring邮箱

apiCustom.getCustomserviceList() ⇒ *

获取客服列表

Kind: instance method of ApiCustom
Returns: * - 正常返回true

apiCustom.sendText(openid, content) ⇒ *

发送文字消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
contentstring内容

apiCustom.sendImage(openid, mediaID) ⇒ *

发送图片消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
mediaIDstring媒体ID

apiCustom.sendVoice(openid, mediaID) ⇒ *

发送声音消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
mediaIDstring媒体ID

apiCustom.sendVideo(openid, mediaID, thumbMediaID, title, description) ⇒ *

发送视频消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
mediaIDstring视频媒体ID
thumbMediaIDstring视频媒体缩略图ID
titlestring标题
descriptionstring描述

apiCustom.sendMusic(openid, title, description, musicurl, hqmusicurl, thumbMediaID) ⇒ *

发送音乐消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
titlestring标题
descriptionstring描述
musicurlstring音乐地址
hqmusicurlstringHQ音乐地址
thumbMediaIDstring缩略图ID

apiCustom.sendNews(openid, articles) ⇒ *

发送图文消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
articlesarray图文消息列表格式为: { "title": "Happy Day", "description": "Is Really A Happy Day", "url": "URL", "picurl": "PIC_URL" }

apiCustom.sendMpNews(openid, mediaID) ⇒ *

发送图文消息

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
mediaIDstring图文消息ID

apiCustom.sendWxCard(openid, cardID) ⇒ *

发送卡券

Kind: instance method of ApiCustom
Returns: * - 正常返回true

ParamTypeDescription
openidstring用户Openid
cardIDstring卡券ID

ApiJssdk

jssdk接口

Kind: global class

apiJssdk.getRedisCache() ⇒ object

返回Redis对象

Kind: instance method of ApiJssdk
Returns: object - redis对象

apiJssdk.getJsapiTicket() ⇒ object

返回jsapi ticket对象,缓存读取

Kind: instance method of ApiJssdk
Returns: object - ticket对象

apiJssdk.getJsapiTicketFromApi(accessToken) ⇒ object

返回jsapi ticket对象,接口返回

Kind: instance method of ApiJssdk
Returns: object - ticket对象

ParamTypeDescription
accessTokenstringaccess-token

apiJssdk.getSign(url, nonce, timestamp) ⇒ object

返回签名

Kind: instance method of ApiJssdk
Returns: object - 返回签名

ParamTypeDescription
urlstring授权网站
noncestring随机字符
timestampstring时间戳

apiJssdk.getJsapiConfig(url) ⇒ object

返回jssdk参数

Kind: instance method of ApiJssdk
Returns: object - 前端jssdk配置参数对象 {appId, timestamp, nonceStr, signature}

ParamTypeDescription
urlstring授权网站

ApiMenu

自定义菜单接口

Kind: global class

apiMenu.createMenu(menuItems) ⇒ boolean

创建自定义菜单

Kind: instance method of ApiMenu
Returns: boolean - 创建结果

ParamTypeDescription
menuItemsobject微信公众平台自定义菜单格式对象,详见微信接口文档

apiMenu.getMenu() ⇒ object

获取当前自定义菜单结构

Kind: instance method of ApiMenu
Returns: object - 菜单结构

apiMenu.deleteMenu() ⇒ boolean

删除当前自定义菜单

Kind: instance method of ApiMenu
Returns: boolean - 结果

ApiMessage

消息接口

Kind: global class

apiMessage.getRandomStr(len) ⇒ string

返回指定长度的随机字符串

Kind: instance method of ApiMessage
Returns: string - 随机字符串

ParamTypeDefaultDescription
leninteger16随机字符长度

apiMessage.getIntervalRandom(min, max) ⇒ integer

返回指定整数区间的随机数

Kind: instance method of ApiMessage
Returns: integer - 随机整数

ParamTypeDescription
mininteger最小整数
maxinteger最大整数

apiMessage.getObjectFromXml(data) ⇒ object

解析xml为对象

Kind: instance method of ApiMessage
Returns: object - 解析结果

ParamTypeDescription
datastring来自微信服务器的xml内容

apiMessage.getXmlFromObject(data) ⇒ object

解析Object为xml

Kind: instance method of ApiMessage
Returns: object - 解析结果

ParamTypeDescription
datastringObject内容

apiMessage.messageEncrypt(msg) ⇒ string

返回微信消息加密文本

Kind: instance method of ApiMessage
Returns: string - 密文

ParamTypeDescription
msgstring信息文本

apiMessage.messageDecrypt(msg) ⇒ string

返回微信消息解密数据

Kind: instance method of ApiMessage
Returns: string - 解密文本

ParamTypeDescription
msgstring密文文本

apiMessage.sendTemplateMessage(openid, template_id, data, jumpUrl, miniprogram = null, type = 'wx') ⇒ string

发送模板消息

Kind: instance method of ApiMessage
Returns: string - 发送结果

ParamTypeDefaultDescription
openidstring接收openid
template_idstring模板ID
datastring模板数据
jumpUrlstring跳转链接
miniprogramstringnull小程序跳转
typestring类型 默认wx-公众号,mini-小程序

apiMessage.sendSubscribeMessage(openid, template_id, data, page = null) ⇒ string

发送订阅消息

Kind: instance method of ApiMessage
Returns: string - 发送结果

ParamTypeDefaultDescription
openidstring接收openid
template_idstring模板ID
datastring模板数据
pagestring跳转页面

apiMessage.checkSign(urlQuery, encryptText) ⇒ boolean

校验请求签名

Kind: instance method of ApiMessage
Returns: boolean - 校验结果

ParamTypeDescription
urlQueryobjectctx.query
encryptTextstring加密密文

apiMessage.getSign(timestamp, nonce, encryptText) ⇒ string

生成签名

Kind: instance method of ApiMessage
Returns: string - 解密结果

ParamTypeDescription
timestampstring/integerunix(10)时间戳
noncestring随机字符串
encryptTextstring加密密文

ApiMiniProgramSession

小程序获取用户Session接口

Kind: global class

apiMiniProgramSession.getSession(js_code) ⇒ object

小程序通过code获取用户Session

Kind: instance method of ApiMiniProgramSession
Returns: object - jscode2session数据

ParamTypeDescription
js_code*授权code

ApiQRCode

qrcode接口

Kind: global class

apiQRCode.createQRCode(type, sceneValue, expire_seconds) ⇒ object

生成二维码

Kind: instance method of ApiQRCode
Returns: object - 二维码值

ParamTypeDefaultDescription
typestring二维码类型
sceneValuestring/integer场景值
expire_secondsinteger30超时时间

ApiServer

服务器验证接口

Kind: global class

apiServer.checkServer(ctx) ⇒ boolean/string

验证消息的确来自微信服务器,微信公众平台接口配置校验

Kind: instance method of ApiServer
Returns: boolean/string - 校验结果

ParamTypeDescription
ctxobject上下文对象

ApiShortUrl

ShortUrl接口

Kind: global class

apiShortUrl.createShortUrl(longurl) ⇒ object

生成二维码

Kind: instance method of ApiShortUrl
Returns: object - 短连接

ParamTypeDescription
longurlstring长连接

ApiWebAuth

用户授权接口

Kind: global class

apiWebAuth.getUserWebAccessToken(code) ⇒ object

通过code获取用户网页授权access_token

Kind: instance method of ApiWebAuth
Returns: object - access_token授权数据

ParamTypeDescription
code*授权code

apiWebAuth.refreshUserWebAccessToken(refresh_token) ⇒ object

刷新用户网页授权access_token

Kind: instance method of ApiWebAuth
Returns: object - access_token授权数据

ParamTypeDescription
refresh_tokenstring刷新token

apiWebAuth.getUserWebInfo(access_token, openid, lang) ⇒ object

获取用户信息

Kind: instance method of ApiWebAuth
Returns: object - 用户信息对象

ParamTypeDefaultDescription
access_tokenstring用户网页授权access_token
openidstring用户openid
langstring"zh_CN"返回地区语音
1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.1-4.1

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago