12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /**
- * Copyright (c) 2022 Yansen Zhang
- * wxcomponent is licensed under Mulan PSL v2.
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
- * You may obtain a copy of Mulan PSL v2 at:
- * http://license.coscl.org.cn/MulanPSL2
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
- * See the Mulan PSL v2 for more details.
- **/
-
- package config
-
- import (
- "errors"
- "time"
- )
-
- // Init 初始化平台实例
- func Init(config Config) error {
- if config == nil {
- return errors.New("平台初始化参数不能为空")
- }
-
- appID := config.GetAppID()
- secret := config.GetAppSecret()
- token := config.GetMsgToken()
-
- if appID == "" || secret == "" || token == "" {
- return errors.New("平台组件初始化内容不能为空")
- }
-
- conf = config
- return nil
- }
-
- // GetConfiger 获取配置实例
- func GetConfiger() Config {
- return conf
- }
-
- // GetAppID 获取平台 APPID
- func GetAppID() string {
- return conf.GetAppID()
- }
-
- // GetAppSecret 获取平台 APPSECRET
- func GetAppSecret() string {
- return conf.GetAppSecret()
- }
-
- // GetAppSecret 获取平台消息校验Token
- func GetMsgToken() string {
- return conf.GetMsgToken()
- }
-
- // GetToken 获取 Token
- func GetAccessToken() string {
- return conf.GetAccessToken()
- }
-
- // RefreshToken 刷新 Token
- func RefreshToken(token string, expire time.Time) error {
- return conf.RefreshToken(token, expire)
- }
-
- // GetTicket 获取票据
- func GetVerifyTicket() string {
- return conf.GetVerifyTicket()
- }
-
- // RefreshTicket 刷新票据
- func RefreshVerifyTicket(ticket string, expire time.Time) error {
- return conf.RefreshVerifyTicket(ticket, expire)
- }
|