Go development WeChat applet SDK recommendations and simple examples

Recently, I was planning to use Go language to develop WeChat applets, and found that many server-side interfaces of WeChat applets will be called, and they also need to be encapsulated by themselves. So I thought about going to GitHub to see if there was a third-party ready-made SDK that I could use directly, and I found two very good third-party libraries.

SDK standards:
Here are a few points. I personally use some standard versions of third-party open source libraries for your reference:

The function is stable and there are cases in the production environment. To avoid SDK problems, developers need to solve them themselves.

The development team is stable and continuously updated. To avoid bugs that no one will fix later, an open source project similar to KPI will emerge.

The function is powerful enough. After all, the purpose of using an open source SDK is to reduce the need to develop some additional functions and focus more on business implementation.

Complete documentation. No matter how good an open source project is, if it does not have a complete document, this will undoubtedly increase the threshold for users, and at the same time reduce the development efficiency, failing to achieve the purpose of directly using third-party SDKs.


easywechat
has used PHP to develop WeChat ecological products. You may all know that easywechat is an open source, unofficial third-party SDK. It is powerful, easy to install and use, because it is a standard Composer package, which means that any PHP project supporting Composer that meets the following installation conditions can use it. Simply use the following command to install and use it normally.

composer require overtrue/wechat

powerwechat
PowerWeChat is a simple and easy-to-use WeChat SDK for Golang that currently covers WeChat official accounts, WeChat mini programs, WeChat payment, and enterprise WeChat. The functions are very powerful and include almost all the products of the WeChat ecosystem. Choosing it is mainly based on the following purposes:

Powerful functions and complete WeChat ecological coverage. Covers WeChat official accounts, WeChat mini programs, WeChat enterprise accounts and WeChat payment. Basically, the WeChat development we come into contact with is also in these categories. So it's enough for us.

The development team is stable. PowerWechat is developed with great concentration by the Artisan Cloud team and is being continuously updated and improved.

Complete documentation. PowerWechat has its own official website. Whether it is WeChat official account, WeChat applet, WeChat enterprise account and WeChat payment, there are independent modules to introduce how to use it, and there are also complete sample codes. The following is a good explanation of how to configure each parameter definition for WeChat enterprise account development.

package main

import (
  "log"
)

func main() {
    
    
  WeComApp, err := work.NewWork(&work.UserConfig{
    
    
    CorpID:  "app_id",       // 企业微信的app id,所有企业微信共用一个。
    AgentID: 100001,         // 内部应用的app id
    Secret:  "wecom_secret", // 内部应用的app secret
    OAuth: work.OAuth{
    
    
      Callback: "https://wecom.artisan-cloud.com/callback",
      Scopes:   nil,
    },
    HttpDebug: true,
  })
  if err != nil {
    
    
    panic(err)
  }
  response := WeComApp.Base.GetCallbackIp()
  log.Println(response)
}

go-wechat-miniapp-sdk
go-wechat-miniapp-sdk is a set of WeChat applet official interface SDK encapsulated using golang language based on WeChat applet related interface encapsulation. Supports the following functions:

Login | User information
Subscribe to messages
Customer service messages
Unified service messages
Obtain mini program code
...
The same SDK is very simple to use and you can get started quickly.

The following is the installation method of the SDK.

go get github.com/dgb8901/go-wechat-miniapp-sdk

The following is the basic information configuration:

package helper

import (
    "github.com/dgb8901/go-wechat-miniapp-sdk/config"
    "github.com/dgb8901/go-wechat-miniapp-sdk/service"
)

type wxaHelper struct {
    
    
    wxaService *service.WxaService
}

var helper = &wxaHelper{
    
    }

func Init() {
    
    

    cfg := &config.Cfg{
    
    
        AppId:         "AppId",
        Secret:        "Secret",
        Token:         "Token",
        AesKey:        "AesKey",
        MsgDataFormat: "DataFormat",
    }
    // wxaConfig := config.NewInRedis(cfg,"127.0.0.1:6379","123456")
    // wxaService := service.NewInRedis(redisConfig)
    wxaConfig := config.NewInMemory(cfg)
    wxaService := service.NewService(wxaConfig)

    helper.wxaService = wxaService
}

func GetWxaService() *service.WxaService {
    
    
    return wxaHelper.wxaService
}

From the records submitted on GitHub, it can be seen that this SDK should be developed by individuals. There is no complete documentation and it has been updated for a long time. It is not recommended for use in production environments. If you want to learn how to encapsulate it yourself, or want to implement your own SDK on this basis, you can learn from this SDK.

Guess you like

Origin blog.csdn.net/u014374009/article/details/133231870