No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

45 líneas
993B

  1. package main
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "io/ioutil"
  6. "log"
  7. )
  8. //WechatAPIConfig all secret related API Config
  9. type WechatAPIConfig struct {
  10. //Token is the wechat API shared secrete
  11. Token string `json:"Token"`
  12. //EncodingAESKey is the Key for encrypt messages
  13. EncodingAESKey string `'json:"EncodingAESKey"`
  14. //Appid is wechat public account appid
  15. Appid string `json:"Appid"`
  16. //AppSecret is how we identify ourselves.
  17. AppSecret string `json:"AppSecret"`
  18. }
  19. //APIConfig contains secrets that cannot store in source file
  20. var APIConfig WechatAPIConfig
  21. func readConfig() error {
  22. log.Printf("read config from %s\r\n", "server_config.json")
  23. body, err := ioutil.ReadFile("server_config.json")
  24. if err != nil {
  25. return err
  26. }
  27. return json.Unmarshal(body, &APIConfig)
  28. }
  29. //convert AesEncryptKey into Binary 32bytes
  30. func getAesEncryptKey() [32]byte {
  31. key, _ := base64.StdEncoding.DecodeString(APIConfig.EncodingAESKey + "=")
  32. var k [32]byte
  33. copy(k[:], key)
  34. return k
  35. }