-
Notifications
You must be signed in to change notification settings - Fork 145
/
main.go
121 lines (99 loc) · 2.66 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
package main
import (
"fmt"
fmt2 "github.com/ArtisanCloud/go-libs/fmt"
"github.com/ArtisanCloud/power-wechat/src/miniProgram"
"github.com/ArtisanCloud/power-wechat/src/payment"
"github.com/ArtisanCloud/power-wechat/src/work"
"os"
"strconv"
)
func GetWorkConfig() *work.UserConfig {
agentID, _ := strconv.Atoi(os.Getenv("agent_id"))
return &work.UserConfig{
CorpID: os.Getenv("corp_id"),
AgentID: agentID,
Secret: os.Getenv("secret"),
ResponseType: os.Getenv("array"),
Log: work.Log{
"debug",
"./wechat.log",
},
OAuth: work.OAuth{
Callback: os.Getenv("oauth_callback"),
Scopes: []string{},
},
//HttpDebug: true,
Debug: true,
// server config
Token: os.Getenv("token"),
AESKey: os.Getenv("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",
},
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",
},
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())
// init payment app
configPayment := GetPaymentConfig()
paymentApp, err := payment.NewPayment(configPayment)
if err != nil {
fmt.Println(err.Error())
}
fmt2.Dump("payment config:", paymentApp.GetConfig())
// init miniProgram app
configMiniProgram := GetMiniProgramConfig()
miniProgramApp, err := miniProgram.NewMiniProgram(configMiniProgram)
if err != nil {
fmt.Println(err.Error())
}
fmt2.Dump("miniprogram config:", miniProgramApp.GetConfig())
}