選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

81 行
1.5KB

  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. }
  47. type sendVoiceMsg struct {
  48. ToUser string `json:"touser"`
  49. MsgType string `json:"msgtype"`
  50. Voice struct {
  51. MediaID string `json:"media_id"`
  52. } `json:"voice"`
  53. }
  54. func kfSendVoice(user, path string) {
  55. mID := uploadVoice(path)
  56. kfSendVoiceByMediaID(user, mID)
  57. }
  58. func kfSendVoiceByMediaID(user, mediaID string) {
  59. u := getKfSendURL()
  60. s := sendVoiceMsg{}
  61. s.ToUser = user
  62. s.MsgType = "voice"
  63. s.Voice.MediaID = mediaID
  64. j, _ := json.Marshal(s)
  65. postJSON(j, u)
  66. }