forked from chanxuehong/wechat
/
http_client.go
60 lines (55 loc) · 1.55 KB
/
http_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
// @description wechat 是腾讯微信公众平台 api 的 golang 语言封装
// @link https://github.com/chanxuehong/wechat for the canonical source repository
// @license https://github.com/chanxuehong/wechat/blob/master/LICENSE
// @authors chanxuehong(chanxuehong@gmail.com)
package mp
import (
"net"
"net/http"
"time"
)
// net/http:
//
// type Client struct {
// // Transport specifies the mechanism by which individual
// // HTTP requests are made.
// // If nil, DefaultTransport is used.
// Transport RoundTripper
//
// ...
// }
//
// var DefaultClient = &Client{}
//
// var DefaultTransport RoundTripper = &Transport{
// Proxy: ProxyFromEnvironment,
// Dial: (&net.Dialer{
// Timeout: 30 * time.Second,
// KeepAlive: 30 * time.Second,
// }).Dial,
// TLSHandshakeTimeout: 10 * time.Second,
// }
// 一般请求的 http.Client
var TextHttpClient = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
},
Timeout: 15 * time.Second,
}
// 多媒体上传下载请求的 http.Client
var MediaHttpClient = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
},
Timeout: 300 * time.Second, // 因为目前微信支持最大的文件是 10MB, 请求超时时间保守设置为 300 秒
}