| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package contact
- import (
- "dashoo.cn/opms_libary/plugin/dingtalk/base"
- "dashoo.cn/opms_libary/plugin/dingtalk/context"
- "encoding/json"
- "github.com/gogf/gf/frame/g"
- )
- const (
- QueryUserIdByPhoneUrl = "https://oapi.dingtalk.com/topapi/v2/user/getbymobile"
- QueryUserInfoByUserIdUrl = "https://oapi.dingtalk.com/topapi/v2/user/get"
- )
- //Contact 通讯录
- type Contact struct {
- base.Base
- }
- //NewContact init
- func NewContact(context *context.Context) *Contact {
- material := new(Contact)
- material.Context = context
- return material
- }
- func (c *Contact) QueryUserIdByPhone(phone string) (response QueryUserIdResponse) {
- body, _ := c.HTTPPostJSONWithAccessToken(QueryUserIdByPhoneUrl, g.Map{"mobile": phone})
- json.Unmarshal(body, &response)
- return response
- }
- func (c *Contact) QueryUserInfoByUserId(userid string) (response QueryUserInfoResponse) {
- body, _ := c.HTTPPostJSONWithAccessToken(QueryUserInfoByUserIdUrl, g.Map{"userid": userid})
- json.Unmarshal(body, &response)
- return response
- }
- func (c *Contact) QueryUserIdAndUnionidByPhone(phone string) (userId, Unionid string) {
- resp := c.QueryUserIdByPhone(phone)
- rresp := c.QueryUserInfoByUserId(resp.Result.Userid)
- userId = rresp.Result.Userid
- Unionid = rresp.Result.Unionid
- return
- }
|