|
- package main
-
- import (
- "encoding/base64"
- "encoding/json"
- "io/ioutil"
- "log"
- )
-
- //WechatAPIConfig all secret related API Config
- type WechatAPIConfig struct {
- //Token is the wechat API shared secrete
- Token string `json:"Token"`
-
- //EncodingAESKey is the Key for encrypt messages
- EncodingAESKey string `'json:"EncodingAESKey"`
-
- //Appid is wechat public account appid
- Appid string `json:"Appid"`
-
- //AppSecret is how we identify ourselves.
- AppSecret string `json:"AppSecret"`
- }
-
- //APIConfig contains secrets that cannot store in source file
- var APIConfig WechatAPIConfig
-
- func readConfig() error {
-
- log.Printf("read config from %s\r\n", "server_config.json")
- body, err := ioutil.ReadFile("server_config.json")
- if err != nil {
- return err
- }
- return json.Unmarshal(body, &APIConfig)
- }
-
- //convert AesEncryptKey into Binary 32bytes
- func getAesEncryptKey() [32]byte {
- key, _ := base64.StdEncoding.DecodeString(APIConfig.EncodingAESKey + "=")
- var k [32]byte
- copy(k[:], key)
- return k
- }
|