checkin.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package checkin
  2. import (
  3. "fmt"
  4. "github.com/silenceper/wechat/v2/util"
  5. )
  6. const (
  7. // setScheduleListURL 为打卡人员排班
  8. setScheduleListURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/setcheckinschedulist?access_token=%s"
  9. // punchCorrectionURL 为打卡人员补卡
  10. punchCorrectionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/punch_correction?access_token=%s"
  11. // addUserFaceURL 录入打卡人员人脸信息
  12. addUserFaceURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/addcheckinuserface?access_token=%s"
  13. // addOptionURL 创建打卡规则
  14. addOptionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/add_checkin_option?access_token=%s"
  15. // updateOptionURL 修改打卡规则
  16. updateOptionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/update_checkin_option?access_token=%s"
  17. // clearOptionURL 清空打卡规则数组元素
  18. clearOptionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/clear_checkin_option_array_field?access_token=%s"
  19. // delOptionURL 删除打卡规则
  20. delOptionURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/del_checkin_option?access_token=%s"
  21. )
  22. // SetScheduleListRequest 为打卡人员排班请求
  23. type SetScheduleListRequest struct {
  24. GroupID int64 `json:"groupid"`
  25. Items []SetScheduleListItem `json:"items"`
  26. YearMonth int64 `json:"yearmonth"`
  27. }
  28. // SetScheduleListItem 排班表信息
  29. type SetScheduleListItem struct {
  30. UserID string `json:"userid"`
  31. Day int64 `json:"day"`
  32. ScheduleID int64 `json:"schedule_id"`
  33. }
  34. // SetScheduleList 为打卡人员排班
  35. // see https://developer.work.weixin.qq.com/document/path/93385
  36. func (r *Client) SetScheduleList(req *SetScheduleListRequest) error {
  37. var (
  38. accessToken string
  39. err error
  40. )
  41. if accessToken, err = r.GetAccessToken(); err != nil {
  42. return err
  43. }
  44. var response []byte
  45. if response, err = util.PostJSON(fmt.Sprintf(setScheduleListURL, accessToken), req); err != nil {
  46. return err
  47. }
  48. return util.DecodeWithCommonError(response, "SetScheduleList")
  49. }
  50. // PunchCorrectionRequest 为打卡人员补卡请求
  51. type PunchCorrectionRequest struct {
  52. UserID string `json:"userid"`
  53. ScheduleDateTime int64 `json:"schedule_date_time"`
  54. ScheduleCheckinTime int64 `json:"schedule_checkin_time"`
  55. CheckinTime int64 `json:"checkin_time"`
  56. Remark string `json:"remark"`
  57. }
  58. // PunchCorrection 为打卡人员补卡
  59. // see https://developer.work.weixin.qq.com/document/path/95803
  60. func (r *Client) PunchCorrection(req *PunchCorrectionRequest) error {
  61. var (
  62. accessToken string
  63. err error
  64. )
  65. if accessToken, err = r.GetAccessToken(); err != nil {
  66. return err
  67. }
  68. var response []byte
  69. if response, err = util.PostJSON(fmt.Sprintf(punchCorrectionURL, accessToken), req); err != nil {
  70. return err
  71. }
  72. return util.DecodeWithCommonError(response, "PunchCorrection")
  73. }
  74. // AddUserFaceRequest 录入打卡人员人脸信息请求
  75. type AddUserFaceRequest struct {
  76. UserID string `json:"userid"`
  77. UserFace string `json:"userface"`
  78. }
  79. // AddUserFace 录入打卡人员人脸信息
  80. // see https://developer.work.weixin.qq.com/document/path/93378
  81. func (r *Client) AddUserFace(req *AddUserFaceRequest) error {
  82. var (
  83. accessToken string
  84. err error
  85. )
  86. if accessToken, err = r.GetAccessToken(); err != nil {
  87. return err
  88. }
  89. var response []byte
  90. if response, err = util.PostJSON(fmt.Sprintf(addUserFaceURL, accessToken), req); err != nil {
  91. return err
  92. }
  93. return util.DecodeWithCommonError(response, "AddUserFace")
  94. }
  95. // AddOptionRequest 创建打卡规则请求
  96. type AddOptionRequest struct {
  97. EffectiveNow bool `json:"effective_now,omitempty"`
  98. Group OptionGroupRule `json:"group,omitempty"`
  99. }
  100. // OptionGroupRule 打卡规则字段
  101. type OptionGroupRule struct {
  102. GroupID int64 `json:"groupid,omitempty"`
  103. GroupType int64 `json:"grouptype"`
  104. GroupName string `json:"groupname"`
  105. CheckinDate []OptionGroupRuleCheckinDate `json:"checkindate,omitempty"`
  106. SpeWorkdays []OptionGroupSpeWorkdays `json:"spe_workdays,omitempty"`
  107. SpeOffDays []OptionGroupSpeOffDays `json:"spe_offdays,omitempty"`
  108. SyncHolidays bool `json:"sync_holidays,omitempty"`
  109. NeedPhoto bool `json:"need_photo,omitempty"`
  110. NoteCanUseLocalPic bool `json:"note_can_use_local_pic,omitempty"`
  111. WifiMacInfos []OptionGroupWifiMacInfos `json:"wifimac_infos,omitempty"`
  112. LocInfos []OptionGroupLocInfos `json:"loc_infos,omitempty"`
  113. AllowCheckinOffWorkday bool `json:"allow_checkin_offworkday,omitempty"`
  114. AllowApplyOffWorkday bool `json:"allow_apply_offworkday,omitempty"`
  115. Range []OptionGroupRange `json:"range"`
  116. WhiteUsers []string `json:"white_users,omitempty"`
  117. Type int64 `json:"type,omitempty"`
  118. ReporterInfo OptionGroupReporterInfo `json:"reporterinfo,omitempty"`
  119. AllowApplyBkCnt int64 `json:"allow_apply_bk_cnt,omitempty"`
  120. AllowApplyBkDayLimit int64 `json:"allow_apply_bk_day_limit,omitempty"`
  121. BukaLimitNextMonth int64 `json:"buka_limit_next_month,omitempty"`
  122. OptionOutRange int64 `json:"option_out_range,omitempty"`
  123. ScheduleList []OptionGroupScheduleList `json:"schedulelist,omitempty"`
  124. OffWorkIntervalTime int64 `json:"offwork_interval_time,omitempty"`
  125. UseFaceDetect bool `json:"use_face_detect,omitempty"`
  126. OpenFaceLiveDetect bool `json:"open_face_live_detect,omitempty"`
  127. OtInfoV2 OptionGroupOtInfoV2 `json:"ot_info_v2,omitempty"`
  128. SyncOutCheckin bool `json:"sync_out_checkin,omitempty"`
  129. BukaRemind OptionGroupBukaRemind `json:"buka_remind,omitempty"`
  130. BukaRestriction int64 `json:"buka_restriction,omitempty"`
  131. SpanDayTime int64 `json:"span_day_time,omitempty"`
  132. StandardWorkDuration int64 `json:"standard_work_duration,omitempty"`
  133. }
  134. // OptionGroupRuleCheckinDate 固定时间上下班打卡时间
  135. type OptionGroupRuleCheckinDate struct {
  136. Workdays []int64 `json:"workdays"`
  137. CheckinTime []OptionGroupRuleCheckinTime `json:"checkintime"`
  138. FlexTime int64 `json:"flex_time"`
  139. AllowFlex bool `json:"allow_flex"`
  140. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  141. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  142. MaxAllowArriveEarly int64 `json:"max_allow_arrive_early"`
  143. MaxAllowArriveLate int64 `json:"max_allow_arrive_late"`
  144. LateRule OptionGroupLateRule `json:"late_rule"`
  145. }
  146. // OptionGroupRuleCheckinTime 工作日上下班打卡时间信息
  147. type OptionGroupRuleCheckinTime struct {
  148. TimeID int64 `json:"time_id"`
  149. WorkSec int64 `json:"work_sec"`
  150. OffWorkSec int64 `json:"off_work_sec"`
  151. RemindWorkSec int64 `json:"remind_work_sec"`
  152. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  153. AllowRest bool `json:"allow_rest"`
  154. RestBeginTime int64 `json:"rest_begin_time"`
  155. RestEndTime int64 `json:"rest_end_time"`
  156. EarliestWorkSec int64 `json:"earliest_work_sec"`
  157. LatestWorkSec int64 `json:"latest_work_sec"`
  158. EarliestOffWorkSec int64 `json:"earliest_off_work_sec"`
  159. LatestOffWorkSec int64 `json:"latest_off_work_sec"`
  160. NoNeedCheckOn bool `json:"no_need_checkon"`
  161. NoNeedCheckOff bool `json:"no_need_checkoff"`
  162. }
  163. // OptionGroupLateRule 晚走晚到时间规则信息
  164. type OptionGroupLateRule struct {
  165. OffWorkAfterTime int64 `json:"offwork_after_time"`
  166. OnWorkFlexTime int64 `json:"onwork_flex_time"`
  167. AllowOffWorkAfterTime int64 `json:"allow_offwork_after_time"`
  168. TimeRules []OptionGroupTimeRule `json:"timerules"`
  169. }
  170. // OptionGroupTimeRule 晚走晚到时间规则
  171. type OptionGroupTimeRule struct {
  172. OffWorkAfterTime int64 `json:"offwork_after_time"`
  173. OnWorkFlexTime int64 `json:"onwork_flex_time"`
  174. }
  175. // OptionGroupSpeWorkdays 特殊工作日
  176. type OptionGroupSpeWorkdays struct {
  177. Timestamp int64 `json:"timestamp"`
  178. Notes string `json:"notes"`
  179. CheckinTime []OptionGroupCheckinTime `json:"checkintime"`
  180. Type int64 `json:"type"`
  181. BegTime int64 `json:"begtime"`
  182. EndTime int64 `json:"endtime"`
  183. }
  184. // OptionGroupCheckinTime 特殊工作日的上下班打卡时间配置
  185. type OptionGroupCheckinTime struct {
  186. TimeID int64 `json:"time_id"`
  187. WorkSec int64 `json:"work_sec"`
  188. OffWorkSec int64 `json:"off_work_sec"`
  189. RemindWorkSec int64 `json:"remind_work_sec"`
  190. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  191. }
  192. // OptionGroupSpeOffDays 特殊非工作日
  193. type OptionGroupSpeOffDays struct {
  194. Timestamp int64 `json:"timestamp"`
  195. Notes string `json:"notes"`
  196. Type int64 `json:"type"`
  197. BegTime int64 `json:"begtime"`
  198. EndTime int64 `json:"endtime"`
  199. }
  200. // OptionGroupWifiMacInfos WIFI 信息
  201. type OptionGroupWifiMacInfos struct {
  202. WifiName string `json:"wifiname"`
  203. WifiMac string `json:"wifimac"`
  204. }
  205. // OptionGroupLocInfos 地点信息
  206. type OptionGroupLocInfos struct {
  207. Lat int64 `json:"lat"`
  208. Lng int64 `json:"lng"`
  209. LocTitle string `json:"loc_title"`
  210. LocDetail string `json:"loc_detail"`
  211. Distance int64 `json:"distance"`
  212. }
  213. // OptionGroupRange 人员信息
  214. type OptionGroupRange struct {
  215. PartyID []string `json:"party_id"`
  216. UserID []string `json:"userid"`
  217. TagID []int64 `json:"tagid"`
  218. }
  219. // OptionGroupReporterInfo 汇报人
  220. type OptionGroupReporterInfo struct {
  221. Reporters []OptionGroupReporters `json:"reporters"`
  222. }
  223. // OptionGroupReporters 汇报对象
  224. type OptionGroupReporters struct {
  225. UserID string `json:"userid"`
  226. TagID int64 `json:"tagid"`
  227. }
  228. // OptionGroupScheduleList 自定义排班规则所有排班
  229. type OptionGroupScheduleList struct {
  230. ScheduleID int64 `json:"schedule_id"`
  231. ScheduleName string `json:"schedule_name"`
  232. TimeSection []OptionGroupTimeSection `json:"time_section"`
  233. AllowFlex bool `json:"allow_flex"`
  234. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  235. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  236. LateRule OptionGroupLateRule `json:"late_rule"`
  237. MaxAllowArriveEarly int64 `json:"max_allow_arrive_early"`
  238. MaxAllowArriveLate int64 `json:"max_allow_arrive_late"`
  239. }
  240. // OptionGroupTimeSection 班次上下班时段信息
  241. type OptionGroupTimeSection struct {
  242. TimeID int64 `json:"time_id"`
  243. WorkSec int64 `json:"work_sec"`
  244. OffWorkSec int64 `json:"off_work_sec"`
  245. RemindWorkSec int64 `json:"remind_work_sec"`
  246. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  247. RestBeginTime int64 `json:"rest_begin_time"`
  248. RestEndTime int64 `json:"rest_end_time"`
  249. AllowRest bool `json:"allow_rest"`
  250. EarliestWorkSec int64 `json:"earliest_work_sec"`
  251. LatestWorkSec int64 `json:"latest_work_sec"`
  252. EarliestOffWorkSec int64 `json:"earliest_off_work_sec"`
  253. LatestOffWorkSec int64 `json:"latest_off_work_sec"`
  254. NoNeedCheckOn bool `json:"no_need_checkon"`
  255. NoNeedCheckOff bool `json:"no_need_checkoff"`
  256. }
  257. // OptionGroupOtInfoV2 加班配置
  258. type OptionGroupOtInfoV2 struct {
  259. WorkdayConf OptionGroupWorkdayConf `json:"workdayconf"`
  260. }
  261. // OptionGroupWorkdayConf 工作日加班配置
  262. type OptionGroupWorkdayConf struct {
  263. AllowOt bool `json:"allow_ot"`
  264. Type int64 `json:"type"`
  265. }
  266. // OptionGroupBukaRemind 补卡提醒
  267. type OptionGroupBukaRemind struct {
  268. OpenRemind bool `json:"open_remind"`
  269. BukaRemindDay int64 `json:"buka_remind_day"`
  270. BukaRemindMonth int64 `json:"buka_remind_month"`
  271. }
  272. // AddOption 创建打卡规则
  273. // see https://developer.work.weixin.qq.com/document/path/98041#%E5%88%9B%E5%BB%BA%E6%89%93%E5%8D%A1%E8%A7%84%E5%88%99
  274. func (r *Client) AddOption(req *AddOptionRequest) error {
  275. var (
  276. accessToken string
  277. err error
  278. )
  279. if accessToken, err = r.GetAccessToken(); err != nil {
  280. return err
  281. }
  282. var response []byte
  283. if response, err = util.PostJSON(fmt.Sprintf(addOptionURL, accessToken), req); err != nil {
  284. return err
  285. }
  286. return util.DecodeWithCommonError(response, "AddOption")
  287. }
  288. // UpdateOptionRequest 修改打卡规则请求
  289. type UpdateOptionRequest struct {
  290. EffectiveNow bool `json:"effective_now,omitempty"`
  291. Group OptionGroupRule `json:"group,omitempty"`
  292. }
  293. // UpdateOption 修改打卡规则
  294. // see https://developer.work.weixin.qq.com/document/path/98041#%E4%BF%AE%E6%94%B9%E6%89%93%E5%8D%A1%E8%A7%84%E5%88%99
  295. func (r *Client) UpdateOption(req *UpdateOptionRequest) error {
  296. var (
  297. accessToken string
  298. err error
  299. )
  300. if accessToken, err = r.GetAccessToken(); err != nil {
  301. return err
  302. }
  303. var response []byte
  304. if response, err = util.PostJSON(fmt.Sprintf(updateOptionURL, accessToken), req); err != nil {
  305. return err
  306. }
  307. return util.DecodeWithCommonError(response, "UpdateOption")
  308. }
  309. // ClearOptionRequest 清空打卡规则数组元素请求
  310. type ClearOptionRequest struct {
  311. GroupID int64 `json:"groupid"`
  312. ClearField []int64 `json:"clear_field"`
  313. EffectiveNow bool `json:"effective_now"`
  314. }
  315. // ClearOption 清空打卡规则数组元素
  316. // see https://developer.work.weixin.qq.com/document/path/98041#%E6%B8%85%E7%A9%BA%E6%89%93%E5%8D%A1%E8%A7%84%E5%88%99%E6%95%B0%E7%BB%84%E5%85%83%E7%B4%A0
  317. func (r *Client) ClearOption(req *ClearOptionRequest) error {
  318. var (
  319. accessToken string
  320. err error
  321. )
  322. if accessToken, err = r.GetAccessToken(); err != nil {
  323. return err
  324. }
  325. var response []byte
  326. if response, err = util.PostJSON(fmt.Sprintf(clearOptionURL, accessToken), req); err != nil {
  327. return err
  328. }
  329. return util.DecodeWithCommonError(response, "ClearOption")
  330. }
  331. // DelOptionRequest 删除打卡规则请求
  332. type DelOptionRequest struct {
  333. GroupID int64 `json:"groupid"`
  334. EffectiveNow bool `json:"effective_now"`
  335. }
  336. // DelOption 删除打卡规则
  337. // see https://developer.work.weixin.qq.com/document/path/98041#%E5%88%A0%E9%99%A4%E6%89%93%E5%8D%A1%E8%A7%84%E5%88%99
  338. func (r *Client) DelOption(req *DelOptionRequest) error {
  339. var (
  340. accessToken string
  341. err error
  342. )
  343. if accessToken, err = r.GetAccessToken(); err != nil {
  344. return err
  345. }
  346. var response []byte
  347. if response, err = util.PostJSON(fmt.Sprintf(delOptionURL, accessToken), req); err != nil {
  348. return err
  349. }
  350. return util.DecodeWithCommonError(response, "DelOption")
  351. }