Wrote an easy-to-use WeChat SDK with Golang

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

WeChat SDK for Go

The SDK developed with Golang is simple and easy to use.

Project Address: Https://github.com/silenceper/wechat

Document Address: Docs

Quick Start

Here is an example of handling message reception and reply:

//配置参数config := &wechat.Config{    AppID:          "xxxx",    AppSecret:      "xxxx",    Token:          "xxxx",    EncodingAESKey: "xxxx",    Cache:          memCache}wc := wechat.NewWechat(config)// 传入request和responseWriterserver := wc.GetServer(request, responseWriter)server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {    //回复消息:演示回复用户发送的消息    text := message.NewText(msg.Content)    return &message.Reply{message.MsgText, text}})server.Serve()server.Send()

Complete code: EXAMPLES/HTTP/HTTP.GO

Used in conjunction with the mainstream framework

The main thing is that request and responsewriter may not get the same way in different frameworks:

    • Beego:./examples/beego/beego.go

    • Gin Framework:./examples/gin/gin.go

Basic Configuration

memcache := cache.NewMemcache("127.0.0.1:11211")wcConfig := &wechat.Config{    AppID:          cfg.AppID,    AppSecret:      cfg.AppSecret,    Token:          cfg.Token,    EncodingAESKey: cfg.EncodingAESKey,//消息加解密时用到    Cache:          memcache,}

Cache settings

The cache is primarily used to save global Access_token and ticket in JS-SDK:
Memcache storage is used by default. Of course, you can also directly implement cache/cache.go the interface in

Basic API Usage

    • Message Management

      • Receive normal messages

      • Receive event push

      • Passive reply message

        • Reply text message

        • Reply to Picture message

        • Reply to a video message

        • Reply to music messages

        • Reply text message

    • customizing menus

      • custom Menu Creation Interface

      • Custom Menu Query Interface

      • Custom Menu Delete Interface

      • Custom Menu Event Push

      • Personalized Menu Interface

        • Add a personalized Menu

        • Delete a personalized menu

        • Test personalized Menu Matching Results

      • Get the public Number menu configuration

    • Web Development

      • Oauth2 Authorization

        • Initiate authorization

        • Exchange Access_token by code

        • Pull User Information

        • Refresh Access_token

        • Verify that the Access_token is valid

      • Get JS-SDK Configuration

    • Material Management

For more API usage please refer to the documentation:
Https://github.com/silenceper ...

Related Article

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.