index.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright (c) 2022 Yansen Zhang
  3. * wxcomponent is licensed under Mulan PSL v2.
  4. * You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. * You may obtain a copy of Mulan PSL v2 at:
  6. * http://license.coscl.org.cn/MulanPSL2
  7. * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. * See the Mulan PSL v2 for more details.
  11. **/
  12. package config
  13. import (
  14. "errors"
  15. "time"
  16. )
  17. // Init 初始化平台实例
  18. func Init(config Config) error {
  19. if config == nil {
  20. return errors.New("平台初始化参数不能为空")
  21. }
  22. appID := config.GetAppID()
  23. secret := config.GetAppSecret()
  24. token := config.GetMsgToken()
  25. if appID == "" || secret == "" || token == "" {
  26. return errors.New("平台组件初始化内容不能为空")
  27. }
  28. conf = config
  29. return nil
  30. }
  31. // GetConfiger 获取配置实例
  32. func GetConfiger() Config {
  33. return conf
  34. }
  35. // GetAppID 获取平台 APPID
  36. func GetAppID() string {
  37. return conf.GetAppID()
  38. }
  39. // GetAppSecret 获取平台 APPSECRET
  40. func GetAppSecret() string {
  41. return conf.GetAppSecret()
  42. }
  43. // GetAppSecret 获取平台消息校验Token
  44. func GetMsgToken() string {
  45. return conf.GetMsgToken()
  46. }
  47. // GetToken 获取 Token
  48. func GetAccessToken() string {
  49. return conf.GetAccessToken()
  50. }
  51. // RefreshToken 刷新 Token
  52. func RefreshToken(token string, expire time.Time) error {
  53. return conf.RefreshToken(token, expire)
  54. }
  55. // GetTicket 获取票据
  56. func GetVerifyTicket() string {
  57. return conf.GetVerifyTicket()
  58. }
  59. // RefreshTicket 刷新票据
  60. func RefreshVerifyTicket(ticket string, expire time.Time) error {
  61. return conf.RefreshVerifyTicket(ticket, expire)
  62. }