-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.go
66 lines (55 loc) · 1.39 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package weishi
import (
"errors"
"github.com/dtapps/go-library/utils/golog"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
"strings"
)
// ClientConfig 实例配置
type ClientConfig struct {
}
// Client 实例
type Client struct {
requestClient *gorequest.App // 请求服务
requestClientStatus bool // 请求服务状态
config struct {
ua string // 用户代理
}
slog struct {
status bool // 状态
client *golog.ApiSLog // 日志服务
}
}
// NewClient 创建实例化
func NewClient(config *ClientConfig) (*Client, error) {
c := &Client{}
c.config.ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"
return c, nil
}
func (c *Client) urlJudge(str string) string {
if strings.Index(str, "weishi.qq.com") != -1 {
return str
}
return ""
}
func (c *Client) request302(url string) (string, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}
client := new(http.Client)
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return errors.New("redirect")
}
response, err := client.Do(req)
if err != nil {
if response.StatusCode == http.StatusFound {
location, err := response.Location()
return location.String(), err
} else {
return "", err
}
}
return "", nil
}