通达OA办公软件PC网页端签到

本文介绍了一种使用Java编写的自动签到脚本,该脚本能够根据时间自动打开浏览器,登录公司内部系统,并根据一天中不同的时间段完成早、中、晚的签到和签退操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.Map;

//实现打开浏览器并跳到指定网址的类 
public class SignIn {
	
	public static void openURL(String browser,String userName,String passWord) {
		
		String head = "http://000.000.000.000:0000/logincheck.php?UNAME=";
		String tail = "&PASSWORD=";
		String logUrl = head+userName+tail+passWord;
		
		try {
			//	日期格式化
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			//	获取当前时间
			Date nowTime = new Date();
			String time = df.format(nowTime);
			//	判断今天是周几
			int weekDay = dayForWeek(time);
			if (weekDay != 7) {
				//	处理浏览器路径
				Map map = System.getenv();
				for (Iterator itr = map.keySet().iterator(); itr.hasNext();) {
					String value = (String) map.get((String) itr.next());
					if (value.contains("firefox.exe")) {
						browser = value;
						break;
					} else if (value.contains("chrome.exe")) {
						browser = value;
					}
				}
				int a = 5 ;
				int b = 6 ;
				int c = 5;
				int d = 6;
				//	登录
				for (int i = 0; i < 5; i++) {//进行五次尝试
					
					if (a != b) {
						Process process = Runtime.getRuntime().exec(new String[] { browser, logUrl });
						a = process.waitFor();
						b = process.exitValue();
					}
					//	签到
					String signInUrlOne = "http://服务器IP:端口/general/attendance/personal/duty/submit.php?REGISTER_TYPE=1&USER_DUTP=1";
					String signInUrlTwo = "http://服务器IP:端口/general/attendance/personal/duty/submit.php?REGISTER_TYPE=2&USER_DUTP=1";
					String signInUrlThree = "http://服务器IP:端口/general/attendance/personal/duty/submit.php?REGISTER_TYPE=3&USER_DUTP=1";
					String signInUrlFour = "http://服务器IP:端口/general/attendance/personal/duty/submit.php?REGISTER_TYPE=4&USER_DUTP=1";
					
					//	判断时间为(早上签到,中午签退,中午签到,下午签退)
					
					if (c != d) {
						SimpleDateFormat clock = new SimpleDateFormat("HH:mm");//设置时间格式
						String now = clock.format(nowTime);
						//	早上签到
						String beginTimeOne = "07:00";
						String endTimeOne = "08:00";
						if (belongCalendar(now, beginTimeOne, endTimeOne)) {
							Process one = Runtime.getRuntime().exec(new String[] { browser, signInUrlOne });
							System.out.println("早上签到");
							c = one.waitFor();
							d = one.exitValue();
						}
						//	中午签退
						String beginTimeTwo = "12:10";
						String endTimeTwo = "12:25";
						if (belongCalendar(now, beginTimeTwo, endTimeTwo)) {
							Process two = Runtime.getRuntime().exec(new String[] { browser, signInUrlTwo });
							System.out.println("中午签退");
							c = two.waitFor();
							d = two.exitValue();
						}
						//	中午签到
						String beginTimeThree = "12:30";
						String endTimeThree = "13:00";
						if (belongCalendar(now, beginTimeThree, endTimeThree)) {
							Process three = Runtime.getRuntime().exec(new String[] { browser, signInUrlThree });
							System.out.println("中午签到");
							c = three.waitFor();
							d = three.exitValue();
						}
						//	下午签退
						String beginTimeFour = "17:50";
						String endTimeFour = "24:00";
						if (belongCalendar(now, beginTimeFour, endTimeFour)) {
							Process four = Runtime.getRuntime().exec(new String[] { browser, signInUrlFour });
							System.out.println("下午签退");
							c = four.waitFor();
							d = four.exitValue();
						}
					}
				}
				
				System.out.println("时间:"+time+",签到");
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	/**
	 * 判断输入的日期是星期几
	 * @param pTime
	 * @return
	 * @throws Throwable
	 */
	public static int dayForWeek(String time) throws Throwable {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date tmpDate = format.parse(time);
		Calendar cal = new GregorianCalendar();
		cal.set(tmpDate.getYear(), tmpDate.getMonth(), tmpDate.getDay());
		return cal.get(Calendar.DAY_OF_WEEK);
	}

	/**
	 * 判断时间是否在时间段内
	 * @param nowTime
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	public static boolean belongCalendar(String nowTime, String beginTime, String endTime) {
		
		SimpleDateFormat clock = new SimpleDateFormat("HH:mm");//设置时间格式
		Calendar date = Calendar.getInstance();
		Calendar begin = Calendar.getInstance();
		Calendar end = Calendar.getInstance();
		
		try {
			
			Date now = clock.parse(nowTime);
			Date begins = clock.parse(beginTime);
			Date ends = clock.parse(endTime);
			
			date.setTime(now);
			begin.setTime(begins);
			end.setTime(ends);

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if (date.after(begin) && date.before(end)) {
			return true;
		} else {
			return false;
		}
	}

}

以上就是具体的操作流程,前提是你得知道你们公司的服务器IP以及端口


public class Demo {

	public static void main(String[] args) {
		//	浏览器地址(注意自己的浏览器安装位置)
		String browser = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
		//	"D:\\DevelopmentTools\\FireFoxDeveloperEdition\\firefox.exe";//	火狐浏览器
		//	"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";//	谷歌浏览器
		// 登录网址	后面要拼接
		//String logUrl = "http://服务器IP:端口/logincheck.php?UNAME=用户名&PASSWORD=密码";
		
                //    这里可以填写多个账户进行登陆
		String [] userNameList = {"用户名"};
		String [] passWordList = {"密码"};
		
		for (int i = 0 ;i<userNameList.length ;i++ ) {
			SignIn.openURL(browser,userNameList[i],passWordList[i]);
		}
		
	}
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叁金Coder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值