You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 satır
1018B

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. )
  6. func getKfSendURL() (url string) {
  7. atk, _ := GetAccessToken()
  8. url = fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s", atk)
  9. return
  10. }
  11. type sendTxtMsg struct {
  12. ToUser string `json:"touser"`
  13. MsgType string `json:"msgtype"`
  14. Text struct {
  15. Content string `json:"content"`
  16. } `json:"text"`
  17. }
  18. func kfSendTxt(user, txt string) {
  19. u := getKfSendURL()
  20. s := sendTxtMsg{}
  21. s.MsgType = "text"
  22. s.Text.Content = txt
  23. s.ToUser = user
  24. j, _ := json.Marshal(s)
  25. postJSON(j, u)
  26. }
  27. type sendPicMsg struct {
  28. ToUser string `json:"touser"`
  29. MsgType string `json:"msgtype"`
  30. Image struct {
  31. MediaID string `json:"media_id"`
  32. } `json:"image"`
  33. }
  34. func kfSendPic(user, pic string) {
  35. mID := uploadImage(pic)
  36. kfSendPicByMediaID(user, mID)
  37. }
  38. func kfSendPicByMediaID(user, mediaID string) {
  39. u := getKfSendURL()
  40. s := sendPicMsg{}
  41. s.ToUser = user
  42. s.MsgType = "image"
  43. s.Image.MediaID = mediaID
  44. j, _ := json.Marshal(s)
  45. postJSON(j, u)
  46. }