代码拉取完成,页面将自动刷新
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"strings"
"time"
)
// config 结构体
type Config struct {
Lock Lock `json:"lock"`
StartDingding StartDingding `json:"start_dingding"`
WorkPlatform WorkPlatform `json:"work_platform"`
Sign Sign `json:"sign"`
}
type Coordinate struct {
X int `json:"x"`
Y int `json:"y"`
}
type Lock struct {
Require bool `json:"require"`
Password string `json:"password"`
Coordinate Coordinate `json:"coordinate"`
}
type StartDingding struct {
Require bool `json:"require"`
Coordinate Coordinate `json:"coordinate"`
}
type WorkPlatform struct {
Coordinate Coordinate `json:"coordinate"`
}
type Click struct {
X int `json:"x"`
Y int `json:"y"`
}
type Photo struct {
Require bool `json:"require"`
Coordinate Coordinate `json:"coordinate"`
}
type Sign struct {
Coordinate Coordinate `json:"coordinate"`
Click Click `json:"click"`
Photo Photo `json:"photo"`
}
// func isDeviced() bool {
// MyCmd := exec.Command("cmd.exe", "/c", "adb devices")
// MyOut, err := MyCmd.CombinedOutput()
// if err != nil {
// log.Fatal(err)
// }
// s := string(MyOut)
// var validDevice = regexp.MustCompile(`(?m:device$)`)
// return validDevice.MatchString(s)
// }
/**
* 是否熄屏
*/
func isPowerOff() bool {
flag := false
MyCmd := exec.Command("cmd.exe", "/c", "adb shell dumpsys power | findstr Display")
MyOut, err := MyCmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
s := string(MyOut)
if strings.Contains(s, "Display Power: state=OFF") {
flag = true
}
return flag
}
/**
* 是否锁屏
*/
func isLock() bool {
flag := true
MyCmd := exec.Command("cmd.exe", "/c", "adb shell dumpsys window policy | findstr isStatusBarKeyguard")
MyOut, err := MyCmd.CombinedOutput()
if err != nil {
log.Fatal(err)
}
s := string(MyOut)
if strings.Contains(s, "isStatusBarKeyguard=false") {
flag = false
}
return flag
}
/**
* adb 模拟点击
*/
func AdbShellInputTap(x, y int) {
x2 := strconv.Itoa(x)
y2 := strconv.Itoa(y)
commandErr := exec.Command("adb", "shell", "input", "tap", x2, y2).Run()
if commandErr != nil {
log.Fatal(commandErr)
}
}
/**
* adb 模拟滑动
*/
func AdbShellInputSwipe(x1, y1, x2, y2 int) {
xx1 := strconv.Itoa(x1)
yy1 := strconv.Itoa(y1)
xx2 := strconv.Itoa(x2)
yy2 := strconv.Itoa(y2)
commandErr := exec.Command("adb", "shell", "input", "swipe", xx1, yy1, xx2, yy2).Run()
if commandErr != nil {
log.Fatal(commandErr)
}
}
/**
* adb 模拟事件
*/
func AdbShellInputKeyEvent(s string) {
commandErr := exec.Command("adb", "shell", "input", "keyevent", s).Run()
if commandErr != nil {
log.Fatal(commandErr)
}
}
/**
* adb 模拟输入文本
*/
func AdbShellInputText(s string) {
commandErr := exec.Command("adb", "shell", "input", "text", s).Run()
if commandErr != nil {
log.Fatal(commandErr)
}
}
func main() {
// 检查周几
day := time.Now().Weekday().String()
if day == time.Sunday.String() || day == time.Saturday.String() {
fmt.Println("双休日无须更新!")
os.Exit(0)
}
// if !isDeviced() {
// fmt.Println("没有连接")
// os.Exit(1)
// }
// 读取 config 配置
jsonFile, openErr := os.Open("config.json")
if openErr != nil {
log.Fatal(openErr)
}
defer jsonFile.Close()
byteValue, readErr := ioutil.ReadAll(jsonFile)
if readErr != nil {
log.Fatal(readErr)
}
var config Config
json.Unmarshal([]byte(byteValue), &config)
fmt.Println("开启钉钉打卡~")
// 检查是否熄屏
if isPowerOff() {
AdbShellInputKeyEvent("26") //power
if isLock() {
// 滑动解锁
AdbShellInputSwipe(747, 1413, 747, 323)
if config.Lock.Require {
AdbShellInputText(config.Lock.Password)
AdbShellInputTap(config.Lock.Coordinate.X, config.Lock.Coordinate.Y)
}
}
}
// 开启钉钉,若在钉钉界面则不需要
if config.StartDingding.Require {
AdbShellInputTap(config.StartDingding.Coordinate.X, config.StartDingding.Coordinate.Y)
time.Sleep(time.Duration(12) * time.Second)
}
// 钉钉工作台
AdbShellInputTap(config.WorkPlatform.Coordinate.X, config.WorkPlatform.Coordinate.Y)
time.Sleep(time.Duration(6) * time.Second)
// 钉钉打卡位置并打卡
AdbShellInputTap(config.Sign.Coordinate.X, config.Sign.Coordinate.Y)
time.Sleep(time.Duration(12) * time.Second)
AdbShellInputTap(config.Sign.Click.X, config.Sign.Click.Y)
// 需要拍照
if config.Sign.Photo.Require {
AdbShellInputTap(config.Sign.Photo.Coordinate.X, config.Sign.Photo.Coordinate.Y)
time.Sleep(time.Duration(6) * time.Second)
AdbShellInputTap(config.Sign.Photo.Coordinate.X, config.Sign.Photo.Coordinate.Y)
}
time.Sleep(time.Duration(15) * time.Second)
fmt.Println("钉钉打卡结束~")
AdbShellInputKeyEvent("26")
os.Exit(0)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。