contact.go 1002 B

12345678910111213141516171819202122232425262728293031323334353637
  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. }