@@ -3,16 +3,14 @@ package gowechat
3
3
4
4
import (
5
5
"fmt"
6
- "net/http"
7
6
"sync"
8
7
9
8
"github.com/astaxie/beego/cache"
10
- "github.com/yaotian/gowechat/util"
11
9
"github.com/yaotian/gowechat/wxcontext"
12
10
)
13
11
14
- //MemCache if wxcontext.Config no cache, this will give a default memory cache.
15
- var MemCache cache.Cache
12
+ //memCache if wxcontext.Config no cache, this will give a default memory cache.
13
+ var memCache cache.Cache
16
14
17
15
// Wechat struct
18
16
type Wechat struct {
@@ -28,33 +26,16 @@ func NewWechat(cfg wxcontext.Config) *Wechat {
28
26
29
27
func initContext (cfg * wxcontext.Config , context * wxcontext.Context ) {
30
28
if cfg .Cache == nil {
31
- if MemCache == nil {
32
- MemCache , _ = cache .NewCache ("memory" , `{"interval":60}` )
29
+ if memCache == nil {
30
+ memCache , _ = cache .NewCache ("memory" , `{"interval":60}` )
33
31
}
34
- cfg .Cache = MemCache
32
+ cfg .Cache = memCache
35
33
}
36
34
context .Config = cfg
37
35
38
36
context .SetAccessTokenLock (new (sync.RWMutex ))
39
37
context .SetJsAPITicketLock (new (sync.RWMutex ))
40
38
41
- //create http client
42
- if cfg .SslCertFilePath != "" && cfg .SslKeyFilePath != "" {
43
- if client , err := util .NewTLSHttpClient (cfg .SslCertFilePath , cfg .SslKeyFilePath ); err == nil {
44
- context .SHTTPClient = client
45
- } else {
46
- fmt .Print (err )
47
- }
48
- }
49
-
50
- if cfg .SslCertContent != "" && cfg .SslKeyContent != "" {
51
- if client , err := util .NewTLSHttpClientFromContent (cfg .SslCertContent , cfg .SslKeyContent ); err == nil {
52
- context .SHTTPClient = client
53
- } else {
54
- fmt .Print (err )
55
- }
56
- }
57
- context .HTTPClient = http .DefaultClient
58
39
}
59
40
60
41
//MchMgr 商户平台
@@ -110,5 +91,7 @@ func (wc *Wechat) checkCfgMch() (err error) {
110
91
if wc .Context .SslKeyFilePath == "" && wc .Context .SslKeyContent == "" {
111
92
return fmt .Errorf ("%s" , "配置中没有SslKey" )
112
93
}
94
+ //初始化 http client, 有错误会出错误
95
+ err = wc .Context .InitHTTPClients ()
113
96
return
114
97
}
0 commit comments