package main import ( "encoding/json" "fmt" ) func getKfSendURL() (url string) { atk, _ := GetAccessToken() url = fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s", atk) return } type sendTxtMsg struct { ToUser string `json:"touser"` MsgType string `json:"msgtype"` Text struct { Content string `json:"content"` } `json:"text"` } func kfSendTxt(user, txt string) { u := getKfSendURL() s := sendTxtMsg{} s.MsgType = "text" s.Text.Content = txt s.ToUser = user j, _ := json.Marshal(s) postJSON(j, u) } type sendPicMsg struct { ToUser string `json:"touser"` MsgType string `json:"msgtype"` Image struct { MediaID string `json:"media_id"` } `json:"image"` } func kfSendPic(user, pic string) { mID := uploadImage(pic) kfSendPicByMediaID(user, mID) } func kfSendPicByMediaID(user, mediaID string) { u := getKfSendURL() s := sendPicMsg{} s.ToUser = user s.MsgType = "image" s.Image.MediaID = mediaID j, _ := json.Marshal(s) postJSON(j, u) }