Skip to content

Commit

Permalink
godoc online
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Mar 27, 2020
1 parent f71fa2f commit ecfa82d
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 54 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 github.com/axiaoxin-com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
go get -u github.com/axiaoxin-com/chaojiying
```

## 在线文档

<https://pkg.go.dev/github.com/axiaoxin-com/chaojiying?tab=doc>

## 用法示例

Expand Down
107 changes: 53 additions & 54 deletions chaojiying.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,32 @@ func (c *Client) PickOneAccount() (Account, error) {
}

// GetScore 超级鹰GetScore接口
/*
接口说明:查询用户的题分信息
接口网址:http://upload.chaojiying.net/Upload/GetScore.php
POST发送模式:application/x-www-form-urlencoded, multipart/form-data, application/json
返回格式:json
返回编码:utf-8
返回汉字编码:Unicode
发送说明:
user=用户账号
pass=用户密码 //或 pass2=用户密码的md5值(32位小写)
返回说明:
err_no,(数值) 返回代码
err_str,(字符串) 中文描述的返回信息
tifen,(数值) 题分
tifen_lock,(数值) 锁定题分
返回json字符串示例:{"err_no":0,"err_str":"OK","tifen":821690,"tifen_lock":0}
*/
func (c *Client) GetScore(user, pass string) (*GetScoreResp, error) {
/* 接口说明:查询用户的题分信息
接口网址:http://upload.chaojiying.net/Upload/GetScore.php
POST发送模式:application/x-www-form-urlencoded, multipart/form-data, application/json
返回格式:json
返回编码:utf-8
返回汉字编码:Unicode
发送说明:
user=用户账号
pass=用户密码 或 pass2=用户密码的md5值(32位小写)
返回说明:
err_no(数值) 返回代码;
err_str(字符串) 中文描述的返回信息;
tifen(数值) 题分;
tifen_lock(数值) 锁定题分
返回json字符串示例:
{"err_no":0, "err_str":"OK", "tifen":821690, "tifen_lock":0}
*/
apiURL := "http://upload.chaojiying.net/Upload/GetScore.php"
data := url.Values{
"user": {user},
Expand Down Expand Up @@ -140,33 +145,33 @@ func (c *Client) GetScore(user, pass string) (*GetScoreResp, error) {
}

// Processing 超级鹰验证码识别接口
/*
接口说明:识别核心接口,一步识别,发送图片和其他相关信息给服务器,服务器返回识别结果和一些其他信息 POST
接口网址:http://upload.chaojiying.net/Upload/Processing.php
发送说明:
user=用户账号
pass=用户密码 //或 pass2=用户密码的md5值(32位小写)
softid=软件ID 在用户中心,软件ID处可以生成
codetype=验证码类型 在价格体系中选用一个适合的类型 点击这里进入
len_min=最小位数 //默认0为不启用,图片类型为可变位长时可启用这个参数
以下两个参数选其一 图片文件的宽推荐不超过460px,高不超过310px
userfile=图片文件二进制流(或是称之为内存流,文件流,字节流的概念)
file_base64=图片文件base64字符串
返回说明:
err_no,(数值) 返回代码
err_str,(字符串) 中文描述的返回信息
pic_id,(字符串) 图片标识号,或图片id号
pic_str,(字符串) 识别出的结果
md5,(字符串) md5校验值,用来校验此条数据返回是否真实有效 点击这里查看md5校验算法
返回json字符串示例:{"err_no":0,"err_str":"OK","pic_id":"1662228516102","pic_str":"8vka","md5":"35d5c7f6f53223fbdc5b72783db0c2c0"}
推荐逻辑处理流程:if (err_no == 0) {识别结果 = pic_str} else {错误代码 = err_no}
*/
func (c *Client) Processing(user, pass string, pic io.Reader) (*ProcessingResp, error) {
/*
接口说明:识别核心接口,一步识别,发送图片和其他相关信息给服务器,服务器返回识别结果和一些其他信息 POST
接口网址:http://upload.chaojiying.net/Upload/Processing.php
发送说明:
user=用户账号
pass=用户密码 //或 pass2=用户密码的md5值(32位小写)
softid=软件ID 在用户中心,软件ID处可以生成
codetype=验证码类型 在价格体系中选用一个适合的类型 点击这里进入
len_min=最小位数 //默认0为不启用,图片类型为可变位长时可启用这个参数
以下两个参数选其一 图片文件的宽推荐不超过460px,高不超过310px
userfile=图片文件二进制流(或是称之为内存流,文件流,字节流的概念)
file_base64=图片文件base64字符串
返回说明:
err_no,(数值) 返回代码
err_str,(字符串) 中文描述的返回信息
pic_id,(字符串) 图片标识号,或图片id号
pic_str,(字符串) 识别出的结果
md5,(字符串) md5校验值,用来校验此条数据返回是否真实有效 点击这里查看md5校验算法
返回json字符串示例:{"err_no":0,"err_str":"OK","pic_id":"1662228516102","pic_str":"8vka","md5":"35d5c7f6f53223fbdc5b72783db0c2c0"}
推荐逻辑处理流程:if (err_no == 0) {识别结果 = pic_str} else {错误代码 = err_no}
*/
apiURL := "http://upload.chaojiying.net/Upload/Processing.php"
picContent, err := ioutil.ReadAll(pic)
if err != nil {
Expand Down Expand Up @@ -224,14 +229,8 @@ func (c *Client) Cr4ck(pic io.Reader) (string, error) {
}

// LoadAccountsFromJSONFile 从指定位置的json文件中加载账号
/* json格式
[
{
"user": "",
"pass": ""
}
]
*/
//
// json格式: [{"user": "", "pass": ""}, ...]
func LoadAccountsFromJSONFile(filePath string) ([]Account, error) {
b, err := ioutil.ReadFile(filePath)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions example_one_acount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package chaojiying_test

import (
"fmt"
"log"
"os"

"github.com/axiaoxin-com/chaojiying"
)

// 使用单账号的方式示例
func Example_oneAccount() {
// 加载验证码图片
pic, err := os.Open("./example/pin.png")
if err != nil {
log.Println(err)
}
defer pic.Close()

// 创建客户端
cli, err := chaojiying.New(nil)
if err != nil {
log.Println(err)
}

// 从环境变量获取账号信息
user := os.Getenv("user")
pass := os.Getenv("pass")

// 指定账号破解验证码
resp, err := cli.Processing(user, pass, pic)
if err != nil {
log.Println(err)
}
fmt.Println("破解结果:", resp.PicStr)

// Output:
// 破解结果: myeee

}
46 changes: 46 additions & 0 deletions example_rand_acount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package chaojiying_test

import (
"fmt"
"log"
"os"

"github.com/axiaoxin-com/chaojiying"
)

// 使用随机选择账号的方式示例
func Example_randAccount() {
// 从json文件中加载所有可用账号
// json格式: [{"user":"xx", "pass":"yy"}]
// 破解验证码时随机选择其中一个可用账号进行调用

// 加载账号json信息
jsonFilename := "../personal-data/chaojiying_accounts.json"
accounts, err := chaojiying.LoadAccountsFromJSONFile(jsonFilename)
if err != nil {
log.Fatal(err)
}

// 加载验证码图片
pic, err := os.Open("./example/pin.png")
if err != nil {
log.Fatal(err)
}
defer pic.Close()

// 创建多账号客户端
cli, err := chaojiying.New(accounts)
if err != nil {
log.Fatal(err)
}

// 随机账号破解
pinCode, err := cli.Cr4ck(pic)
if err != nil {
log.Fatal(err)
}
fmt.Println("破解结果:", pinCode)

// Output:
// 破解结果: myeee
}

0 comments on commit ecfa82d

Please sign in to comment.