Golang realization of WeChat chat robot

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Main modules

    • Get UUID
    • Get QR code based on UUID
    • Display two-dimensional code
    • Scan Code Login
    • Initializing information
    • Turn on State synchronization notifications
    • Get Contacts
    • Send Message
    • Synchronizing information
    • Get Auto Reply content

Source Address

Https://github.com/qianlnk/gobot

Web-Version API

Get UUID

    • Interface Address
      https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_={Timestamp}

    • Method
      GET

    • Results

window.QRLogin.code = 200; window.QRLogin.uuid = "xxx";
    • Realize
      Reference Getuuid method

Get two-dimensional code

    • Interface Address
      https://login.weixin.qq.com/qrcode/{UUID}?t=webwx&_={Timestamp}

    • Method
      GET

    • Realize
      Reference Genqrcode method

    • Output the QR code to the terminal
      Https://github.com/qianlnk/qrcode

Login

    • Interface Address
      https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip={1,0}&uuid=(UUID}&_={Timestamp}

Tip:1 No sweep code 0 has been swept code

    • Method
      GET

    • Results

window.code=xxx;xxx:    408 登陆超时    201 扫描成功    200 确认登录当返回200时,还会有window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=xxx&uuid=xxx&lang=xxx&scan=xxx";

Get the URL that is required by the regular, followed by a unified base_url representation.

BASE_URL = https://wx.qq.com
    • Realize
      Refer to the Login method

    • Jump
      Get login information for a user

    Skey       string `xml:"skey"`    Wxsid      string `xml:"wxsid"`    Wxuin      string `xml:"wxuin"`    PassTicket string `xml:"pass_ticket"`

Initialization

    • Interface Address
      BASE_URL/webwxinit?pass_ticket={PassTicket}&skey={Skey}&r={Timestamp}

    • Method
      POST

    • Results

type InitResult struct {    BaseResponse        BaseResponse     `json:"BaseResponse"`    Count               int              `json:"Count"`    ContactList         []Contact        `json:"ContactList"`    SyncKey             SyncKey          `json:"SyncKey"`    User                User             `json:"User"`    ChatSet             string           `json:"ChatSet"`    SKey                string           `json:"SKey"`    ClientVersion       int              `json:"ClientVersion"`    SystemTime          int              `json:"SystemTime"`    GrayScale           int              `json:"GrayScale"`    InviteStartCount    int              `json:"InviteStartCount"`    MPSubscribeMsgCount int              `json:"MPSubscribeMsgCount"`    MPSubscribeMsgList  []MPSubscribeMsg `json:"MPSubscribeMsgList"`    ClickReportInterval int              `json:"ClickReportInterval"`}
    • Realize
      Refer to the Init method

Status notifications

    • Interface Address
      BASE_URL/webwxstatusnotify?lang=zh_CN&pass_ticket={PassTicket}

    • Parameters

    params := make(map[string]interface{})    params["BaseRequest"] = w.baseRequest    params["Code"] = 3    params["FromUserName"] = w.user.UserName    params["ToUserName"] = w.user.UserName    params["ClientMsgId"] = int(time.Now().Unix())
    • Method
      POST

-Achieve
Reference Statusnotify method

Get Contacts

    • Interface Address
      BASE_URL/webwxgetcontact?sid={Wxsid}&skey={Skey}&pass_ticket={PassTicket}

    • Parameters

    params := make(map[string]interface{})    params["BaseRequest"] = w.baseRequest

-Method
POST

    • Realize
      Reference GetContact method

Synchronizing information

    • Interface Address
      https://host/cgi-bin/mmwebwx-bin/synccheck

Host

    Hosts = []string{        "webpush.wx.qq.com",        "webpush2.wx.qq.com",        "webpush.wechat.com",        "webpush1.wechat.com",        "webpush2.wechat.com",        "webpush1.wechatapp.com",    }

-Parameters

        v := url.Values{}        v.Add("r", w.timestamp())        v.Add("sid", w.loginRes.Wxsid)        v.Add("uin", w.loginRes.Wxuin)        v.Add("skey", w.loginRes.Skey)        v.Add("deviceid", w.deviceID)        v.Add("synckey", w.strSyncKey())        v.Add("_", w.timestamp())
    • Method
      GET

    • Results

window.synccheck={retcode:"xxx",selector:"xxx"}retcode:    0 正常    1100 手机上退出网页版    1101在其他地方登录网页版selector:    0 正常    2 新的消息    7 进入/离开聊天界面
    • Realize
      Reference Synccheck method

When selector=2 the new information is read

    • Interface Address
      BASE_URL/webwxsync?sid={Wxsid}&skey={Skey}&pass_ticket={PassTicket}

    • Parameters

    params := make(map[string]interface{})    params["BaseRequest"] = w.baseRequest    params["SyncKey"] = w.syncKey    params["rr"] = ^int(time.Now().Unix())
    • Method
      POST

    • Attention

Modify Synckey, important

    if msg.BaseResponse.Ret == 0 {        w.syncKey = msg.SyncKey    }
    • Realize
      Reference Wxsync method

Send Message

    • Interface Address
      BASE_URL/webwxsendmsg?pass_ticket={PassTicket}

    • Parameters

    params := make(map[string]interface{})    params["BaseRequest"] = w.baseRequest    msg := make(map[string]interface{})    msg["Type"] = 1    msg["Content"] = message    msg["FromUserName"] = w.user.UserName    msg["ToUserName"] = to    msg["LocalID"] = clientMsgID    msg["ClientMsgId"] = clientMsgID    params["Msg"] = msg
    • Method
      POST

    • Realize
      Reference SendMessage method

Turing API

Get Auto Reply content

    • Interface Address
      http://www.tuling123.com/openapi/api

    • Go to Turing's website to register and get key
      Http://www.tuling123.com

    • Parameters

    params := make(map[string]interface{})    params["userid"] = uid    params["key"] = w.cfg.Tuling.Keys[w.user.NickName].Key    params["info"] = msg
    • Method
      POST

    • Results

    Code int         `json:"code"`    Text string      `json:"text"` //100000    URL  string      `json:"url"`  //200000    List interface{} `json:"list"` //302000 []News 308000 []Menu
    • Realize
      Reference Getreply method

Run.png

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.