Skip to content

Commit

Permalink
Merge pull request #6 from EldersJavas/main
Browse files Browse the repository at this point in the history
大更新:可以使用配置文件,不需要修改源代码
  • Loading branch information
EldersJavas authored Feb 3, 2021
2 parents bf150a0 + 0f1a540 commit 16e06f7
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test_auto-get-fu-card
name: Build auto-get-fu-card

on:
push:
Expand Down
32 changes: 5 additions & 27 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
name: Test_auto-get-fu-card
name: Test auto-get-fu-card

on:
push:
branches:
- master
- feature/*
paths-ignore:
- '**/*.md'
- .gitignore
- .editorconfig
- appveyor.yml
- 'azure-pipelines*.yml'
- 'ci/azure-pipelines/template*.yml'

pull_request:
branches:
- master
- feature/*
- release/*
paths-ignore:
- '**/*.md'
- .gitignore
- .editorconfig
- appveyor.yml
- 'azure-pipelines*.yml'
- 'ci/azure-pipelines/template*.yml'

branches: [ main ]
pull_request:
branches: [ main ]
jobs:
Build_macos:
name: Test on macos
Expand All @@ -49,9 +28,8 @@ jobs:
mvn test
Build_Linux:
name: Build on ubuntu
name: Test on ubuntu
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
Expand Down
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,44 @@

### Step1:PC端配置

1.`src/main/resources/static/dirver/chromedriver.exe`复制到D盘根目录.<br>注意浏览器的版本,从 [镜像站](http://npm.taobao.org/mirrors/chromedriver/) 下载。
```
填写路径时一定要这样写
C:\\Program Files\\Chrome\\Application\\chrome.exe
而不是
C:\Program Files\Chrome\Application\chrome.exe
```

#### A.使用配置文件

1. 配置`config.properties`

2.`src/main/java/com/dream/autogetfucard/chromeHelper/ChromeHelper.java``phone` 属性填上自己的手机号
```java
private static final String phone = "00000000000";
```
| Key | 备注 |
| :------------: | :------------: |
| PhoneNumber | 电话号码 |
| DriverLocal | chromedriver.exe 路径 [镜像站](http://npm.taobao.org/mirrors/chromedriver/)(根据Chrome版本下载) |
| ChromeLocal | chrome.exe 路径 |

2. 启动程序

```java
java -jar auto-get-fu-card.jar
```

注意`config.properties``auto-get-fu-card.jar`必须在一个文件夹下.

#### B.不用配置文件,用参数

| 参数 | 备注 |
| :------------: | :------------: |
| -p or -phone | 电话号码 |
| -d or -driver | chromedriver.exe 路径 |
| -c or -chrome | chrome.exe 路径 |

示例:

```java
java -jar auto-get-fu-card.jar -p 12345678900 -d D:\\chromedriver.exe -c C:\\Program Files\\Chrome\\Application\\chrome.exe
```

### Step2:手机端(能收短信的都行)配置

Expand All @@ -47,11 +79,10 @@
3. 因为苹果的限制所以必须收到短信的时候点击运行按钮,拉下菜单就看见了


### 树莓派等 Linux 设备: Gammu
#### 树莓派等 Linux 设备: Gammu
如果你身边有 3G/4G 模块,也可以尝试在树莓派等设备上搭建 Gammu 来实现手机上的效果。
本程序已经在 Raspberry Pi 3B + Ubuntu + EC20 模块下测试通过。

#### 安装&配置
1.安装和配置 Gammu.
```
sudo apt-get update && sudo apt-get install gammu
Expand All @@ -72,6 +103,6 @@ sudo gammu-smsd --config /etc/gammu-smsdrc --pid /var/run/gammu-smsd.pid --daemo
```
理论上就可以尝试接收来自支付宝的验证码,领取福卡了。

### 手
####

运行之后收到验证码自己往里输行了
3 changes: 3 additions & 0 deletions config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PhoneNumber=12345678900
DriverLocal=D:\\chromedriver.exe
ChromeLocal=C:\\Program Files\\Chrome\\Application\\chrome.exe
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,84 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.*;
import java.util.Iterator;
import java.util.Properties;

@SpringBootApplication

public class AutoGetFuCardApplication {
public static String ChromeLocal;
public static String DriverLocal;
public static String PhoneNumber;
public static boolean IsConfig;


public static void main(String[] args) {
IsConfig=false;
Properties prop = new Properties();
try{
//读取属性文件config.properties
InputStream in = new BufferedInputStream (new FileInputStream("config.properties"));
prop.load(in); ///加载属性列表
Iterator<String> it=prop.stringPropertyNames().iterator();
while(it.hasNext()){
String key=it.next();
System.out.println(key+":"+prop.getProperty(key));
if("PhoneNumber".equals(key)){
PhoneNumber=prop.getProperty(key);

}
else if(("DriverLocal".equals(key))){
DriverLocal=prop.getProperty(key);
}else{
ChromeLocal=prop.getProperty(key);
IsConfig=true;//所有参数都包含才能使用配置文件,否则不能用.
}
in.close();
}
} catch(Exception e){
IsConfig=false;
System.out.println("配置文件加载失败");
}


if(args != null && args.length > 0) {
for(int index = 0; index < args.length; index = index + 2) {
if(index + 1 < args.length) {
if(args[index].equalsIgnoreCase("-c") || args[index].equalsIgnoreCase("-chrome")) {
ChromeLocal = args[index + 1];
}else if(IsConfig){
ChromeLocal="";
}else{
//ChromeLocal="C:\\Program Files\\Chrome\\Application\\chrome.exe";
System.out.println("错误:没Chrome你让我怎么运行.");
System.exit(0);
}

if(args[index].equalsIgnoreCase("-d") || args[index].equalsIgnoreCase("-driver")) {
DriverLocal = args[index + 1];
}else if(IsConfig){
ChromeLocal="";
} else{
//ChromeLocal="D:\\chromedriver.exe";
System.out.println("错误:没ChromeDriver你让我怎么运行.");
System.exit(0);
}

if(args[index].equalsIgnoreCase("-p") || args[index].equalsIgnoreCase("-phone")) {
PhoneNumber = args[index + 1];
}else if(IsConfig){
PhoneNumber="";
} else{
//PhoneNumber="12345678900";
System.out.println("错误:没电话号码你让我怎么运行.");
System.exit(0);
}
}
}
}

SpringApplication.run(AutoGetFuCardApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

Expand All @@ -12,13 +13,15 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import static com.dream.autogetfucard.AutoGetFuCardApplication.*;

/**
* 打开浏览器的类
*/
@Component
public class ChromeHelper implements CommandLineRunner {

private static final String phone = "00000000000";
//private static final String phone = "123";

public static volatile String code = "000000";

Expand Down Expand Up @@ -90,16 +93,22 @@ public class ChromeHelper implements CommandLineRunner {
condition = lock.newCondition();
}



@Override
public void run(String... args) {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", DriverLocal);
ChromeOptions options = new ChromeOptions();
options.setBinary(ChromeLocal);
//WebDriverException="D:\\Program Files\\CentBrowser\\Application\\chrome.exe";

new Thread(() -> {
WebDriver driver = new ChromeDriver();
WebDriver driver = new ChromeDriver(options);
System.out.println("started");
Arrays.stream(urls).forEach(t -> {
driver.get(t);
driver.findElement(By.className("btn___SkWL1")).click();
driver.findElement(By.id("J-mobile")).sendKeys(phone);
driver.findElement(By.id("J-mobile")).sendKeys(PhoneNumber);
driver.findElement(By.className("sendCode___16OJu")).click();
lock.lock();
try {
Expand Down

0 comments on commit 16e06f7

Please sign in to comment.