bingo_wx

package module
v0.0.0-...-d10c483 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 16 Imported by: 0

README

bingo_wx

微信公众号、企业微信快速开发框架,无需熟悉微信的接口规范就可以快速对接现有的业务。基于bingo
包括

  • 微信公众号
  • 企业微信
  • 新增了 apiv3

api v3 的使用

导入包
import (
 "github.com/aosfather/bingo_wx/apiv3"
)

构建api v3 sdk

apiv3 需要服务商商户私钥加密信息和微信平台沟通

api:=apiv3.ApiV3{}
api.MerchantId="服务商商户号"
//读取私钥
pk,err:=ioutil.ReadFile("e:/opt/私钥.pem")
	if err!=nil {
		t.Error("私钥没找到")
	}
//读取平台公钥如果有的话
fpub,err:=ioutil.ReadFile("e:/opt/平台公钥.cert")
	if err!=nil {
		t.Error("没有公钥")
	}
//设置私钥编号和私钥内容,编号在下载的界面有
api.SetMerchantKey("EDFA23343",pk))
//设置私钥编号和私钥内容,编号在下载的界面有
api.SetFlatKey("PEDFA23343",fpub))

开始使用sdk 调用相应的接口

现在apiv3包中有两个通用的方法对应Get和Post请求,DoGet,DoPost。
除此之外apiv3包还封装了和实名认证申请相关的接口。例如下面的“查询商户实名状态的”

//调用查询商户实名状态的接口
apiv3.MerchantApplymentState(api,"xxxxxxxxxx")
sdk提供了下载平台公钥的接口

apiv3接口中提供了下载平台公钥的方法,前提是需要设置api v3的密钥,这个在微信商户后台设置的。

//指明下载保存的文件名,会将下载更新的平台秘钥写入该文件,包括秘钥编号
api.DownloadFlatPublicKey("/opt/xx_cert.txt")

Documentation

Index

Constants

View Source
const (
	EVENT_SUB      = "subscribe"   //订阅
	EVENT_UNSUB    = "unsubscribe" //取消订阅
	EVENT_SCAN     = "SCAN"        //扫描
	EVENT_LOCATION = "LOCATION"    //地址
	EVENT_CLICK    = "CLICK"       //点击
	EVENT_VIEW     = "VIEW"        //跳转

	//消息类型
	MSGTYPE_TEXT        = "text"
	MSGTYPE_IMAGE       = "image"
	MSGTYPE_VIDEO       = "video"
	MSGTYPE_SHORT_VIDEO = "shortvideo"
	MSGTYPE_VOICE       = "voice"
	MSGTYPE_LOCATION    = "location"
	MSGTYPE_LINK        = "link"
	MSGTYPE_EVENT       = "event"
)

事件类型

View Source
const (
	Text     = "text"
	Location = "location"
	Image    = "image"
	Link     = "link"
	Event    = "event"
	Music    = "music"
	News     = "news"
	Voice    = "voice"
	Video    = "video"
)
View Source
const AccessTokenURL = "https://api.weixin.qq.com/cgi-bin/token"

Variables

View Source
var (
	CHARS []byte = []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
)

Functions

func BytesOrderToNumber

func BytesOrderToNumber(orderBytes []byte) int

还原4个字节的网络字节序

func GetCurrTs

func GetCurrTs() int64

GetCurrTs return current timestamps

func HTTPGet

func HTTPGet(uri string) ([]byte, error)

HTTPGet get 请求

func NumberToBytesOrder

func NumberToBytesOrder(number int) []byte

---------------协议算法------------------// 生成4个字节的网络字节序

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

---------------------------PKCS7-----------------------------//

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte, blockSize int) []byte

func RandomStr

func RandomStr(length int) string

RandomStr 随机生成字符串

func Signature

func Signature(params ...string) string

Signature sha1签名

Types

type AES

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

func (*AES) Init

func (this *AES) Init(key []byte)

type BaseEncrypt

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

Encrypt

func (*BaseEncrypt) DecryptInputMsg

func (this *BaseEncrypt) DecryptInputMsg(msg_signature, timestamp, nonce string, postdata WxEncryptInputMessage) (int, string)

机密消息

func (*BaseEncrypt) EncryptMsg

func (this *BaseEncrypt) EncryptMsg(replyMsg, nonce, timestamp string) (int, string)

加密消息

func (*BaseEncrypt) Init

func (this *BaseEncrypt) Init(token, appid, aeskey string)

func (*BaseEncrypt) VerifyURL

func (this *BaseEncrypt) VerifyURL(msg_signature, echostr string, paramters ...string) bool

type JsSigner

type JsSigner struct {
	mvc.SimpleController
	App        *WxApplication
	DefaultStr string
}

func (*JsSigner) Get

func (this *JsSigner) Get(c mvc.Context, p interface{}) (interface{}, mvc.BingoError)

func (*JsSigner) GetConfig

func (this *JsSigner) GetConfig(uri string) (config *jsConfig, err error)

GetConfig 获取jssdk需要的配置参数 uri 为当前网页地址

func (*JsSigner) GetParameType

func (this *JsSigner) GetParameType(method string) interface{}

type ResAccessToken

type ResAccessToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
	// contains filtered or unexported fields
}

ResAccessToken struct

type WxApplication

type WxApplication struct {
	AppID      string
	Ticket     *resTicket
	AppSecret  string
	UpdateTime time.Time
}

func (*WxApplication) GetAccessToken

func (this *WxApplication) GetAccessToken() (accessToken string, err error)

func (*WxApplication) GetAccessTokenFromServer

func (this *WxApplication) GetAccessTokenFromServer() (resAccessToken ResAccessToken, err error)

GetAccessTokenFromServer 强制从微信服务器获取token

func (*WxApplication) GetTicket

func (this *WxApplication) GetTicket() (ticketStr string, err error)

GetTicket 获取jsapi_tocket

type WxArticleMsg

type WxArticleMsg struct {
	ArticleCount int            `xml:",omitempty"`
	Articles     []*articleItem `xml:"Articles>item,omitempty"`
	// contains filtered or unexported fields
}

func (*WxArticleMsg) AddArticle

func (this *WxArticleMsg) AddArticle(title, desc, picurl, url string)

func (*WxArticleMsg) Init

func (this *WxArticleMsg) Init(w *WxMessageBody)

type WxEncryptInputMessage

type WxEncryptInputMessage struct {
	XMLName    xml.Name `xml:"xml"`
	ToUserName string
	AppId      string
	Encrypt    string
}

输入的加密消息

type WxEncryptOutputMessage

type WxEncryptOutputMessage struct {
	XMLName      xml.Name `xml:"xml"`
	Encrypt      string
	MsgSignature string
	TimeStamp    string
	Nonce        string
}

输出的加密消息

type WxImageMsg

type WxImageMsg struct {
	Image string `xml:"Image>MediaId"`
	// contains filtered or unexported fields
}

func (*WxImageMsg) Init

func (this *WxImageMsg) Init(w *WxMessageBody)

func (*WxImageMsg) SetBody

func (this *WxImageMsg) SetBody(image string)

type WxMessage

type WxMessage struct {
	WxRequest
	// contains filtered or unexported fields
}

func (*WxMessage) GetData

func (this *WxMessage) GetData() interface{}

func (*WxMessage) GetDataType

func (this *WxMessage) GetDataType() string

type WxMessageBody

type WxMessageBody struct {
	XMLName xml.Name `xml:"xml"`

	Content  string //文本内容
	Event    string //当类型为Event时候有值,事件类型:subscribe(订阅)、unsubscribe(取消订阅)、自定义菜单事件CLICK、上报位置LOCATION、用户已关注时的事件推送SCAN、菜单跳转VIEW
	EventKey string //CLICK事件KEY值,与自定义菜单接口中KEY值对应
	//为通过二维码订阅的时候事件为subscribe事件KEY值,qrscene_为前缀,后面为二维码的参数值
	Ticket                 string  //二维码的ticket,可用来换取二维码图片
	Latitude               float32 //LOCATION地理位置纬度
	Longitude              float32 //LOCATION地理位置经度
	Precision              float32 //LOCATION地理位置精度
	Location_X, Location_Y float32 //地理位置维度,地理位置经度
	Scale                  int     //地图缩放大小
	Label                  string  //地理位置信息
	PicUrl                 string  //图片地址
	Format                 string  //语音格式,如amr,speex等
	Recognition            string  //语音识别结果,UTF8编码
	MediaId                string  //图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
	ThumbMediaId           string  //视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。
	Title                  string  //link消息标题
	Description            string  //link消息描述
	Url                    string  //link消息链接
	MsgId                  int     //消息id,64位整型
	// contains filtered or unexported fields
}

type WxMusicMsg

type WxMusicMsg struct {
	Music music
	// contains filtered or unexported fields
}

func (*WxMusicMsg) Init

func (this *WxMusicMsg) Init(w *WxMessageBody)

func (*WxMusicMsg) SetBody

func (this *WxMusicMsg) SetBody(title, desc, murl, hqurl, mediaid string)

type WxRequest

type WxRequest struct {
	Timestamp string `Field:"timestamp"`
	Nonce     string `Field:"nonce"`
	Signature string `Field:"signature"`
	Echostr   string `Field:"echostr"`
}

type WxResponse

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

type WxTextMsg

type WxTextMsg struct {
	Content string
	// contains filtered or unexported fields
}

func (*WxTextMsg) Init

func (this *WxTextMsg) Init(w *WxMessageBody)

func (*WxTextMsg) SetBody

func (this *WxTextMsg) SetBody(text string)

type WxVideoMsg

type WxVideoMsg struct {
	Video video
	// contains filtered or unexported fields
}

func (*WxVideoMsg) Init

func (this *WxVideoMsg) Init(w *WxMessageBody)

func (*WxVideoMsg) SetBody

func (this *WxVideoMsg) SetBody(video string)

type WxVoiceMsg

type WxVoiceMsg struct {
	Voice string `xml:"Voice>MediaId"`
	// contains filtered or unexported fields
}

func (*WxVoiceMsg) Init

func (this *WxVoiceMsg) Init(w *WxMessageBody)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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