wxcom

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 9 Imported by: 0

README

go-wxcom

GitHub Workflow Status Codecov Go Report Card GitHub go.mod Go version

企业微信 SDK

Feature

  • 通讯录管理(暂未计划)
  • 应用管理
    • 获取应用
    • 设置应用
    • 自定义菜单
      • 创建菜单
      • 获取菜单
      • 删除菜单
  • 身份验证
    • 构造网页授权链接
    • 构造扫码登录链接
    • 获取访问用户身份
  • 消息管理
    • 发送应用信息:支持文本、图片、语音、文件、文本卡片、markdown消息
    • 发送消息到群聊会话
      • 创建群聊会话
      • 修改群聊会话
      • 获取群聊会话
      • 应用推送信息

使用

go get github.com/mingzaily/go-wxcom

Example

package main

import (
  "fmt"
  "github.com/mingzaily/go-wxcom"
)

func main() {
  client := wxcom.New("corpid", "corpsecret", 0)

  resp, err := client.M().ToUser([]string{"test_user"}).Text("测试").Send()
  if err != nil {
    panic(err)
  }
  fmt.Println(resp)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

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

Message struct is used to compose and fire individual message client.

func (*Message) Clone added in v0.4.0

func (m *Message) Clone() *Message

Clone method create the new message client.

func (*Message) DuplicateCheck added in v0.4.0

func (m *Message) DuplicateCheck(enableDuplicateCheck, duplicateCheckInterval int) *Message

DuplicateCheck method enables the duplicate check. Param example: 0, 0 duplicate check is not enabled. 1, 1800 duplicate check within 1800 seconds.

func (*Message) File

func (m *Message) File(mediaId string) *file

File method creates file message.

func (*Message) Image

func (m *Message) Image(mediaId string) *image

Image method creates image message.

func (*Message) Markdown

func (m *Message) Markdown(content string) *markdown

Markdown method creates markdown message.

func (*Message) Text

func (m *Message) Text(content string) *text

Text method creates text message.

func (*Message) Textcard

func (m *Message) Textcard(title, description, url string) *textcard

Textcard method creates textcard message.

func (*Message) ToParty added in v0.4.0

func (m *Message) ToParty(partyList []string) *Message

ToParty method sets to party to in the current message.

func (*Message) ToTag added in v0.4.0

func (m *Message) ToTag(tagList []string) *Message

ToTag method sets to tag to in the current message.

func (*Message) ToUser added in v0.4.0

func (m *Message) ToUser(userList []string) *Message

ToUser method sets to user to in the current message.

func (*Message) Video

func (m *Message) Video(mediaId string) *video

Video method creates video message.

func (*Message) Voice

func (m *Message) Voice(mediaId string) *voice

Voice method creates voice message.

type Oauth added in v0.5.0

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

Oauth struct is used to get user info client.

func (*Oauth) GenAuthorizationUrl added in v0.5.0

func (o *Oauth) GenAuthorizationUrl(redirectUri string) string

GenAuthorizationUrl method to construct web page authorization link.

func (*Oauth) GenAuthorizationUrlWithState added in v0.5.2

func (o *Oauth) GenAuthorizationUrlWithState(redirectUri, state string) string

GenAuthorizationUrlWithState method to construct web page authorization link with state.

func (*Oauth) GenAuthorizeScanCodeUrl added in v0.5.0

func (o *Oauth) GenAuthorizeScanCodeUrl(redirectUri string) string

GenAuthorizeScanCodeUrl method to build the scan code login authorization link.

func (*Oauth) GenAuthorizeScanCodeUrlWithState added in v0.5.2

func (o *Oauth) GenAuthorizeScanCodeUrlWithState(redirectUri, state string) string

GenAuthorizeScanCodeUrlWithState method to build the scan code login authorization link with state.

func (*Oauth) GetUserInfo added in v0.5.0

func (o *Oauth) GetUserInfo(code string) (*RespOauth, error)

GetUserInfo method to obtain user information through code.

type RespMessage added in v0.4.0

type RespMessage struct {
	Invaliduser  string `json:"invaliduser"`
	Invalidparty string `json:"invalidparty"`
	Invalidtag   string `json:"invalidtag"`
	Msgid        string `json:"msgid"`
	ResponseCode string `json:"response_code"`
	// contains filtered or unexported fields
}

RespMessage struct holds response values of send message.

type RespOauth added in v0.5.0

type RespOauth struct {
	UserId         string `json:"UserId"`
	DeviceId       string `json:"DeviceId"`
	OpenId         string `json:"OpenId"`
	ExternalUserId string `json:"external_userid"`
	// contains filtered or unexported fields
}

RespOauth struct holds response values of get user info.

type Wxcom

type Wxcom struct {
	Resty *resty.Client
	// contains filtered or unexported fields
}

Wxcom struct is used to create wxcom client.

The cache uses patrickmn/go-cache. You can refer to related documents(https://github.com/patrickmn/go-cache) if necessary.

The resty uses go-resty/resty/v2. You can refer to related documents(https://github.com/go-resty/resty) if necessary.

func New

func New(corpid, corpsecret string, agentid int) *Wxcom

New method creates a new Wxcom client.

func (*Wxcom) GetAccessToken added in v0.4.0

func (w *Wxcom) GetAccessToken() string

GetAccessToken method get access token from server or cache.

func (*Wxcom) GetAgentid added in v0.4.0

func (w *Wxcom) GetAgentid() int

GetAgentid method get agentid from client.

func (*Wxcom) M added in v0.4.0

func (w *Wxcom) M() *Message

M method creates a new Message instance.

func (*Wxcom) NewMessage added in v0.4.0

func (w *Wxcom) NewMessage() *Message

NewMessage is an alias for method `M()`. Creates a new Message instance.

func (*Wxcom) NewOauth added in v0.5.0

func (w *Wxcom) NewOauth() *Oauth

NewOauth is an alias for method `O()`. Creates a new Oauth instance.

func (*Wxcom) O added in v0.5.0

func (w *Wxcom) O() *Oauth

O method creates a new Oauth instance.

Jump to

Keyboard shortcuts

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