wxoffice.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package notice
  2. import (
  3. "github.com/fastwego/offiaccount"
  4. "github.com/fastwego/offiaccount/apis/account"
  5. "github.com/fastwego/offiaccount/apis/message/template"
  6. "kpt.notice/pkg/log"
  7. )
  8. type wxMessage struct {
  9. MsgType string `json:"msgtype"`
  10. Content string `json:"content"`
  11. }
  12. var ServerAcc *offiaccount.OffiAccount = offiaccount.New(offiaccount.Config{
  13. Appid: "wxe1cc563ba393dd1a",
  14. Secret: "25e56243da9581eab6f4d67a12ef4658",
  15. Token: "123",
  16. EncodingAESKey: "6yYJ4sS5y1hJgvIXEqavV2rmCutyXkywndxUQFgX54f",
  17. })
  18. func CreateQRCode(sceneID string) []byte {
  19. // time limit in 3 days
  20. json := `{
  21. "action_name": "QR_SCENE",
  22. "expire_seconds":259200,
  23. "action_info": {
  24. "scene": {
  25. "scene_id":` + sceneID + `
  26. }
  27. }`
  28. resp, err := account.CreateQRCode(ServerAcc, []byte(json))
  29. if err != nil {
  30. log.Error(err)
  31. return nil
  32. }
  33. return resp
  34. }
  35. /*
  36. send tmp message to wx
  37. */
  38. func MsgTemplate(msg []byte) ([]byte, error) {
  39. return template.Send(ServerAcc, msg)
  40. }
  41. // func OfficeInit() {
  42. // if ServerAcc == nil {
  43. // ServerAcc = offiaccount.New(offiaccount.Config{
  44. // Appid: "wxe1cc563ba393dd1a",
  45. // Secret: "25e56243da9581eab6f4d67a12ef4658",
  46. // Token: "123",
  47. // EncodingAESKey: "6yYJ4sS5y1hJgvIXEqavV2rmCutyXkywndxUQFgX54f",
  48. // })
  49. // }
  50. // }