From d74c2284cf4459f2c54ed024b7edba1f4e478385 Mon Sep 17 00:00:00 2001 From: jiangyong Date: Tue, 10 Mar 2026 21:55:32 +0800 Subject: [PATCH] contract --- qyweixin/app_hr.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/qyweixin/app_hr.go b/qyweixin/app_hr.go index 55d2929..8e3ae30 100644 --- a/qyweixin/app_hr.go +++ b/qyweixin/app_hr.go @@ -15,6 +15,7 @@ var ( urlQyWeixinHrGetStaffInfo = "https://qyapi.weixin.qq.com/cgi-bin/hr/get_staff_info" urlQyWeixinHrGetDepartment = "https://qyapi.weixin.qq.com/cgi-bin/department/list" urlQyWeixinHrGetDepartmentUser = "https://qyapi.weixin.qq.com/cgi-bin/user/list" + urlQyWeixinHrGetContactInfo = "https://qyapi.weixin.qq.com/cgi-bin/user/get" ) type AppHr struct { @@ -44,12 +45,39 @@ type StaffInfo struct { BankCard string } +type ContactInfo struct { + Realname string + DirectLeader []string + DepartmentId []int64 + IsDepartmentLeader []int +} + func NewAppHr(cfg *AppConfig) *AppHr { return &AppHr{ App: *NewApp(cfg), } } +func (h *AppHr) GetContactInfo(userId string) (*ContactInfo, error) { + reqUrl := fmt.Sprintf("%s?access_token=%s", urlQyWeixinHrGetContactInfo, h.GetToken()) + reqBody := make(map[string]interface{}) + reqBody["userid"] = userId + rspBody, err := util.HttpPostJson(reqUrl, nil, []byte(goutil.EncodeJSON(reqBody))) + if err != nil { + return nil, err + } + contract := new(ContactInfo) + result, err := h.GetResult(rspBody) + if err != nil { + return nil, err + } + contract.Realname = cast.ToString(result["name"]) + contract.DirectLeader = cast.ToStringSlice(result["direct_leader"]) + contract.DepartmentId = cast.ToInt64Slice(result["department"]) + contract.IsDepartmentLeader = cast.ToIntSlice(result["is_leader_in_dept"]) + return contract, nil +} + func (h *AppHr) GetStaffInfo(userId string) (*StaffInfo, error) { reqUrl := fmt.Sprintf("%s?access_token=%s", urlQyWeixinHrGetStaffInfo, h.GetToken()) reqBody := make(map[string]interface{})