golang封装的微信小程序服务端SDK
source link: https://www.itwork.club/2021/04/23/go-wechat-miniapp-sdk/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
golang封装的微信小程序服务端SDK
置顶Apr 23, 2021SDK8点击
对接微信小程序开发,离不开对接微信小程序的服务端接口,每次开发一个小程序都需要对接一次接口。为了以后快速开发,避免每开发一次就得对接一次服务端的接口。经过自己的多次对接的经验,现在将一些小程序常用的服务端接口封装成一个快速开发的SDK包。
本SDK是使用golang开发的,适用于golang项目。
基于微信小程序服务端的接口封装,使用golang语言封装的一套微信小程序官方接口SDK,SDK实现了
基于内存
和基于Redis
两种方式管理access_token若在使用过程中出现bug,请到issues提问.
当前版本: v1.0.0
go >= 1.14
go get github.com/dgb8901/go-wechat-miniapp-sdk
初始化SDK
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.Config{
AppId: "AppId",
Secret: "Secret",
Token: "Token",
AesKey: "AesKey",
MsgDataFormat: "DataFormat",
}
// wxaConfig := config.NewRedis(cfg,"127.0.0.1:6379","123456")
// wxaService := service.NewInRedis(redisConfig)
wxaConfig := config.NewMemory(cfg)
wxaService := service.NewInMemory(wxaConfig)
helper.wxaService = wxaService
}
func GetWxaService() *service.WxaService {
return wxaHelper.wxaService
}
// 获取用户service
userService := helper.GetWxaService().GetUserService()
// 根据用户service获取用户session
session, err := userService.Jscode2Session(jsCode)
QQ: 770713275
License
MIT License, see license file
原文作者: dgb8901,yinxing
原文链接: https://www.itwork.club/2021/04/23/go-wechat-miniapp-sdk/
版权声明: 转载请注明出处
体验小程序「简易记账」
关注公众号「特想学英语」
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK