wechat-js

WeChat Client

Client interface depend WeChat Core API, you need to create an instance of WeChat

const WeChat = require('wechat-lite');

const wx = new WeChat({
  appId: 'wx-your-app-id'
});

Get UUID

wx.uuid().then(function(uuid){
  console.log(uuid);
})

Generate QRCode

console.log(wx.qrcode(uuid));

Waiting for scan

(function wait(){
  wx.status(uuid).then(function(status){
    if(status.code == 200){
      console.log(status.redirect_uri); //登录URL
    }else{
      wait();
    }
  });
})()

Get login info

wx.login(url).then(function(info){
  console.log(info); // login info
})

Client Initialization

const client = new WeChat.Client(login);

client.init().then(function(){
  // success
});

Send and receive messages

client.send('hi').then(function(){
  // success
});