contact.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package contact
  2. import (
  3. "dashoo.cn/opms_libary/plugin/dingtalk/base"
  4. "dashoo.cn/opms_libary/plugin/dingtalk/context"
  5. "encoding/json"
  6. "github.com/gogf/gf/frame/g"
  7. )
  8. const (
  9. QueryUserIdByPhoneUrl = "https://oapi.dingtalk.com/topapi/v2/user/getbymobile"
  10. QueryUserInfoByUserIdUrl = "https://oapi.dingtalk.com/topapi/v2/user/get"
  11. )
  12. //Contact 通讯录
  13. type Contact struct {
  14. base.Base
  15. }
  16. //NewContact init
  17. func NewContact(context *context.Context) *Contact {
  18. material := new(Contact)
  19. material.Context = context
  20. return material
  21. }
  22. func (c *Contact) QueryUserIdByPhone(phone string) (response QueryUserIdResponse) {
  23. body, _ := c.HTTPPostJSONWithAccessToken(QueryUserIdByPhoneUrl, g.Map{"mobile": phone})
  24. json.Unmarshal(body, &response)
  25. return response
  26. }
  27. func (c *Contact) QueryUserInfoByUserId(userid string) (response QueryUserInfoResponse) {
  28. body, _ := c.HTTPPostJSONWithAccessToken(QueryUserInfoByUserIdUrl, g.Map{"userid": userid})
  29. json.Unmarshal(body, &response)
  30. return response
  31. }
  32. func (c *Contact) QueryUserIdAndUnionidByPhone(phone string) (userId, Unionid string) {
  33. resp := c.QueryUserIdByPhone(phone)
  34. rresp := c.QueryUserInfoByUserId(resp.Result.Userid)
  35. userId = rresp.Result.Userid
  36. Unionid = rresp.Result.Unionid
  37. return
  38. }