checkin.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. CheckinMethodType int64 `json:"checkin_method_type,omitempty"`
  132. SpanDayTime int64 `json:"span_day_time,omitempty"`
  133. StandardWorkDuration int64 `json:"standard_work_duration,omitempty"`
  134. }
  135. // OptionGroupRuleCheckinDate 固定时间上下班打卡时间
  136. type OptionGroupRuleCheckinDate struct {
  137. Workdays []int64 `json:"workdays"`
  138. CheckinTime []OptionGroupRuleCheckinTime `json:"checkintime"`
  139. FlexTime int64 `json:"flex_time"`
  140. AllowFlex bool `json:"allow_flex"`
  141. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  142. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  143. MaxAllowArriveEarly int64 `json:"max_allow_arrive_early"`
  144. MaxAllowArriveLate int64 `json:"max_allow_arrive_late"`
  145. LateRule OptionGroupLateRule `json:"late_rule"`
  146. }
  147. // OptionGroupRuleCheckinTime 工作日上下班打卡时间信息
  148. type OptionGroupRuleCheckinTime struct {
  149. TimeID int64 `json:"time_id"`
  150. WorkSec int64 `json:"work_sec"`
  151. OffWorkSec int64 `json:"off_work_sec"`
  152. RemindWorkSec int64 `json:"remind_work_sec"`
  153. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  154. AllowRest bool `json:"allow_rest"`
  155. RestBeginTime int64 `json:"rest_begin_time"`
  156. RestEndTime int64 `json:"rest_end_time"`
  157. EarliestWorkSec int64 `json:"earliest_work_sec"`
  158. LatestWorkSec int64 `json:"latest_work_sec"`
  159. EarliestOffWorkSec int64 `json:"earliest_off_work_sec"`
  160. LatestOffWorkSec int64 `json:"latest_off_work_sec"`
  161. NoNeedCheckOn bool `json:"no_need_checkon"`
  162. NoNeedCheckOff bool `json:"no_need_checkoff"`
  163. }
  164. // OptionGroupLateRule 晚走晚到时间规则信息
  165. type OptionGroupLateRule struct {
  166. OffWorkAfterTime int64 `json:"offwork_after_time"`
  167. OnWorkFlexTime int64 `json:"onwork_flex_time"`
  168. AllowOffWorkAfterTime int64 `json:"allow_offwork_after_time"`
  169. TimeRules []OptionGroupTimeRule `json:"timerules"`
  170. }
  171. // OptionGroupTimeRule 晚走晚到时间规则
  172. type OptionGroupTimeRule struct {
  173. OffWorkAfterTime int64 `json:"offwork_after_time"`
  174. OnWorkFlexTime int64 `json:"onwork_flex_time"`
  175. }
  176. // OptionGroupSpeWorkdays 特殊工作日
  177. type OptionGroupSpeWorkdays struct {
  178. Timestamp int64 `json:"timestamp"`
  179. Notes string `json:"notes"`
  180. CheckinTime []OptionGroupCheckinTime `json:"checkintime"`
  181. Type int64 `json:"type"`
  182. BegTime int64 `json:"begtime"`
  183. EndTime int64 `json:"endtime"`
  184. }
  185. // OptionGroupCheckinTime 特殊工作日的上下班打卡时间配置
  186. type OptionGroupCheckinTime struct {
  187. TimeID int64 `json:"time_id"`
  188. WorkSec int64 `json:"work_sec"`
  189. OffWorkSec int64 `json:"off_work_sec"`
  190. RemindWorkSec int64 `json:"remind_work_sec"`
  191. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  192. }
  193. // OptionGroupSpeOffDays 特殊非工作日
  194. type OptionGroupSpeOffDays struct {
  195. Timestamp int64 `json:"timestamp"`
  196. Notes string `json:"notes"`
  197. Type int64 `json:"type"`
  198. BegTime int64 `json:"begtime"`
  199. EndTime int64 `json:"endtime"`
  200. }
  201. // OptionGroupWifiMacInfos WIFI信息
  202. type OptionGroupWifiMacInfos struct {
  203. WifiName string `json:"wifiname"`
  204. WifiMac string `json:"wifimac"`
  205. }
  206. // OptionGroupLocInfos 地点信息
  207. type OptionGroupLocInfos struct {
  208. Lat int64 `json:"lat"`
  209. Lng int64 `json:"lng"`
  210. LocTitle string `json:"loc_title"`
  211. LocDetail string `json:"loc_detail"`
  212. Distance int64 `json:"distance"`
  213. }
  214. // OptionGroupRange 人员信息
  215. type OptionGroupRange struct {
  216. PartyID []string `json:"party_id"`
  217. UserID []string `json:"userid"`
  218. TagID []int64 `json:"tagid"`
  219. }
  220. // OptionGroupReporterInfo 汇报人
  221. type OptionGroupReporterInfo struct {
  222. Reporters []OptionGroupReporters `json:"reporters"`
  223. }
  224. // OptionGroupReporters 汇报对象
  225. type OptionGroupReporters struct {
  226. UserID string `json:"userid"`
  227. TagID int64 `json:"tagid"`
  228. }
  229. // OptionGroupScheduleList 自定义排班规则所有排班
  230. type OptionGroupScheduleList struct {
  231. ScheduleID int64 `json:"schedule_id"`
  232. ScheduleName string `json:"schedule_name"`
  233. TimeSection []OptionGroupTimeSection `json:"time_section"`
  234. AllowFlex bool `json:"allow_flex"`
  235. FlexOnDutyTime int64 `json:"flex_on_duty_time"`
  236. FlexOffDutyTime int64 `json:"flex_off_duty_time"`
  237. LateRule OptionGroupLateRule `json:"late_rule"`
  238. MaxAllowArriveEarly int64 `json:"max_allow_arrive_early"`
  239. MaxAllowArriveLate int64 `json:"max_allow_arrive_late"`
  240. }
  241. // OptionGroupTimeSection 班次上下班时段信息
  242. type OptionGroupTimeSection struct {
  243. TimeID int64 `json:"time_id"`
  244. WorkSec int64 `json:"work_sec"`
  245. OffWorkSec int64 `json:"off_work_sec"`
  246. RemindWorkSec int64 `json:"remind_work_sec"`
  247. RemindOffWorkSec int64 `json:"remind_off_work_sec"`
  248. RestBeginTime int64 `json:"rest_begin_time"`
  249. RestEndTime int64 `json:"rest_end_time"`
  250. AllowRest bool `json:"allow_rest"`
  251. EarliestWorkSec int64 `json:"earliest_work_sec"`
  252. LatestWorkSec int64 `json:"latest_work_sec"`
  253. EarliestOffWorkSec int64 `json:"earliest_off_work_sec"`
  254. LatestOffWorkSec int64 `json:"latest_off_work_sec"`
  255. NoNeedCheckOn bool `json:"no_need_checkon"`
  256. NoNeedCheckOff bool `json:"no_need_checkoff"`
  257. }
  258. // OptionGroupOtInfoV2 加班配置
  259. type OptionGroupOtInfoV2 struct {
  260. WorkdayConf OptionGroupWorkdayConf `json:"workdayconf"`
  261. }
  262. // OptionGroupWorkdayConf 工作日加班配置
  263. type OptionGroupWorkdayConf struct {
  264. AllowOt bool `json:"allow_ot"`
  265. Type int64 `json:"type"`
  266. }
  267. // OptionGroupBukaRemind 补卡提醒
  268. type OptionGroupBukaRemind struct {
  269. OpenRemind bool `json:"open_remind"`
  270. BukaRemindDay int64 `json:"buka_remind_day"`
  271. BukaRemindMonth int64 `json:"buka_remind_month"`
  272. }
  273. // AddOption 创建打卡规则
  274. // 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
  275. func (r *Client) AddOption(req *AddOptionRequest) error {
  276. var (
  277. accessToken string
  278. err error
  279. )
  280. if accessToken, err = r.GetAccessToken(); err != nil {
  281. return err
  282. }
  283. var response []byte
  284. if response, err = util.PostJSON(fmt.Sprintf(addOptionURL, accessToken), req); err != nil {
  285. return err
  286. }
  287. return util.DecodeWithCommonError(response, "AddOption")
  288. }
  289. // UpdateOptionRequest 修改打卡规则请求
  290. type UpdateOptionRequest struct {
  291. EffectiveNow bool `json:"effective_now,omitempty"`
  292. Group OptionGroupRule `json:"group,omitempty"`
  293. }
  294. // UpdateOption 修改打卡规则
  295. // 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
  296. func (r *Client) UpdateOption(req *UpdateOptionRequest) error {
  297. var (
  298. accessToken string
  299. err error
  300. )
  301. if accessToken, err = r.GetAccessToken(); err != nil {
  302. return err
  303. }
  304. var response []byte
  305. if response, err = util.PostJSON(fmt.Sprintf(updateOptionURL, accessToken), req); err != nil {
  306. return err
  307. }
  308. return util.DecodeWithCommonError(response, "UpdateOption")
  309. }
  310. // ClearOptionRequest 清空打卡规则数组元素请求
  311. type ClearOptionRequest struct {
  312. GroupID int64 `json:"groupid"`
  313. ClearField []int64 `json:"clear_field"`
  314. EffectiveNow bool `json:"effective_now"`
  315. }
  316. // ClearOption 清空打卡规则数组元素
  317. // 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
  318. func (r *Client) ClearOption(req *ClearOptionRequest) error {
  319. var (
  320. accessToken string
  321. err error
  322. )
  323. if accessToken, err = r.GetAccessToken(); err != nil {
  324. return err
  325. }
  326. var response []byte
  327. if response, err = util.PostJSON(fmt.Sprintf(clearOptionURL, accessToken), req); err != nil {
  328. return err
  329. }
  330. return util.DecodeWithCommonError(response, "ClearOption")
  331. }
  332. // DelOptionRequest 删除打卡规则请求
  333. type DelOptionRequest struct {
  334. GroupID int64 `json:"groupid"`
  335. EffectiveNow bool `json:"effective_now"`
  336. }
  337. // DelOption 删除打卡规则
  338. // 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
  339. func (r *Client) DelOption(req *DelOptionRequest) error {
  340. var (
  341. accessToken string
  342. err error
  343. )
  344. if accessToken, err = r.GetAccessToken(); err != nil {
  345. return err
  346. }
  347. var response []byte
  348. if response, err = util.PostJSON(fmt.Sprintf(delOptionURL, accessToken), req); err != nil {
  349. return err
  350. }
  351. return util.DecodeWithCommonError(response, "DelOption")
  352. }