wechat

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2020 License: MIT Imports: 9 Imported by: 0

README

WeChat SDK for Go

👏👏👏 Golang Wechat SDK

golang MIT license

目录

快速入门

缓存
package main

import	"github.com/fideism/golang-wechat/cache"

func main() {
    redis := &cache.RedisOpts{
            Host:        "127.0.0.1:6379",
            Password:    "111111",
            Database:    1,
            MaxIdle:     5, //最大等待连接中的数量
            MaxActive:   3, //最大连接数据库连接数
            IdleTimeout: 1, //客户端的idle
    }

    cache := cache.NewRedis(redis)
}
公众号

详细方法见公众号参考

package main

import (
	"fmt"
	wechat "github.com/fideism/golang-wechat"
	"github.com/fideism/golang-wechat/cache"
	"github.com/fideism/golang-wechat/officialaccount"
	offConfig "github.com/fideism/golang-wechat/officialaccount/config"
)

func main() {
    redis := &cache.RedisOpts{
        Host:     "127.0.0.1:6379",
    }
    
    config := &offConfig.Config{
        AppID:          "xxx",
        AppSecret:      "xxx",
        Token:          "xxx",
        EncodingAESKey: "xxx",
        Cache:          cache.NewRedis(redis),
    }
    
    // 初始化wechat实例,分别调用对应功能模块
    wechat := wechat.NewWechat()
    officail := wechat.GetOfficialAccount(config)
    
    // 单独获得officailAccount实例
    // officail := officialaccount.NewOfficialAccount(config)
    
    token, err := officail.GetAccessToken()
    if err != nil {
        panic(err)
    }
    
    fmt.Println(token)
}

参数

Params util.Params

import "github.com/fideism/golang-wechat/util"

// Params map[string]interface{}
type Params map[string]interface{}

// Set 设置值
func (p Params) Set(k string, v interface{})

// Get 获取值
func (p Params) Get(k string) (v interface{})

// GetString 强制获取k对应的v string类型
func (p Params) GetString(k string) string

// Exists 判断是否存在
func (p Params) Exists(k string) bool

//具体使用
p := util.Params{
    "openid": "xx",
}

//alse can
p.Set("notify_url", "https://github.com/fideism/golang-wechat")
日志

默认记录debug级别日志

可以通过设置系统LOG_LEVEL来控制日志记录

Based On 👍

silenceper/wechat

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Wechat

type Wechat struct {
	// contains filtered or unexported fields
}

Wechat struct

func NewWechat

func NewWechat() *Wechat

NewWechat init

func (*Wechat) GetMiniProgram

func (w *Wechat) GetMiniProgram(c *miniConfig.Config) *miniprogram.MiniProgram

GetMiniProgram 获取小程序的实例

func (*Wechat) GetOfficialAccount

func (w *Wechat) GetOfficialAccount(c *offConfig.Config) *officialaccount.OfficialAccount

GetOfficialAccount 获取微信公众号实例

func (*Wechat) GetOpenPlatform

func (w *Wechat) GetOpenPlatform(c *openConfig.Config) *openplatform.OpenPlatform

GetOpenPlatform 获取微信开放平台的实例

func (*Wechat) GetPay

func (w *Wechat) GetPay(c *config.Config) *pay.Pay

GetPay 获取微信支付的实例

func (*Wechat) SetCache

func (w *Wechat) SetCache(cache cache.Cache)

SetCache 设置cache

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL