wechat-api Version: 1.2.2 By @Jackson Tian

微信公共平台Node库 API

api_common: API索引


API

根据appid和appsecret创建API的构造函数
如需跨进程跨机器进行操作Wechat API(依赖access token),access token需要进行全局维护
使用策略如下:

  1. 调用用户传入的获取token的异步方法,获得token之后使用
  2. 使用appid/appsecret获取token。并调用用户传入的保存token方法保存

Tips:

  • 如果跨机器运行wechat模块,需要注意同步机器之间的系统时间。

Examples:

var API = require('wechat').API;
var api = new API('appid', 'secret');

以上即可满足单进程使用。
当多进程时,token需要全局维护,以下为保存token的接口。

var api = new API('appid', 'secret', function (callback) {
  // 传入一个获取全局token的方法
  fs.readFile('access_token.txt', 'utf8', function (err, txt) {
    if (err) {return callback(err);}
    callback(null, JSON.parse(txt));
  });
}, function (token, callback) {
  // 请将token存储到全局,跨进程、跨机器级别的全局,比如写到数据库、redis等
  // 这样才能在cluster模式及多机情况下使用,以下为写入到文件的示例
  fs.writeFile('access_token.txt', JSON.stringify(token), callback);
});
函数 API() API
参数 appid(String) 在公众平台上申请得到的appid
参数 appsecret(String) 在公众平台上申请得到的app secret
参数 getToken(Function) 可选的。获取全局token对象的方法,多进程模式部署时需在意
参数 saveToken(Function) 可选的。保存全局token对象的方法,多进程模式部署时需在意

setOpts

用于设置urllib的默认options

Examples:

api.setOpts({timeout: 15000});
方法 API.prototype.setOpts() setOpts
参数 opts(Object) 默认选项

request

设置urllib的hook

Examples:

api.setHook(function (options) {
  // options
});
方法 API.prototype.request() request
参数 beforeRequest(Function) 需要封装的方法

getLatestToken

获取最新的token

Examples:

api.getLatestToken(callback);

Callback:

  • err, 获取access token出现异常时的异常对象
  • token, 获取的token
方法 API.prototype.getLatestToken() getLatestToken
参数 method(Function) 需要封装的方法
参数 args(Array) 方法需要的参数

mixin

用于支持对象合并。将对象合并到API.prototype上,使得能够支持扩展
Examples:

// 媒体管理(上传、下载)
API.mixin(require('./lib/api_media'));
方法 API.mixin() API mixin
参数 obj(Object) 要合并的对象

api_custom_service: API索引


getRecords

获取客服聊天记录
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=获取客服聊天记录

Opts:

{
 "starttime" : 123456789,
 "endtime" : 987654321,
 "openid": "OPENID", // 非必须
 "pagesize" : 10,
 "pageindex" : 1,
}

Examples:

api.getRecords(opts, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "recordlist": [
   {
     "worker": " test1",
     "openid": "oDF3iY9WMaswOPWjCIp_f3Bnpljk",
     "opercode": 2002,
     "time": 1400563710,
     "text": " 您好,客服test1为您服务。"
   },
   {
     "worker": " test1",
     "openid": "oDF3iY9WMaswOPWjCIp_f3Bnpljk",
     "opercode": 2003,
     "time": 1400563731,
     "text": " 你好,有什么事情? "
   },
 ]
}
方法 exports.getRecords() exports getRecords
参数 opts(Object) 查询条件
参数 callback(Function) 回调函数

getCustomServiceList

获取客服基本信息
详细请看:http://dkf.qq.com/document-3_1.html

Examples:

api.getCustomServiceList(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "kf_list": [
    {
      "kf_account": "test1@test",
      "kf_nick": "ntest1",
      "kf_id": "1001"
    },
    {
      "kf_account": "test2@test",
      "kf_nick": "ntest2",
      "kf_id": "1002"
    },
    {
      "kf_account": "test3@test",
      "kf_nick": "ntest3",
      "kf_id": "1003"
    }
  ]
}
方法 exports.getCustomServiceList() exports getCustomServiceList
参数 callback(Function) 回调函数

getOnlineCustomServiceList

获取在线客服接待信息
详细请看:http://dkf.qq.com/document-3_2.html

Examples:

api.getOnlineCustomServiceList(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "kf_online_list": [
    {
      "kf_account": "test1@test",
      "status": 1,
      "kf_id": "1001",
      "auto_accept": 0,
      "accepted_case": 1
    },
    {
      "kf_account": "test2@test",
      "status": 1,
      "kf_id": "1002",
      "auto_accept": 0,
      "accepted_case": 2
    }
  ]
}
方法 exports.getOnlineCustomServiceList() exports getOnlineCustomServiceList
参数 callback(Function) 回调函数

api_data: API索引


图文分析数据接口指的是用于获得公众平台官网数据统计模块中图文分析数据的接口
详情请见:http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
Examples:

api.getArticleSummary(startDate, endDate, callback); // 只能取1天数据
api.getArticleTotal(startDate, endDate, callback); // 只能取1天数据
api.getUserRead(startDate, endDate, callback); // 只能取3天数据
api.getUserReadHour(startDate, endDate, callback); // 只能取1天数据
api.getUserShare(startDate, endDate, callback); // 只能取7天数据
api.getUserShareHour(startDate, endDate, callback); // 只能取1天数据

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "list":[...] // 详细请参见<http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html>
}
参数 startDate(String) 起始日期,格式为2014-12-08
参数 endDate(String) 结束日期,格式为2014-12-08
参数 callback(Function) 回调函数

api_feedback: API索引


updateFeedback

标记客户的投诉处理状态
Examples:

api.updateFeedback(openid, feedbackId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.updateFeedback() exports updateFeedback
参数 openid(String) 用户ID
参数 feedbackId(String) 投诉ID
参数 callback(Function) 回调函数

api_group: API索引


getGroups

获取分组列表
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
Examples:

api.getGroups(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "groups": [
   {"id": 0, "name": "未分组", "count": 72596},
   {"id": 1, "name": "黑名单", "count": 36}
 ]
}
方法 exports.getGroups() exports getGroups
参数 callback(Function) 回调函数

getWhichGroup

查询用户在哪个分组
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
Examples:

api.getWhichGroup(openid, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "groupid": 102
}
方法 exports.getWhichGroup() exports getWhichGroup
参数 openid(String) Open ID
参数 callback(Function) 回调函数

createGroup

创建分组
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
Examples:

api.createGroup('groupname', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"group": {"id": 107, "name": "test"}}
方法 exports.createGroup() exports createGroup
参数 name(String) 分组名字
参数 callback(Function) 回调函数

updateGroup

更新分组名字
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
Examples:

api.updateGroup(107, 'new groupname', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"errcode": 0, "errmsg": "ok"}
方法 exports.updateGroup() exports updateGroup
参数 id(Number) 分组ID
参数 name(String) 新的分组名字
参数 callback(Function) 回调函数

moveUserToGroup

移动用户进分组
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
Examples:

api.moveUserToGroup(openid, groupId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"errcode": 0, "errmsg": "ok"}
方法 exports.moveUserToGroup() exports moveUserToGroup
参数 openid(String) 用户的openid
参数 groupId(Number) 分组ID
参数 callback(Function) 回调函数

api_ip: API索引


getIp

获取微信服务器IP地址
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E5%BE%AE%E4%BF%A1%E6%9C%8D%E5%8A%A1%E5%99%A8IP%E5%9C%B0%E5%9D%80
Examples:

api.getIp(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "ip_list":["127.0.0.1","127.0.0.1"]
}
方法 exports.getIp() exports getIp
参数 callback(Function) 回调函数

api_mass_send: API索引


uploadNews

上传多媒体文件,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.uploadNews(news, callback);

News:

{
 "articles": [
   {
     "thumb_media_id":"qI6_Ze_6PtV7svjolgs-rN6stStuHIjs9_DidOHaj0Q-mwvBelOXCFZiq2OsIU-p",
     "author":"xxx",
     "title":"Happy Day",
     "content_source_url":"www.qq.com",
     "content":"content",
     "digest":"digest",
     "show_cover_pic":"1"
  },
  {
     "thumb_media_id":"qI6_Ze_6PtV7svjolgs-rN6stStuHIjs9_DidOHaj0Q-mwvBelOXCFZiq2OsIU-p",
     "author":"xxx",
     "title":"Happy Day",
     "content_source_url":"www.qq.com",
     "content":"content",
     "digest":"digest",
     "show_cover_pic":"0"
  }
 ]
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "type":"news",
 "media_id":"CsEf3ldqkAYJAU6EJeIkStVDSvffUJ54vqbThMgplD-VJXXof6ctX5fI6-aYyUiQ",
 "created_at":1391857799
}
方法 exports.uploadNews() exports uploadNews
参数 news(Object) 图文消息对象
参数 callback(Function) 回调函数

uploadMPVideo

将通过上传下载多媒体文件得到的视频media_id变成视频素材
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.uploadMPVideo(opts, callback);

Opts:

{
 "media_id": "rF4UdIMfYK3efUfyoddYRMU50zMiRmmt_l0kszupYh_SzrcW5Gaheq05p_lHuOTQ",
 "title": "TITLE",
 "description": "Description"
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "type":"video",
 "media_id":"IhdaAQXuvJtGzwwc0abfXnzeezfO0NgPK6AQYShD8RQYMTtfzbLdBIQkQziv2XJc",
 "created_at":1391857799
}
方法 exports.uploadMPVideo() exports uploadMPVideo
参数 opts(Object) 待上传为素材的视频
参数 callback(Function) 回调函数

massSend

群发消息,分别有图文(news)、文本(text)、语音(voice)、图片(image)和视频(video)
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSend(opts, receivers, callback);

opts:

{
 "image":{
   "media_id":"123dsdajkasd231jhksad"
 },
 "msgtype":"image"
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSend() exports massSend
参数 opts(Object) 待发送的数据
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

massSendNews

群发图文(news)消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSendNews(mediaId, receivers, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSendNews() exports massSendNews
参数 mediaId(String) 图文消息的media id
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

massSendText

群发文字(text)消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSendText(content, receivers, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSendText() exports massSendText
参数 content(String) 文字消息内容
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

massSendVoice

群发声音(voice)消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSendVoice(media_id, receivers, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSendVoice() exports massSendVoice
参数 mediaId(String) 声音media id
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

massSendImage

群发图片(image)消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSendImage(media_id, receivers, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSendImage() exports massSendImage
参数 mediaId(String) 图片media id
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

massSendVideo

群发视频(video)消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSendVideo(mediaId, receivers, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSendVideo() exports massSendVideo
参数 mediaId(String) 视频media id
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

massSendMPVideo

群发视频(video)消息,直接通过上传文件得到的media id进行群发(自动生成素材)
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.massSendMPVideo(data, receivers, callback);

Data:

{
 "media_id": "rF4UdIMfYK3efUfyoddYRMU50zMiRmmt_l0kszupYh_SzrcW5Gaheq05p_lHuOTQ",
 "title": "TITLE",
 "description": "Description"
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id":34182
}
方法 exports.massSendMPVideo() exports massSendMPVideo
参数 data(Object) 视频数据
参数 receivers(String,Array) 接收人。一个组,或者openid列表
参数 callback(Function) 回调函数

deleteMass

删除群发消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.deleteMass(message_id, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"ok"
}
方法 exports.deleteMass() exports deleteMass
参数 messageId(String) 待删除群发的消息id
参数 callback(Function) 回调函数

previewNews

预览接口,预览图文消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.previewNews(openid, mediaId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id": 34182
}
方法 exports.previewNews() exports previewNews
参数 openid(String) 用户openid
参数 mediaId(String) 图文消息mediaId
参数 callback(Function) 回调函数

previewText

预览接口,预览文本消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.previewText(openid, content, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id": 34182
}
方法 exports.previewText() exports previewText
参数 openid(String) 用户openid
参数 content(String) 文本消息
参数 callback(Function) 回调函数

previewVoice

预览接口,预览语音消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.previewVoice(openid, mediaId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id": 34182
}
方法 exports.previewVoice() exports previewVoice
参数 openid(String) 用户openid
参数 mediaId(String) 语音mediaId
参数 callback(Function) 回调函数

previewImage

预览接口,预览图片消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.previewImage(openid, mediaId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id": 34182
}
方法 exports.previewImage() exports previewImage
参数 openid(String) 用户openid
参数 mediaId(String) 图片mediaId
参数 callback(Function) 回调函数

previewVideo

预览接口,预览视频消息
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.previewVideo(openid, mediaId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"send job submission success",
 "msg_id": 34182
}
方法 exports.previewVideo() exports previewVideo
参数 openid(String) 用户openid
参数 mediaId(String) 视频mediaId
参数 callback(Function) 回调函数

getMassMessageStatus

查询群发消息状态
详情请见:http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html
Examples:

api.getMassMessageStatus(messageId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "msg_id":201053012,
 "msg_status":"SEND_SUCCESS"
}
方法 exports.getMassMessageStatus() exports getMassMessageStatus
参数 messageId(String) 消息ID
参数 callback(Function) 回调函数

api_media: API索引


uploadMedia

上传多媒体文件,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
Examples:

api.uploadMedia('filepath', type, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}

Shortcut:

  • exports.uploadImage(filepath, callback);
  • exports.uploadVoice(filepath, callback);
  • exports.uploadVideo(filepath, callback);
  • exports.uploadThumb(filepath, callback);
方法 exports.uploadMedia() exports uploadMedia
参数 filepath(String) 文件路径
参数 type(String) 媒体类型,可用值有image、voice、video、thumb
参数 callback(Function) 回调函数

getMedia

根据媒体ID获取媒体内容
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件
Examples:

api.getMedia('media_id', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的文件Buffer对象
  • res, HTTP响应对象
方法 exports.getMedia() exports getMedia
参数 mediaId(String) 媒体文件的ID
参数 callback(Function) 回调函数

api_menu: API索引


createMenu

创建自定义菜单
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单创建接口

Menu:

{
 "button":[
   {
     "type":"click",
     "name":"今日歌曲",
     "key":"V1001_TODAY_MUSIC"
   },
   {
     "name":"菜单",
     "sub_button":[
       {
         "type":"view",
         "name":"搜索",
         "url":"http://www.soso.com/"
       },
       {
         "type":"click",
         "name":"赞一下我们",
         "key":"V1001_GOOD"
       }]
     }]
   }
 ]
}

Examples:

api.createMenu(menu, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"errcode":0,"errmsg":"ok"}
方法 exports.createMenu() exports createMenu
参数 menu(Object) 菜单对象
参数 callback(Function) 回调函数

getMenu

获取菜单
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单查询接口

Examples:

api.getMenu(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

// 结果示例
{
 "menu": {
   "button":[
     {"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},
     {"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},
     {"name":"菜单","sub_button":[
       {"type":"view","name":"搜索","url":"http://www.soso.com/","sub_button":[]},
       {"type":"view","name":"视频","url":"http://v.qq.com/","sub_button":[]},
       {"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]
     }
   ]
 }
}
方法 exports.getMenu() exports getMenu
参数 callback(Function) 回调函数

removeMenu

删除自定义菜单
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口
Examples:

api.removeMenu(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"errcode":0,"errmsg":"ok"}
方法 exports.removeMenu() exports removeMenu
参数 callback(Function) 回调函数

api_message: API索引


sendText

客服消息,发送文字消息
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
Examples:

api.sendText('openid', 'Hello world', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendText() exports sendText
参数 openid(String) 用户的openid
参数 text(String) 发送的消息内容
参数 callback(Function) 回调函数

sendImage

客服消息,发送图片消息
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
Examples:

api.sendImage('openid', 'media_id', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendImage() exports sendImage
参数 openid(String) 用户的openid
参数 mediaId(String) 媒体文件的ID,参见uploadMedia方法
参数 callback(Function) 回调函数

sendVoice

客服消息,发送语音消息
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
Examples:

api.sendVoice('openid', 'media_id', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendVoice() exports sendVoice
参数 openid(String) 用户的openid
参数 mediaId(String) 媒体文件的ID
参数 callback(Function) 回调函数

sendVideo

客服消息,发送视频消息
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
Examples:

api.sendVideo('openid', 'media_id', 'thumb_media_id', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendVideo() exports sendVideo
参数 openid(String) 用户的openid
参数 mediaId(String) 媒体文件的ID
参数 thumbMediaId(String) 缩略图文件的ID
参数 callback(Function) 回调函数

sendMusic

客服消息,发送音乐消息
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
Examples:

var music = {
 title: '音乐标题', // 可选
 description: '描述内容', // 可选
 musicurl: 'http://url.cn/xxx', 音乐文件地址
 hqmusicurl: "HQ_MUSIC_URL",
 thumb_media_id: "THUMB_MEDIA_ID"
};
api.sendMusic('openid', music, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendMusic() exports sendMusic
参数 openid(String) 用户的openid
参数 music(Object) 音乐文件
参数 callback(Function) 回调函数

sendNews

客服消息,发送图文消息
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=发送客服消息
Examples:

var articles = [
 {
   "title":"Happy Day",
   "description":"Is Really A Happy Day",
   "url":"URL",
   "picurl":"PIC_URL"
 },
 {
   "title":"Happy Day",
   "description":"Is Really A Happy Day",
   "url":"URL",
   "picurl":"PIC_URL"
 }];
api.sendNews('openid', articles, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendNews() exports sendNews
参数 openid(String) 用户的openid
参数 articles(Array) 图文列表
参数 callback(Function) 回调函数

api_payment: API索引


deliverNotify

微信公众号支付: 发货通知
详情请见:http://mp.weixin.qq.com/htmledition/res/bussiness-faq/wx_mp_pay.zip 接口文档订单发货通知

Data:

{
  "appid" : "wwwwb4f85f3a797777",
  "openid" : "oX99MDgNcgwnz3zFN3DNmo8uwa-w",
  "transid" : "111112222233333",
  "out_trade_no" : "555666uuu",
  "deliver_timestamp" : "1369745073",
  "deliver_status" : "1",
  "deliver_msg" : "ok",
  "app_signature" : "53cca9d47b883bd4a5c85a9300df3da0cb48565c",
  "sign_method" : "sha1"
}

Examples:

api.deliverNotify(data, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{"errcode":0, "errmsg":"ok"}
方法 exports.deliverNotify() exports deliverNotify
参数 package(Object) package对象
参数 callback(Function) 回调函数

orderQuery

微信公众号支付: 订单查询
详情请见:http://mp.weixin.qq.com/htmledition/res/bussiness-faq/wx_mp_pay.zip 接口文档订单查询部分

Package:

{
  "appid" : "wwwwb4f85f3a797777",
  "package" : "out_trade_no=11122&partner=1900090055&sign=4e8d0df3da0c3d0df38f",
  "timestamp" : "1369745073",
  "app_signature" : "53cca9d47b883bd4a5c85a9300df3da0cb48565c",
  "sign_method" : "sha1"
}

Examples:

api.orderQuery(query, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode":0,
  "errmsg":"ok",
  "order_info": {
    "ret_code":0,
    "ret_msg":"",
    "input_charset":"GBK",
    "trade_state":"0",
    "trade_mode":"1",
    "partner":"1900000109",
    "bank_type":"CMB_FP",
    "bank_billno":"207029722724",
    "total_fee":"1",
    "fee_type":"1",
    "transaction_id":"1900000109201307020305773741",
    "out_trade_no":"2986872580246457300",
    "is_split":"false",
    "is_refund":"false",
    "attach":"",
    "time_end":"20130702175943",
    "transport_fee":"0",
    "product_fee":"1",
    "discount":"0",
    "rmb_total_fee":""
  }
}
方法 exports.orderQuery() exports orderQuery
参数 query(Object) query对象
参数 callback(Function) 回调函数

api_qrcode: API索引


createTmpQRCode

创建临时二维码
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
Examples:

api.createTmpQRCode(10000, 1800, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "ticket":"gQG28DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0FuWC1DNmZuVEhvMVp4NDNMRnNRAAIEesLvUQMECAcAAA==",
 "expire_seconds":1800
}
方法 exports.createTmpQRCode() exports createTmpQRCode
参数 sceneId(Number) 场景ID
参数 expire(Number) 过期时间,单位秒。最大不超过1800
参数 callback(Function) 回调函数

createLimitQRCode

创建永久二维码
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
Examples:

api.createLimitQRCode(100, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "ticket":"gQG28DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL0FuWC1DNmZuVEhvMVp4NDNMRnNRAAIEesLvUQMECAcAAA=="
}
方法 exports.createLimitQRCode() exports createLimitQRCode
参数 sceneId(Number) 场景ID。ID不能大于100000
参数 callback(Function) 回调函数

showQRCodeURL

生成显示二维码的链接。微信扫描后,可立即进入场景
Examples:

api.showQRCodeURL(titck);
// => https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
方法 exports.showQRCodeURL() exports showQRCodeURL
参数 ticket(String) 二维码Ticket
返回 String
显示二维码的URL地址,通过img标签可以显示出来

api_semantic: API索引


semantic

发送语义理解请求
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=%E8%AF%AD%E4%B9%89%E7%90%86%E8%A7%A3

Opts:

{
  "query":"查一下明天从北京到上海的南航机票",
  "city":"北京",
  "category": "flight,hotel"
}

Examples:

api.semantic(uid, opts, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode":0,
  "query":"查一下明天从北京到上海的南航机票",
  "type":"flight",
  "semantic":{
      "details":{
          "start_loc":{
              "type":"LOC_CITY",
              "city":"北京市",
              "city_simple":"北京",
              "loc_ori":"北京"
              },
          "end_loc": {
              "type":"LOC_CITY",
              "city":"上海市",
              "city_simple":"上海",
              "loc_ori":"上海"
            },
          "start_date": {
              "type":"DT_ORI",
              "date":"2014-03-05",
              "date_ori":"明天"
            },
         "airline":"中国南方航空公司"
      },
  "intent":"SEARCH"
}
方法 exports.semantic() exports semantic
参数 openid(String) 用户ID
参数 opts(Object) 查询条件
参数 callback(Function) 回调函数

api_shop_common: API索引


uploadPicture

上传图片
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.uploadPicture('/path/to/your/img.jpg', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
 "image_url": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2ibl4JWwwnW3icSJGqecVtRiaPxwWEIr99eYYL6AAAp1YBo12CpQTXFH6InyQWXITLvU4CU7kic4PcoXA/0"
}
方法 exports.uploadPicture() exports uploadPicture
参数 filepath(String) 文件路径
参数 callback(Function) 回调函数

api_shop_express: API索引


addExpressTemplate

增加邮费模板
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.addExpress(express, callback);

Express:

{
 "delivery_template": {
   "Name": "testexpress",
   "Assumer": 0,
   "Valuation": 0,
   "TopFee": [
     {
       "Type": 10000027,
       "Normal": {
         "StartStandards": 1,
         "StartFees": 2,
         "AddStandards": 3,
         "AddFees": 1
       },
       "Custom": [
         {
           "StartStandards": 1,
           "StartFees": 100,
           "AddStandards": 1,
           "AddFees": 3,
           "DestCountry": "中国",
           "DestProvince": "广东省",
           "DestCity": "广州市"
         }
       ]
     },
     {
       "Type": 10000028,
       "Normal": {
         "StartStandards": 1,
         "StartFees": 3,
         "AddStandards": 3,
         "AddFees": 2
       },
       "Custom": [
         {
           "StartStandards": 1,
           "StartFees": 10,
           "AddStandards": 1,
           "AddFees": 30,
           "DestCountry": "中国",
           "DestProvince": "广东省",
           "DestCity": "广州市"
         }
       ]
     },
     {
       "Type": 10000029,
       "Normal": {
         "StartStandards": 1,
         "StartFees": 4,
         "AddStandards": 3,
         "AddFees": 3
       },
       "Custom": [
         {
           "StartStandards": 1,
           "StartFees": 8,
           "AddStandards": 2,
           "AddFees": 11,
           "DestCountry": "中国",
           "DestProvince": "广东省",
           "DestCity": "广州市"
         }
       ]
     }
   ]
 }
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
 "template_id": 123456
}
方法 exports.addExpressTemplate() exports addExpressTemplate
参数 express(Object) 邮费模版
参数 callback(Function) 回调函数

deleteExpressTemplate

修改邮费模板
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.deleteExpressTemplate(templateId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.deleteExpressTemplate() exports deleteExpressTemplate
参数 templateId(Number) 邮费模版ID
参数 callback(Function) 回调函数

updateExpressTemplate

修改邮费模板
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.updateExpressTemplate(template, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Express:

{
 "template_id": 123456,
 "delivery_template": ...
}

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.updateExpressTemplate() exports updateExpressTemplate
参数 template(Object) 邮费模版
参数 callback(Function) 回调函数

getExpressTemplateById

获取指定ID的邮费模板
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getExpressTemplateById(templateId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success",
 "template_info": {
   "Id": 103312916,
   "Name": "testexpress",
   "Assumer": 0,
   "Valuation": 0,
   "TopFee": [
     {
       "Type": 10000027,
       "Normal": {
         "StartStandards": 1,
         "StartFees": 2,
         "AddStandards": 3,
         "AddFees": 1
       },
       "Custom": [
         {
           "StartStandards": 1,
           "StartFees": 1000,
           "AddStandards": 1,
           "AddFees": 3,
           "DestCountry": "中国",
           "DestProvince": "广东省",
           "DestCity": "广州市"
         }
       ]
     },
     ...
   ]
 }
}
方法 exports.getExpressTemplateById() exports getExpressTemplateById
参数 templateId(Number) 邮费模版Id
参数 callback(Function) 回调函数

getAllExpressTemplates

获取所有邮费模板的未封装版本
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getAllExpressTemplates(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success",
 "templates_info": [
   {
     "Id": 103312916,
     "Name": "testexpress1",
     "Assumer": 0,
     "Valuation": 0,
     "TopFee": [...],
   },
   {
     "Id": 103312917,
     "Name": "testexpress2",
     "Assumer": 0,
     "Valuation": 2,
     "TopFee": [...],
   },
   {
     "Id": 103312918,
     "Name": "testexpress3",
     "Assumer": 0,
     "Valuation": 1,
     "TopFee": [...],
   }
 ]
}
方法 exports.getAllExpressTemplates() exports getAllExpressTemplates
参数 callback(Function) 回调函数

api_shop_goods: API索引


createGoods

增加商品
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.createGoods(goods, callback);

Goods:

{
 "product_base":{
   "category_id":[
     "537074298"
   ],
   "property":[
     {"id":"1075741879","vid":"1079749967"},
     {"id":"1075754127","vid":"1079795198"},
     {"id":"1075777334","vid":"1079837440"}
   ],
   "name":"testaddproduct",
   "sku_info":[
     {
       "id":"1075741873",
       "vid":["1079742386","1079742363"]
     }
   ],
   "main_img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0",
   "img":[
     "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0"
   ],
   "detail":[
     {"text":"testfirst"},
     {"img": 4whpV1VZl2iccsvYbHvnphkyGtnvjD3ul1UcLcwxrFdwTKYhH9Q5YZoCfX4Ncx655ZK6ibnlibCCErbKQtReySaVA/0"},
     {"text":"testagain"}
   ],
   "buy_limit":10
 },
 "sku_list":[
   {
     "sku_id":"1075741873:1079742386",
     "price":30,
     "icon_url": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl28bJj62XgfHPibY3ORKicN1oJ4CcoIr4BMbfA8LqyyjzOZzqrOGz3f5K Wq1QGP3fo6TOTSYD3TBQjuw/0",
     "product_code":"testing",
     "ori_price":9000000,
     "quantity":800
   },
   {
     "sku_id":"1075741873:1079742363",
     "price":30,
     "icon_url": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl28bJj62XgfHPibY3ORKicN1oJ4CcoIr4BMbfA8LqyyjzOZzqrOGz3f5K Wq1QGP3fo6TOTSYD3TBQjuw/0",
     "product_code":"testingtesting",
     "ori_price":9000000,
     "quantity":800
   }
 ],
 "attrext":{
   "location":{
     "country":"中国",
     "province":"广东省",
     "city":"广州市",
     "address":"T.I.T创意园"
   },
   "isPostFree":0,
   "isHasReceipt":1,
   "isUnderGuaranty":0,
   "isSupportReplace":0
 },
 "delivery_info":{
   "delivery_type":0,
   "template_id":0,
   "express":[
     {"id":10000027,"price":100},
     {"id":10000028,"price":100},
     {"id":10000029,"price":100}
   ]
 }
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success",
 "product_id": "pDF3iYwktviE3BzU3BKiSWWi9Nkw"
}
方法 exports.createGoods() exports createGoods
参数 goods(Object) 商品信息
参数 callback(Function) 回调函数

getGoods

查询商品
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getGoods(productId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success",
 "product_info":{
   "product_id":"pDF3iY6Kr_BV_CXaiYysoGqJhppQ",
   "product_base":{
     "name":"testaddproduct",
     "category_id":[537074298],
     "img":[
       "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0"
     ],
     "property":[
       {"id":"品牌","vid":"Fujifilm/富⼠士"},
       {"id":"屏幕尺⼨寸","vid":"1.8英⼨寸"},
       {"id":"防抖性能","vid":"CCD防抖"}
     ],
     "sku_info":[
       {
         "id":"1075741873",
         "vid":[
           "1079742386",
           "1079742363"
         ]
       }
     ],
     "buy_limit":10,
     "main_img": 4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic 0FD3vN0V8PILcibEGb2fPfEOmw/0",
     "detail_html": "<div class=\"item_pic_wrp\" style= \"margin-bottom:8px;font-size:0;\"><img class=\"item_pic\" style= \"width:100%;\" alt=\"\" src=\"http://mmbiz.qpic.cn/mmbiz/ 4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic 0FD3vN0V8PILcibEGb2fPfEOmw/0\" ></div><p style=\"margin-bottom: 11px;margin-top:11px;\">test</p><div class=\"item_pic_wrp\" style=\"margin-bottom:8px;font-size:0;\"><img class=\"item_pic\" style=\"width:100%;\" alt=\"\" src=\"http://mmbiz.qpic.cn/mmbiz/ 4whpV1VZl2iccsvYbHvnphkyGtnvjD3ul1UcLcwxrFdwTKYhH9Q5YZoCfX4Ncx655 ZK6ibnlibCCErbKQtReySaVA/0\" ></div><p style=\"margin-bottom: 11px;margin-top:11px;\">test again</p>"
   },
   "sku_list":[
     {
       "sku_id":"1075741873:1079742386",
       "price":30,
       "icon_url": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0",
       "quantity":800,
       "product_code":"testing",
       "ori_price":9000000
     },
     {
       "sku_id":"1075741873:1079742363",
       "price":30,
       "icon_url": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl28bJj62XgfHPibY3ORKicN1oJ4CcoIr4BMbfA8LqyyjzOZzqrOGz3f5KWq1QGP3fo6TOTSYD3TBQjuw/0",
       "quantity":800,
       "product_code":"testingtesting",
       "ori_price":9000000
     }
   ],
   "attrext":{
     "isPostFree":0,
     "isHasReceipt":1,
     "isUnderGuaranty":0,
     "isSupportReplace":0,
     "location":{
       "country":"中国",
       "province":"广东省",
       "city":"⼲州市",
       "address":"T.I.T创意园"
     }
   },
   "delivery_info":{
     "delivery_type":1,
     "template_id":103312920
   }
 }
}
方法 exports.getGoods() exports getGoods
参数 productId(String) 商品Id
参数 callback(Function) 回调函数

api_shop_group: API索引


createGoodsGroup

创建商品分组
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.createGoodsGroup(groupName, productList, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success",
 "group_id": 19
}
方法 exports.createGoodsGroup() exports createGoodsGroup
参数 groupName(String) 分组名
参数 productList(Array) 该组商品列表
参数 callback(Function) 回调函数

deleteGoodsGroup

删除商品分组
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.deleteGoodsGroup(groupId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.deleteGoodsGroup() exports deleteGoodsGroup
参数 groupId(String) 分组ID
参数 callback(Function) 回调函数

updateGoodsGroup

修改商品分组属性
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.updateGoodsGroup(groupId, groupName, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.updateGoodsGroup() exports updateGoodsGroup
参数 groupId(String) 分组ID
参数 groupName(String) 分组名
参数 callback(Function) 回调函数

updateGoodsForGroup

修改商品分组内的商品
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.updateGoodsForGroup(groupId, addProductList, delProductList, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.updateGoodsForGroup() exports updateGoodsForGroup
参数 groupId(Object) 分组ID
参数 addProductList(Array) 待添加的商品数组
参数 delProductList(Array) 待删除的商品数组
参数 callback(Function) 回调函数

getAllGroups

获取所有商品分组
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getAllGroups(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
 "groups_detail": [
   {
     "group_id": 200077549,
     "group_name": "新品上架"
   },{
     "group_id": 200079772,
     "group_name": "全球热卖"
   }
 ]
}
方法 exports.getAllGroups() exports getAllGroups
参数 callback(Function) 回调函数

getGroupById

根据ID获取商品分组
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getGroupById(groupId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
 "group_detail": {
   "group_id": 200077549,
   "group_name": "新品上架",
   "product_list": [
     "pDF3iYzZoY-Budrzt8O6IxrwIJAA",
     "pDF3iY3pnWSGJcO2MpS2Nxy3HWx8",
     "pDF3iY33jNt0Dj3M3UqiGlUxGrio"
   ]
 }
}
方法 exports.getGroupById() exports getGroupById
参数 groupId(String) 分组ID
参数 callback(Function) 回调函数

api_shop_order: API索引


getOrderById

根据订单Id获取订单详情
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getOrderById(orderId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success",
  "order": {
    "order_id": "7197417460812533543",
    "order_status": 6,
    "order_total_price": 6,
    "order_create_time": 1394635817,
    "order_express_price": 5,
    "buyer_openid": "oDF3iY17NsDAW4UP2qzJXPsz1S9Q",
    "buyer_nick": "likeacat",
    "receiver_name": "张小猫",
    "receiver_province": "广东省",
    "receiver_city": "广州市",
    "receiver_address": "华景路一号南方通信大厦5楼",
    "receiver_mobile": "123456789",
    "receiver_phone": "123456789",
    "product_id": "pDF3iYx7KDQVGzB7kDg6Tge5OKFo",
    "product_name": "安莉芳E-BRA专柜女士舒适内衣蕾丝3/4薄杯聚拢上托性感文胸KB0716",
    "product_price": 1,
    "product_sku": "10000983:10000995;10001007:10001010",
    "product_count": 1,
    "product_img": "http://img2.paipaiimg.com/00000000/item-52B87243-63CCF66C00000000040100003565C1EA.0.300x300.jpg",
    "delivery_id": "1900659372473",
    "delivery_company": "059Yunda",
    "trans_id": "1900000109201404103172199813"
  }
}
方法 exports.getOrderById() exports getOrderById
参数 orderId(String) 订单Id
参数 callback(Function) 回调函数

getOrdersByStatus

根据订单状态/创建时间获取订单详情
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getOrdersByStatus([status,] [beginTime,] [endTime,] callback);

Usage:
当只传入callback参数时,查询所有状态,所有时间的订单
当传入两个参数,第一个参数为Number类型,第二个参数为callback时,查询指定状态,所有时间的订单
当传入两个参数,第一个参数为Date类型,第二个参数为callback时,查询所有状态,指定订单创建起始时间的订单(待测试)
当传入三个参数,第一参数为订单状态码,第二参数为订单创建起始时间,第三参数为callback
当传入四个参数,第一参数为订单状态码,第二参数为订单创建起始时间,第三参数为订单创建终止时间,第四参数为callback
Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success",
  "order_list": [
    {
      "order_id": "7197417460812533543",
      "order_status": 6,
      "order_total_price": 6,
      "order_create_time": 1394635817,
      "order_express_price": 5,
      "buyer_openid": "oDF3iY17NsDAW4UP2qzJXPsz1S9Q",
      "buyer_nick": "likeacat",
      "receiver_name": "张小猫",
      "receiver_province": "广东省",
      "receiver_city": "广州市",
      "receiver_address": "华景路一号南方通信大厦5楼",
      "receiver_mobile": "123456",
      "receiver_phone": "123456",
      "product_id": "pDF3iYx7KDQVGzB7kDg6Tge5OKFo",
      "product_name": "安莉芳E-BRA专柜女士舒适内衣蕾丝3/4薄杯聚拢上托性感文胸KB0716",
      "product_price": 1,
      "product_sku": "10000983:10000995;10001007:10001010",
      "product_count": 1,
      "product_img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2icND8WwMThBEcehjhDv2icY4GrDSG5RLM3B2qd9kOicWGVJcsAhvXfibhWRNoGOvCfMC33G9z5yQr2Qw/0",
      "delivery_id": "1900659372473",
      "delivery_company": "059Yunda",
      "trans_id": "1900000109201404103172199813"
    },
    {
      "order_id": "7197417460812533569",
      "order_status": 8,
      "order_total_price": 1,
      "order_create_time": 1394636235,
      "order_express_price": 0,
      "buyer_openid": "oDF3iY17NsDAW4UP2qzJXPsz1S9Q",
      "buyer_nick": "likeacat",
      "receiver_name": "张小猫",
      "receiver_province": "广东省",
      "receiver_city": "广州市",
      "receiver_address": "华景路一号南方通信大厦5楼",
      "receiver_mobile": "123456",
      "receiver_phone": "123456",
      "product_id": "pDF3iYx7KDQVGzB7kDg6Tge5OKFo",
      "product_name": "项坠333",
      "product_price": 1,
      "product_sku": "1075741873:1079742377",
      "product_count": 1,
      "product_img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2icND8WwMThBEcehjhDv2icY4GrDSG5RLM3B2qd9kOicWGVJcsAhvXfibhWRNoGOvCfMC33G9z5yQr2Qw/0",
      "delivery_id": "1900659372473",
      "delivery_company": "059Yunda",
      "trans_id": "1900000109201404103172199813"
    }
  ]
}
方法 exports.getOrdersByStatus() exports getOrdersByStatus
参数 status(Number) 状态码。(无此参数-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中)
参数 beginTime(Date) 订单创建时间起始时间。(无此参数则不按照时间做筛选)
参数 endTime(Date) 订单创建时间终止时间。(无此参数则不按照时间做筛选)
参数 callback(Function) 回调函数

setExpressForOrder

设置订单发货信息
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.setExpressForOrder(orderId, deliveryCompany, deliveryTrackNo, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.setExpressForOrder() exports setExpressForOrder
参数 orderId(String) 订单Id
参数 deliveryCompany(String) 物流公司 (物流公司Id请参考微信小店API手册)
参数 deliveryTrackNo(String) 运单Id
参数 callback(Function) 回调函数

closeOrder

关闭订单
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.closeOrder(orderId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.closeOrder() exports closeOrder
参数 orderId(String) 订单Id
参数 callback(Function) 回调函数

api_shop_shelf: API索引


createShelf

增加货架
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.createShelf(shelf, callback);

Shelf:

{
  "shelf_data": {
    "module_infos": [
    {
      "group_info": {
        "filter": {
          "count": 2
        },
        "group_id": 50
      },
      "eid": 1
    },
    {
      "group_infos": {
        "groups": [
          {
            "group_id": 49
          },
          {
            "group_id": 50
          },
          {
            "group_id": 51
          }
        ]
      },
      "eid": 2
    },
    {
      "group_info": {
        "group_id": 52,
        "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5Jm64z4I0TTicv0TjN7Vl9bykUUibYKIOjicAwIt6Oy0Y6a1Rjp5Tos8tg/0"
      },
      "eid": 3
    },
    {
      "group_infos": {
        "groups": [
          {
            "group_id": 49,
            "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5uUQx7TLx4tB9qZfbe3JmqR4NkkEmpb5LUWoXF1ek9nga0IkeSSFZ8g/0"
          },
          {
            "group_id": 50,
            "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5G1kdy3ViblHrR54gbCmbiaMnl5HpLGm5JFeENyO9FEZAy6mPypEpLibLA/0"
          },
          {
            "group_id": 52,
            "img": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5uUQx7TLx4tB9qZfbe3JmqR4NkkEmpb5LUWoXF1ek9nga0IkeSSFZ8g/0"
          }
        ]
      },
      "eid": 4
    },
    {
      "group_infos": {
        "groups": [
          {
            "group_id": 43
          },
          {
            "group_id": 44
          },
          {
            "group_id": 45
          },
          {
            "group_id": 46
          }
        ],
      "img_background": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl29nqqObBwFwnIX3licVPnFV5uUQx7TLx4tB9qZfbe3JmqR4NkkEmpb5LUWoXF1ek9nga0IkeSSFZ8g/0"
      },
      "eid": 5
    }
    ]
  },
  "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2ibrWQn8zWFUh1YznsMV0XEiavFfLzDWYyvQOBBszXlMaiabGWzz5B2KhNn2IDemHa3iarmCyribYlZYyw/0",
  "shelf_name": "测试货架"
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success",
  "shelf_id": 12
}
方法 exports.createShelf() exports createShelf
参数 shelf(Object) 货架信息
参数 callback(Function) 回调函数

deleteShelf

删除货架
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.deleteShelf(shelfId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success"
}
方法 exports.deleteShelf() exports deleteShelf
参数 shelfId(String) 货架Id
参数 callback(Function) 回调函数

updateShelf

修改货架
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.updateShelf(shelf, callback);

Shelf:

{
  "shelf_id": 12345,
  "shelf_data": ...,
  "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/ 4whpV1VZl2ibrWQn8zWFUh1YznsMV0XEiavFfLzDWYyvQOBBszXlMaiabGWzz5B2K hNn2IDemHa3iarmCyribYlZYyw/0",
  "shelf_name": "货架名称"
}

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success"
}
方法 exports.updateShelf() exports updateShelf
参数 shelf(Object) 货架信息
参数 callback(Function) 回调函数

getAllShelves

获取所有货架
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getAllShelf(callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success",
  "shelves": [
    {
      "shelf_info": {
      "module_infos": [
        {
        "group_infos": {
          "groups": [
          {
            "group_id": 200080093
          },
          {
            "group_id": 200080118
          },
          {
            "group_id": 200080119
          },
          {
            "group_id": 200080135
          }
          ],
          "img_background": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl294FzPwnf9dAcaN7ButStztAZyy2yHY8pW6sTQKicIhAy5F0a2CqmrvDBjMFLtc2aEhAQ7uHsPow9A/0"
        },
        "eid": 5
        }
      ]
      },
      "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl294FzPwnf9dAcaN7ButStztAZyy2yHY8pW6sTQKicIhAy5F0a2CqmrvDBjMFLtc2aEhAQ7uHsPow9A/0",
      "shelf_name": "新新人类",
      "shelf_id": 22
    },
    {
      "shelf_info": {
      "module_infos": [
        {
          "group_info": {
            "group_id": 200080119,
            "filter": {
              "count": 4
            }
          },
          "eid": 1
        }
      ]
      },
      "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl294FzPwnf9dAcaN7ButStztAZyy2yHY8pW6sTQKicIhAy5F0a2CqmrvDBjMFLtc2aEhAQ7uHsPow9A/0",
      "shelf_name": "店铺",
      "shelf_id": 23
    }
  ]
}
方法 exports.getAllShelves() exports getAllShelves
参数 callback(Function) 回调函数

getShelfById

根据货架ID获取货架信息
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.getShelfById(shelfId, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
  "errcode": 0,
  "errmsg": "success",
  "shelf_info": {
    "module_infos": [...]
  },
  "shelf_banner": "http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2ibp2DgDXiaic6WdflMpNdInS8qUia2BztlPu1gPlCDLZXEjia2qBdjoLiaCGUno9zbs1UyoqnaTJJGeEew/0",
  "shelf_name": "新建货架",
  "shelf_id": 97
}
方法 exports.getShelfById() exports getShelfById
参数 shelfId(String) 货架Id
参数 callback(Function) 回调函数

api_shop_stock: API索引


updateStock

增加库存
详细请看:http://mp.weixin.qq.com/wiki/index.php?title=微信小店接口
Examples:

api.updateStock(10, productId, sku, callback); // 增加10件库存
api.updateStock(-10, productId, sku, callback); // 减少10件库存

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode": 0,
 "errmsg": "success"
}
方法 exports.updateStock() exports updateStock
参数 number(Number) 增加或者删除的数量
参数 productId(String) 商品ID
参数 sku(String) SKU信息
参数 callback(Function) 回调函数

api_template: API索引


setIndustry

设置所属行业
Examples:

var industryIds = {
 "industry_id1":'1',
 "industry_id2":"4"
};
api.setIndustry(industryIds, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.setIndustry() exports setIndustry
参数 industryIds(Object) 公众号模板消息所属行业编号

addTemplate

获得模板ID
Examples:

var templateIdShort = 'TM00015';
api.addTemplate(templateIdShort, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.addTemplate() exports addTemplate
参数 templateIdShort(String) 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式

sendTemplate

发送模板消息
Examples:

var templateId: '模板id';
// URL置空,则在发送后,点击模板消息会进入一个空白页面(ios), 或无法点击(android)
var url: 'http://weixin.qq.com/download';
var topcolor = '#FF0000'; // 顶部颜色
var data = {
 user:{
   "value":'黄先生',
   "color":"#173177"
 }
};
api.sendTemplate('openid', templateId, url, topColor, data, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.sendTemplate() exports sendTemplate
参数 openid(String) 用户的openid
参数 templateId(String) 模板ID
参数 url(String) URL置空,则在发送后,点击模板消息会进入一个空白页面(ios),或无法点击(android)
参数 topColor(String) 顶部颜色
参数 data(Object) 渲染模板的数据
参数 callback(Function) 回调函数

api_url: API索引


shorturl

短网址服务
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=长链接转短链接接口
Examples:

api.shorturl('http://mp.weixin.com', callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象
方法 exports.shorturl() exports shorturl
参数 longUrl(String) 需要转换的长链接,支持http://、https://、weixin://wxpay格式的url
参数 callback(Function) 回调函数

api_user: API索引


getUser

获取用户基本信息
详情请见:http://mp.weixin.qq.com/wiki/index.php?title=获取用户基本信息
Examples:

api.getUser(openid, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "subscribe": 1,
 "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
 "nickname": "Band",
 "sex": 1,
 "language": "zh_CN",
 "city": "广州",
 "province": "广东",
 "country": "中国",
 "headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
 "subscribe_time": 1382694957
}
方法 exports.getUser() exports getUser
参数 openid(String) 用户的openid
参数 callback(Function) 回调函数

getFollowers

获取关注者列表
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=获取关注者列表
Examples:

api.getFollowers(callback);
// or
api.getFollowers(nextOpenid, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "total":2,
 "count":2,
 "data":{
   "openid":["","OPENID1","OPENID2"]
 },
 "next_openid":"NEXT_OPENID"
}
方法 exports.getFollowers() exports getFollowers
参数 nextOpenid(String) 调用一次之后,传递回来的nextOpenid。第一次获取时可不填
参数 callback(Function) 回调函数

updateRemark

设置用户备注名
详细细节 http://mp.weixin.qq.com/wiki/index.php?title=设置用户备注名接口
Examples:

api.updateRemark(openid, remark, callback);

Callback:

  • err, 调用失败时得到的异常
  • result, 调用正常时得到的对象

Result:

{
 "errcode":0,
 "errmsg":"ok"
}
方法 exports.updateRemark() exports updateRemark
参数 openid(String) 用户的openid
参数 remark(String) 新的备注名,长度必须小于30字符
参数 callback(Function) 回调函数

util: API索引