Merge branch 'wcd-2411-update' into dengjh-2507-update
| | |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, leaveEndDuration); |
| | | } |
| | | |
| | | // TODO:20250813修改 增加打卡时间判断,打卡时间需要闭环 |
| | | Boolean actualTimeLoopFlag = ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) == ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()); |
| | | if (!actualTimeLoopFlag) { |
| | | List<String> editStatusList = Arrays.asList(Constant.ATTENDANCE_STATE_GOOUT, Constant.ATTENDANCE_STATE_BUSINESS, Constant.ATTENDANCE_STATE_LEAVE); |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && editStatusList.contains(attendance.getStartClockResults())) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | | } |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && editStatusList.contains(attendance.getEndClockResults())) { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | | } |
| | | } |
| | | |
| | | // // 查询考勤请假表 |
| | | // List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | // Double leaveDuration = new Double(0.00);//计算的总时长 |
| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.temp.service.WechatRobotService; |
| | | import me.zhengjie.utils.weixin.AesException; |
| | | import me.zhengjie.utils.weixin.WXBizJsonMsgCrypt; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | @Override |
| | | public Object handleRobotCallback(String msgSignature, String timestamp, String nonce, HttpServletRequest request, HttpServletResponse response) { |
| | | WXBizJsonMsgCrypt wxcpt = null; |
| | | try { |
| | | WXBizJsonMsgCrypt wxcpt = new WXBizJsonMsgCrypt(TOKEN, ENCODING_AES_KEY, CORP_ID); |
| | | wxcpt = new WXBizJsonMsgCrypt(TOKEN, ENCODING_AES_KEY, CORP_ID); |
| | | // 读取回调数据 |
| | | StringBuilder sb = new StringBuilder(); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); |
| | |
| | | String callbackData = sb.toString(); |
| | | |
| | | JSONObject jsonObject = JSONObject.parseObject(callbackData); |
| | | String decryptedMessage = wxcpt.DecryptMsg(msgSignature, timestamp, nonce, jsonObject.toString()); |
| | | String decryptedMessage = wxcpt.DecryptRobotMsg(msgSignature, timestamp, nonce, jsonObject.toString()); |
| | | System.out.println("接收到机器人发送的加密消息:" + jsonObject.toJSONString()); |
| | | System.out.println("接收到机器人发送的解密后消息:" + decryptedMessage); |
| | | |
| | | return wxcpt.EncryptMsg("消息已收到", "", nonce); |
| | | JSONObject decryptedMessageJson = JSONObject.parseObject(decryptedMessage); |
| | | if (decryptedMessageJson.getString("msgtype").equals("text")) { |
| | | return wxcpt.EncryptRobotMsg("消息已收到", "", nonce); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | try { |
| | | if (wxcpt != null) { |
| | | return wxcpt.EncryptRobotMsg("消息接收出现异常,请联系管理员处理 o(╥﹏╥o...)", "", nonce); |
| | | } |
| | | } catch (AesException aesException) { |
| | | aesException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | return null; |
| | |
| | | */ |
| | | private static void fixJsonStructure(JSONObject jsonObject) { |
| | | // 定义需要确保为列表的字段名 |
| | | String[] listFields = {"ProcessList", "NodeList", "Details", "Notifyer", "SubNodeList", "SpRecord" }; |
| | | String[] listFields = {"ProcessList", "NodeList", "Details", "Notifyer", "SubNodeList", "SpRecord", "Comments" }; |
| | | |
| | | for (String fieldName : listFields) { |
| | | if (jsonObject.has(fieldName)) { |
| | |
| | | return String.format(format, encrypt, signature, timestamp, nonce); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 提取出 JSON 包中的加密消息(智能机器人) |
| | | * @param jsontext 待提取的json字符串 |
| | | * @return 提取出的加密消息字符串 |
| | | * @throws AesException |
| | | */ |
| | | public static Object[] extractRobot(String jsontext) throws AesException { |
| | | Object[] result = new Object[3]; |
| | | try { |
| | | |
| | | JSONObject json = new JSONObject(jsontext); |
| | | String encrypt_msg = json.getString("encrypt"); |
| | | // System.out.println(json.toString()); |
| | | // String msgid = json.getString("msgid"); |
| | | // String aibotid = json.getString("aibotid"); |
| | | // String chatid = json.getString("chatid"); |
| | | // String chattype = json.getString("chattype"); |
| | | // JSONObject from = json.getJSONObject("from"); |
| | | // String userid = from.getString("userid"); |
| | | // String msgtype = json.getString("msgtype"); |
| | | // JSONObject text = json.getJSONObject("text"); |
| | | // String content = text.getString("content"); |
| | | |
| | | result[0] = encrypt_msg; |
| | | return result; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new AesException(AesException.ParseJsonError); |
| | | } |
| | | } |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 将企业微信智能机器人回复用户的消息加密打包. |
| | | * <ol> |
| | | * <li>对要发送的消息进行AES-CBC加密</li> |
| | | * <li>生成安全签名</li> |
| | | * <li>将消息密文和安全签名打包成json格式</li> |
| | | * </ol> |
| | | * |
| | | * @param replyMsg 企业微信待回复用户的消息,json格式的字符串 |
| | | * @param timeStamp 时间戳,可以自己生成,也可以用URL参数的timestamp |
| | | * @param nonce 随机串,可以自己生成,也可以用URL参数的nonce |
| | | * |
| | | * @return 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的json格式的字符串 |
| | | * @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 |
| | | */ |
| | | public String EncryptRobotMsg(String replyMsg, String timeStamp, String nonce) throws AesException { |
| | | // 加密 |
| | | String encrypt = encrypt(getRandomStr(), replyMsg); |
| | | |
| | | // 生成安全签名 |
| | | if (timeStamp == "") { |
| | | timeStamp = Long.toString(System.currentTimeMillis()); |
| | | } |
| | | |
| | | String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt); |
| | | |
| | | // System.out.println("发送给平台的签名是: " + signature[1].toString()); |
| | | // 生成发送的json''' |
| | | String result = JsonParse.generate(encrypt, signature, timeStamp, nonce); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 检验智能机器人消息的真实性,并且获取解密后的明文. |
| | | * <ol> |
| | | * <li>利用收到的密文生成安全签名,进行签名验证</li> |
| | | * <li>若验证通过,则提取json中的加密消息</li> |
| | | * <li>对消息进行解密</li> |
| | | * </ol> |
| | | * |
| | | * @param msgSignature 签名串,对应URL参数的msg_signature |
| | | * @param timeStamp 时间戳,对应URL参数的timestamp |
| | | * @param nonce 随机串,对应URL参数的nonce |
| | | * @param postData 密文,对应POST请求的数据 |
| | | * |
| | | * @return 解密后的原文 |
| | | * @throws AesException 执行失败,请查看该异常的错误码和具体的错误信息 |
| | | */ |
| | | public String DecryptRobotMsg(String msgSignature, String timeStamp, String nonce, String postData) |
| | | throws AesException { |
| | | |
| | | // 密钥,公众账号的app secret |
| | | // 提取密文 |
| | | Object[] encrypt = JsonParse.extractRobot(postData); |
| | | |
| | | // 验证安全签名 |
| | | String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt[0].toString()); |
| | | |
| | | // 和URL中的签名比较是否相等 |
| | | // System.out.println("第三方收到URL中的签名:" + msg_sign); |
| | | // System.out.println("第三方校验签名:" + signature); |
| | | if (!signature.equals(msgSignature)) { |
| | | throw new AesException(AesException.ValidateSignatureError); |
| | | } |
| | | |
| | | // 解密 |
| | | String result = decrypt(encrypt[0].toString()); |
| | | return result; |
| | | } |
| | | } |