node-webot / co-wechat-api

Wechat API. Support Async Functions
Other
724 stars 170 forks source link

[ERROR] api.batchGetUser() NOT A FUNCTION #54

Closed Here21 closed 7 years ago

Here21 commented 7 years ago
  const user  = [ 
    'o3gdewT5m6HzRGZrGr726Y3M20AE', 
    'o3gdewZPmhIQlCnatI3LI9D55-cc',
    'o3gdewYlR32p_zrHH76O7DsJOn7I',
    'o3gdewUVPwuExcS9XAjQkOY-8LPU'
  ]

  const userList = await api.batchGetUser(user);
  console.log(userList);
// got as below
(node:6042) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: api.batchGetUser is not a function
(node:6042) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
JacksonTian commented 7 years ago

TypeError: api.batchGetUser is not a function

Here21 commented 7 years ago

solved

exports.batchGetUsers = async function (openids) {
  const { accessToken } = await this.ensureAccessToken();
  var url = this.prefix + 'user/info/batchget?access_token=' + accessToken;
  var data = {};
  data.user_list = openids.map(function (openid) {
    return {openid: openid, lang: 'zh_CN'};
  });
  return this.request(url, postJSON(data));
};

文档上写的是: api.batchGetUser(['openid1', 'openid2']) 可以 closed

JacksonTian commented 7 years ago

文档已经更新。谢谢。