Documentation ¶
Index ¶
- Constants
- Variables
- func AddRoute(g *gin.Engine)
- func CheckSignature(c *gin.Context)
- func GetAccessToken() (accessToken string, err error)
- func HandleRequest(c *gin.Context)
- func SendWechatmpMessageToUser(message WechatmpMessage) error
- func ServeFlag(serveCmd *cobra.Command)
- type AccessToken
- type LLMInstance
- type Signature
- type WechatmpMessage
Constants ¶
View Source
const ( ID = "wechatmp" Comment = "[module] wechatmp api service" RoutePrefix = "/" DefaultEnable = false )
Variables ¶
View Source
var Module = module.Module{ ID: ID, Comment: Comment, RouteFunc: AddRoute, RoutePrefix: RoutePrefix, FlagFunc: ServeFlag, }
Functions ¶
func CheckSignature ¶
func GetAccessToken ¶
GetAccessToken 获取 access_token
func HandleRequest ¶
func SendWechatmpMessageToUser ¶
func SendWechatmpMessageToUser(message WechatmpMessage) error
公众号发送普通文本消息(由于没有认证公众号,暂时未测试)
Types ¶
type AccessToken ¶
var ( // 存储消息 MsgContext = gmap.New() // 存储 access_token,用于请求订阅号 api WechatmpAccessToken AccessToken )
type LLMInstance ¶
type LLMInstance interface { Ask(question string) (answer string, err error) SetModelName(name string) SetModelEndpoint(endpoint string) SetModelPrompt(prompt string) SetSafetyMode(enabled bool) }
var LLM LLMInstance
type Signature ¶
type Signature struct { Signature string `json:"signature" form:"signature" xml:"signature" validate:"required"` Timestamp string `json:"timestamp" form:"timestamp" xml:"timestamp" validate:"required"` Nonce string `json:"nonce" form:"nonce" xml:"nonce" validate:"required"` Echostr string `json:"echostr" form:"echostr" xml:"echostr" ` Openid string `json:"openid" form:"openid" xml:"openid" ` Encrtpt_type string `json:"encrtpt_type" form:"encrtpt_type" xml:"encrtpt_type" ` Msg_signature string `json:"msg_signature" form:"msg_signature" xml:"msg_signature" ` }
signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。 timestamp 时间戳 nonce 随机数 echostr 随机字符串
type WechatmpMessage ¶
type WechatmpMessage struct { XMLName xml.Name `json:"-" xml:"xml"` // 指定 xml 根标签 ToUserName string `json:"ToUserName" xml:"ToUserName"` FromUserName string `json:"FromUserName" xml:"FromUserName"` CreateTime int64 `json:"CreateTime" xml:"CreateTime"` MsgType string `json:"MsgType" xml:"MsgType"` // event, text, image, voice, video, shortvideo, location, link // event Event string `json:"Event" xml:"Event"` // subscribe, unsubscribe, SCAN, LOCATION, CLICK, VIEW EventKey string `json:"EventKey" xml:"EventKey"` // 事件KEY值,qrscene_为前缀,后面为二维码的参数值,或者与自定义菜单接口中KEY值对应 // text Content string `json:"Content" xml:"Content"` MsgId int64 `json:"MsgId" xml:"MsgId"` MediaId string `json:"MediaId" xml:"MediaId"` // image, voice, video, shortvideo // image PicUrl string `json:"PicUrl" xml:"PicUrl"` // voice Format string `json:"Format" xml:"Format"` // amr, speex // video shortvideo ThumbMediaId string `json:"ThumbMediaId" xml:"ThumbMediaId"` // location Location_X float64 `json:"Location_X" xml:"Location_X"` Location_Y float64 `json:"Location_Y" xml:"Location_Y"` Scale int64 `json:"Scale" xml:"Scale"` Label string `json:"Label" xml:"Label"` // link Title string `json:"Title" xml:"Title"` Description string `json:"Description" xml:"Description"` URL string `json:"URL" xml:"URL"` }
微信公众号消息结构体
func (*WechatmpMessage) HandleEvent ¶
func (m *WechatmpMessage) HandleEvent() (reply string, err error)
处理消息事件
func (*WechatmpMessage) HandleText ¶
func (m *WechatmpMessage) HandleText() (reply string, err error)
处理文本消息
func (*WechatmpMessage) ReplyTextMessage ¶
func (message *WechatmpMessage) ReplyTextMessage() (reply string, err error)
构造回复消息 - 文本消息
Source Files ¶
Click to show internal directories.
Click to hide internal directories.