12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /**
- * 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 wxcomponent
-
- import (
- "encoding/base64"
- "errors"
-
- "gitee.com/yansen_zh/wxcomponent/api/authorization"
- "gitee.com/yansen_zh/wxcomponent/config"
- "gitee.com/yansen_zh/wxcomponent/utils/log"
- )
-
- var aesKey []byte
-
- // InitLogger 初始化 Logger
- func InitLogger(logger log.Logger) {
- log.SetLogger(logger)
- }
-
- // InitConfig 初始化配置
- func InitConfig(conf config.Config, authConfig config.AuthorizerConfig) error {
- err := config.Init(conf, authConfig)
- if err != nil {
- var e error
- aesKey, e = base64.StdEncoding.DecodeString(conf.GetAppSecret() + "=")
- if e != nil {
- return e
- }
- }
-
- return err
- }
-
- // Start 启动服务
- func Start() error {
- if config.GetConfiger() == nil {
- return errors.New("请先进行配置初始化")
- }
-
- if log.GetLogger() == nil {
- return errors.New("请先进行日志初始化")
- }
-
- if !config.GetPushTicketState() {
- // 启动ticket推送服务, 之后微信服务器会每隔 10 分钟推送 component_verify_ticket
- err := authorization.StartPushTicket()
-
- if err != nil {
- config.RefreshPushTicketState(true)
- }
-
- return err
- }
-
- return nil
- }
|