-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
165 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/chromedp/chromedp" | ||
"istep/env" | ||
"log" | ||
) | ||
|
||
func Client(keeper chan int, commands chan ChangeCommand, showClient bool) { | ||
keeper <- 1 | ||
var ctx context.Context | ||
var cancel context.CancelFunc | ||
defer func() { | ||
<-keeper | ||
}() | ||
if showClient { | ||
// 创建一个chrome配置实例 | ||
opts := append(chromedp.DefaultExecAllocatorOptions[:], | ||
chromedp.Flag("headless", false), | ||
) | ||
ctx, cancel = chromedp.NewExecAllocator(context.Background(), opts...) | ||
defer cancel() | ||
ctx, cancel = chromedp.NewContext(ctx) | ||
defer cancel() | ||
} else { | ||
ctx, cancel = chromedp.NewContext(context.Background()) | ||
defer cancel() | ||
} | ||
// 访问网站并等待页面加载完成 | ||
if env.CfgWay.Value == env.COM_SHUABU { | ||
if err := chromedp.Run(ctx, | ||
//chromedp.Emulate(device.IPadPro11), | ||
chromedp.Navigate(env.CfgShuabuHost.Value), | ||
chromedp.WaitVisible("app", chromedp.ByID), | ||
); err != nil { | ||
log.Fatal(err) | ||
} | ||
} else if env.CfgWay.Value == env.COM_17BUSHU { | ||
if err := chromedp.Run(ctx, | ||
//chromedp.Emulate(device.IPadPro11), | ||
chromedp.Navigate(env.Cfg17BushuHost.Value), | ||
chromedp.WaitVisible("submitBtn", chromedp.ByID), | ||
); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
defer func() { | ||
err := recover() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
for { | ||
cmd := <-commands | ||
if env.CfgWay.Value == env.COM_SHUABU { | ||
changeStepNumberWithShuabu(ctx, cmd) | ||
} else if env.CfgWay.Value == env.API { | ||
changeStepNumberWithApi(cmd) | ||
} else { | ||
changeStepNumberWith17bushu(ctx, cmd) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/chromedp/chromedp" | ||
"istep/env" | ||
"log" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func changeStepNumberWith17bushu(ctx context.Context, cmd ChangeCommand) { | ||
defer func() { | ||
wg.Done() | ||
}() | ||
fmt.Printf("【修改步数任务】: 为%s修改步数为%d", cmd.UserID, cmd.StepNumber) | ||
err := chromedp.Run(ctx, | ||
chromedp.Navigate(env.Cfg17BushuHost.Value), | ||
chromedp.WaitVisible("submitBtn", chromedp.ByID), | ||
chromedp.SendKeys("#phone", cmd.UserID), | ||
chromedp.SendKeys("#password", cmd.Password, chromedp.ByID), | ||
chromedp.SendKeys("#steps", strconv.Itoa(cmd.StepNumber)), | ||
chromedp.Click("#submitBtn", chromedp.ByID), | ||
chromedp.Sleep(5*time.Second), | ||
chromedp.ActionFunc(func(ctx context.Context) error { | ||
var failMsg string | ||
_ = chromedp.Run(ctx, chromedp.Text("#failMsg", &failMsg, chromedp.ByID)) | ||
if failMsg == "" { | ||
fmt.Print("\t修改步数成功\n") | ||
} else { | ||
fmt.Printf("\t修改步数失败: %s(请注意密码编码)\n", failMsg) | ||
} | ||
return nil | ||
}), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/chromedp/chromedp" | ||
"istep/env" | ||
"log" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
/* | ||
* | ||
使用shuabu网站进行shuabu | ||
*/ | ||
func changeStepNumberWithShuabu(ctx context.Context, cmd ChangeCommand) { | ||
defer func() { | ||
wg.Done() | ||
}() | ||
fmt.Printf("【修改步数任务】: 为%s修改步数为%d", cmd.UserID, cmd.StepNumber) | ||
err := chromedp.Run(ctx, | ||
chromedp.Navigate(env.Cfg17BushuHost.Value), | ||
chromedp.WaitVisible("submitBtn", chromedp.ByID), | ||
chromedp.SendKeys("#app > div > div > div > div > div.w-11\\/12.mx-auto > div.ant-spin-nested-loading > div > div > div:nth-child(1) > div.form-input > input", cmd.UserID), | ||
chromedp.SendKeys("#app > div > div > div > div > div.w-11\\/12.mx-auto > div.ant-spin-nested-loading > div > div > div:nth-child(2) > div.form-input > span > input", cmd.Password, chromedp.ByID), | ||
chromedp.SendKeys("#app > div > div > div > div > div.w-11\\/12.mx-auto > div.ant-spin-nested-loading > div > div > div:nth-child(3) > div.form-input > input", strconv.Itoa(cmd.StepNumber)), | ||
chromedp.Click("#app > div > div > div > div > div.w-11\\/12.mx-auto > button", chromedp.ByQuery), | ||
chromedp.Sleep(5*time.Second), | ||
//chromedp.ActionFunc(func(ctx context.Context) error { | ||
// var failMsg string | ||
// _ = chromedp.Run(ctx, chromedp.Text("#failMsg", &failMsg, chromedp.ByID)) | ||
// if failMsg == "" { | ||
// fmt.Print("\t修改步数成功\n") | ||
// } else { | ||
// fmt.Printf("\t修改步数失败: %s(请注意密码编码)\n", failMsg) | ||
// } | ||
// return nil | ||
//}), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |