qy

package
v0.0.0-...-125b544 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package qy provides accesstoken fetch functions for wechat qy dev

Package qy provides encrpytmsg and decrpytmsg for qy wechat message.

Package qy provides menu create opertations.

Package qy provides functions for handling the received messages.

Index

Examples

Constants

View Source
const (
	// Msg type
	TextMsg     = "text"
	ImageMsg    = "image"
	VoiceMsg    = "voice"
	VideoMsg    = "video"
	LocationMsg = "location"
	EventMsg    = "event"

	// Event type
	SubscribeEvent       = "subscribe"
	UnsubscribeEvent     = "unsubscribe"
	LocationEvent        = "LOCATION"
	MenuClickEvent       = "click"
	MenuViewEvent        = "view"
	ScanCodePushEvent    = "scancode_push"
	ScanCodeWaitEvent    = "scancode_waitmsg"
	PicSysPhotoEvent     = "pic_sysphoto"
	PicPhotoOrAlbumEvent = "pic_photo_or_album"
	PicWeiXinEvent       = "pic_weixin"
	LocationSelectEvent  = "location_select"
	EnterAgentEvent      = "enter_agent"
)

Variables

This section is empty.

Functions

func CreateMenu

func CreateMenu(menuLayout []byte, accessToken, agentID string) error
Example
package main

import (
	"fmt"

	"github.com/bigwhite/gowechat/qy"
)

const (
	accessToken = "wx1234abcd"
	layout      = `{
	    "button": [
			{
				"name":"submenu1",
				"subbutton": [
				    {
						"name": "item1",
						"type":"click",
						"key":"s1-item1"
					},
				    {
						"name": "item2",
						"type":"click",
						"key":"s1-item2"
					}
				]
			},
			{
				"name":"submenu2",
				"subbutton": [
				    {
						"name": "item1",
						"type":"click",
						"key":"s2-item1"
					},
				    {
						"name": "item2",
						"type":"click",
						"key":"s2-item2"
					}
				]
			}
		]
} `
	agentID = "5"
)

func main() {
	err := qy.CreateMenu([]byte(layout), accessToken, agentID)
	fmt.Println(err)
}
Output:

https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token=wx1234abcd&agentid=5
invalid access_token

func DecryptMsg

func DecryptMsg(cipherText, encodingAESKey string) ([]byte, int, string, error)

DecryptMsg is used to decrpyt msg_encrypt in wechat qy request. it returns msg, msgLen, corpid, error. msg_encrypt = Base64_Encode( AES_Encrypt[random(16B) + msg_len(4B) + msg + $CorpID]).

func EncryptMsg

func EncryptMsg(msg []byte, corpID string, encodingAESKey string) (string, error)

EncryptMsg is used to encrpyt msg in wechat qy response or custom message. it returns msg_encrypt. msg_encrypt = Base64_Encode( AES_Encrypt[random(16B) + msg_len(4B) + msg + $CorpID]).

func FetchAccessToken

func FetchAccessToken(corpID, corpSecret string) (string, float64, error)

FetchAccessToken could be used to fetch access token for wechat qy dev.

func NewRecvHandler

func NewRecvHandler(corpID, token, encodingAESKey string) pb.RecvHandler

NewRecvHandler creates an instance of recvHandler which implements pb.RecvHandler interface.

func SendMsg

func SendMsg(accessToken string, pkg interface{}) error

func ValidateSignature

func ValidateSignature(signature, token, timestamp, nonce, msgEncrypt string) bool

ValidateSignature is used to validate the signature in request to figure out whether the http request come from wechat qy platform.

func ValidateURL

func ValidateURL(signature, token, timestamp, nonce, cipherEchoStr, encodingAESKey string) (bool, []byte)

Types

type Article

type Article struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Url         string `json:"url,omitempty"`
	PicUrl      string `json:"picurl,omitempty"`
}

type Articles

type Articles struct {
	Articles []Article `json:"articles"`
}

type RecvEnterAgentDataPkg

type RecvEnterAgentDataPkg struct {
	pb.RecvBaseDataPkg
	Event    string
	EventKey string
}

type RecvHTTPReqBody

type RecvHTTPReqBody struct {
	ToUserName string
	AgentID    string
	Encrypt    string
}

RecvHTTPReqBody is a unmarshall result for below xml data: <xml>

<ToUserName><![CDATA[toUser]]</ToUserName>
<AgentID><![CDATA[toAgentID]]</AgentID>
<Encrypt><![CDATA[msg_encrypt]]</Encrypt>

</xml>

type RecvHTTPRespBody

type RecvHTTPRespBody struct {
	XMLName      xml.Name `xml:"xml"`
	Encrypt      pb.CDATAText
	MsgSignature pb.CDATAText
	TimeStamp    int
	Nonce        pb.CDATAText
}

RecvHTTPResqBody is a source for marshalling below xml data: <xml>

<Encrypt><![CDATA[msg_encrypt]]></Encrypt>
<MsgSignature><![CDATA[msg_signature]]></MsgSignature>
<TimeStamp>timestamp</TimeStamp>
<Nonce><![CDATA[nonce]]></Nonce>

</xml>

type RecvImageDataPkg

type RecvImageDataPkg struct {
	pb.RecvBaseDataPkg
	PicURL  string `xml:"PicUrl"`
	MediaID string `xml:"MediaId"`
	MsgID   uint64 `xml:"MsgId"`
	AgentID int
}

RecvImageDataPkg is a Image Message received from wechat platform.

type RecvLocationDataPkg

type RecvLocationDataPkg struct {
	pb.RecvBaseDataPkg
	LocX    float64 `xml:"Location_X"`
	LocY    float64 `xml:"Location_Y"`
	Scale   int
	Label   string
	MsgID   uint64 `xml:"MsgId"`
	AgentID int
}

RecvLocationDataPkg is a Location Message received from wechat platform.

type RecvLocationEventDataPkg

type RecvLocationEventDataPkg struct {
	pb.RecvBaseDataPkg
	Event     string
	Latitude  float64
	Longitude float64
	Precision float64
	AgentID   int
}

RecvLocationEventDataPkg is a Location event Message received from wechat platform.

type RecvMenuEventDataPkg

type RecvMenuEventDataPkg struct {
	pb.RecvBaseDataPkg
	Event    string
	EventKey string
	AgentID  int
}

RecvMenuEventDataPkg is a Menu Click event Message received from wechat platform.

type RecvRespTextDataPkg

type RecvRespTextDataPkg struct {
	pb.RecvRespBaseDataPkg
	Content pb.CDATAText
}

type RecvSubscribeEventDataPkg

type RecvSubscribeEventDataPkg struct {
	pb.RecvBaseDataPkg
	Event   string
	AgentID int
}

RecvSubscribeEventDataPkg is a Subscribe/Unsubscribe event Message received from wechat platform.

type RecvTextDataPkg

type RecvTextDataPkg struct {
	pb.RecvBaseDataPkg
	Content string
	MsgID   uint64 `xml:"MsgId"`
	AgentID int
}

RecvTextDataPkg is a Text Message received from wechat platform.

type RecvVideoDataPkg

type RecvVideoDataPkg struct {
	pb.RecvBaseDataPkg
	MediaID      string `xml:"MediaId"`
	ThumbMediaID string `xml:"ThumbMediaId"`
	MsgID        uint64 `xml:"MsgId"`
	AgentID      int
}

RecvVideoDataPkg is a Video Message received from wechat platform.

type RecvVoiceDataPkg

type RecvVoiceDataPkg struct {
	pb.RecvBaseDataPkg
	MediaID string `xml:"MediaId"`
	Format  string
	MsgID   uint64 `xml:"MsgId"`
	AgentID int
}

RecvVoiceDataPkg is a Voice Message received from wechat platform.

type SendMsgImagePkg

type SendMsgImagePkg struct {
	pb.SendMsgImagePkg
	ToParty string `json:"toparty,omitempty"`
	ToTag   string `json:"totag,omitempty"`
	AgentID string `json:"agentid"`
	Safe    string `json:"safe,omitempty"`
}

type SendMsgNewsPkg

type SendMsgNewsPkg struct {
	ToUserName string   `json:"touser"`
	ToParty    string   `json:"toparty,omitempty"`
	ToTag      string   `json:"totag,omitempty"`
	MsgType    string   `json:"msgtype"`
	AgentID    string   `json:"agentid"`
	News       Articles `json:"news"`
}

type SendMsgTextPkg

type SendMsgTextPkg struct {
	pb.SendMsgTextPkg
	ToParty string `json:"toparty,omitempty"`
	ToTag   string `json:"totag,omitempty"`
	AgentID string `json:"agentid"`
	Safe    string `json:"safe,omitempty"`
}

Jump to

Keyboard shortcuts

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