-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathmain.go
138 lines (116 loc) · 3.19 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"fmt"
fmt2 "github.com/ArtisanCloud/PowerLibs/v2/fmt"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/miniProgram"
"github.com/ArtisanCloud/PowerWeChat/v2/src/payment"
"github.com/ArtisanCloud/PowerWeChat/v2/src/work"
"os"
"strconv"
)
func GetWorkConfig() *work.UserConfig {
agentID, _ := strconv.Atoi(os.Getenv("wecom_agent_id"))
return &work.UserConfig{
CorpID: os.Getenv("corp_id"),
AgentID: agentID,
Secret: os.Getenv("wecom_secret"),
ResponseType: os.Getenv("array"),
Log: work.Log{
Level: "debug",
File: "./wechat.log",
ENV: os.Getenv("work.env"),
},
OAuth: work.OAuth{
Callback: os.Getenv("app_oauth_callback_url"),
Scopes: []string{},
},
Cache: kernel.NewRedisClient(&kernel.RedisOptions{
Addr: "127.0.0.1:6379",
Password: "",
DB: 1,
}),
//HttpDebug: true,
Debug: true,
// server config
Token: os.Getenv("app_message_token"),
AESKey: os.Getenv("app_message_aes_key"),
}
}
func GetPaymentConfig() *payment.UserConfig {
return &payment.UserConfig{
//"corp_id": os.Getenv("corp_id"),
//"secret": os.Getenv("secret"),
AppID: os.Getenv("app_id"),
MchID: os.Getenv("mch_id"),
MchApiV3Key: os.Getenv("mch_api_v3_key"),
Key: os.Getenv("key"),
CertPath: os.Getenv("wx_cert_path"),
KeyPath: os.Getenv("wx_key_path"),
SerialNo: os.Getenv("serial_no"),
ResponseType: os.Getenv("array"),
Log: payment.Log{
Level: "debug",
File: "./wechat.log",
},
Http: payment.Http{
Timeout: 30.0,
BaseURI: "https://api.mch.weixin.qq.com",
},
Cache: kernel.NewRedisClient(&kernel.RedisOptions{
Addr: "127.0.0.1:6379",
Password: "",
DB: 1,
}),
NotifyURL: os.Getenv("notify_url"),
HttpDebug: true,
//Debug: true,
//"sandbox": true,
// server config
//Token: os.Getenv("token"),
//AESKey: os.Getenv("aes_key"),
}
}
func GetMiniProgramConfig() *miniProgram.UserConfig {
return &miniProgram.UserConfig{
AppID: os.Getenv("miniprogram_app_id"), // 小程序、公众号或者企业微信的appid
Secret: os.Getenv("miniprogram_secret"), // 商户号 appID
ResponseType: os.Getenv("array"),
Log: miniProgram.Log{
Level: "debug",
File: "./wechat.log",
},
Cache: kernel.NewRedisClient(&kernel.RedisOptions{
Addr: "127.0.0.1:6379",
Password: "",
DB: 1,
}),
HttpDebug: true,
//Debug: true,
//"sandbox": true,
}
}
func main() {
fmt.Printf("hello Wechat! \n")
// init wecom app
configWecom := GetWorkConfig()
wecomApp, err := work.NewWork(configWecom)
if err != nil {
fmt.Println(err.Error())
}
fmt2.Dump("wecom config:", wecomApp.GetConfig().All())
// init payment app
configPayment := GetPaymentConfig()
paymentApp, err := payment.NewPayment(configPayment)
if err != nil {
fmt.Println(err.Error())
}
fmt2.Dump("payment config:", paymentApp.GetConfig().All())
// init miniProgram app
configMiniProgram := GetMiniProgramConfig()
miniProgramApp, err := miniProgram.NewMiniProgram(configMiniProgram)
if err != nil {
fmt.Println(err.Error())
}
fmt2.Dump("miniprogram config:", miniProgramApp.GetConfig().All())
}