智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

  1. package svc
  2. import (
  3. "applet/app/cfg"
  4. offical "applet/app/db/official"
  5. "applet/app/utils/cache"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/xiaoju"
  7. "github.com/tidwall/gjson"
  8. )
  9. // 小桔基本配置
  10. func XiaojuKey() map[string]string {
  11. param := map[string]string{
  12. "key": offical.SysCfgByKeyStr("xiaoju_key"),
  13. "sign_secret": offical.SysCfgByKeyStr("xiaoju_sign_secret"),
  14. "data_secret": offical.SysCfgByKeyStr("xiaoju_data_secret"),
  15. "secret": offical.SysCfgByKeyStr("xiaoju_secret"),
  16. "url": "https://gw.am.xiaojukeji.com/online/energy/v1/",
  17. }
  18. return param
  19. }
  20. func GetXiaojuToken(platformKey map[string]string) string {
  21. key := "zhiying_xiaoju_token"
  22. token, err := cache.GetString(key)
  23. if cfg.Prd == false {
  24. return token
  25. }
  26. if err != nil || token == "" {
  27. token1, _ := xiaoju.GetXiaojuToken(platformKey)
  28. token = gjson.Get(token1, "accessToken").String()
  29. if token != "" {
  30. availableTime := gjson.Get(token1, "availableTime").Int()
  31. cache.SetEx(key, token, int(availableTime-20))
  32. }
  33. }
  34. return token
  35. }