-
Notifications
You must be signed in to change notification settings - Fork 1
/
wx.go
49 lines (45 loc) · 789 Bytes
/
wx.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
package wx
import (
"encoding/json"
"io/ioutil"
"os"
)
// 测试使用
type Config struct {
AppId string `json:"app_id"`
Secret string `json:"secret"`
MchId string `json:"mch_id"`
MchKey string `json:"mch_key"`
Openid string `json:"openid"`
}
// 测试使用
type TestConfig struct {
Ma Config `json:"ma"`
Mp Config `json:"mp"`
Pay Config `json:"pay"`
}
// 测试使用
func GetConfig(filename string) TestConfig {
var c TestConfig
f, err := os.Open(filename)
if err != nil {
f, err := os.Create(filename)
if err != nil {
panic(err)
}
b, err := json.Marshal(c)
if err != nil {
panic(err)
}
_, _ = f.Write(b)
}
b, err := ioutil.ReadAll(f)
if err != nil {
panic(err)
}
err = json.Unmarshal(b, &c)
if err != nil {
panic(err)
}
return c
}