001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 *  http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.wechat;
017
018
019import com.jfinal.weixin.sdk.api.ApiConfig;
020import io.jboot.app.config.annotation.ConfigModel;
021import io.jboot.utils.StrUtil;
022
023@ConfigModel(prefix = "jboot.wechat")
024public class JbootWechatConfig {
025
026    private String debug = "false";
027    private String appId;
028    private String appSecret;
029    private String token;
030    private String partner;
031    private String paternerKey;
032    private String cert;
033
034
035    public String getDebug() {
036        return debug;
037    }
038
039    public void setDebug(String debug) {
040        this.debug = debug;
041    }
042
043    public boolean isDebug() {
044        return "true".equalsIgnoreCase(debug);
045    }
046
047    public String getAppId() {
048        return appId;
049    }
050
051    public void setAppId(String appId) {
052        this.appId = appId;
053    }
054
055    public String getAppSecret() {
056        return appSecret;
057    }
058
059    public void setAppSecret(String appSecret) {
060        this.appSecret = appSecret;
061    }
062
063    public String getToken() {
064        return token;
065    }
066
067    public void setToken(String token) {
068        this.token = token;
069    }
070
071    public String getPartner() {
072        return partner;
073    }
074
075    public void setPartner(String partner) {
076        this.partner = partner;
077    }
078
079    public String getPaternerKey() {
080        return paternerKey;
081    }
082
083    public void setPaternerKey(String paternerKey) {
084        this.paternerKey = paternerKey;
085    }
086
087    public String getCert() {
088        return cert;
089    }
090
091    public void setCert(String cert) {
092        this.cert = cert;
093    }
094
095    public boolean isConfigOk() {
096        return StrUtil.isNotBlank(appId)
097                && StrUtil.isNotBlank(appSecret)
098                && StrUtil.isNotBlank(token);
099    }
100
101    public ApiConfig getApiConfig() {
102
103        if (!isConfigOk()) {
104            return null;
105        }
106
107        ApiConfig config = new ApiConfig();
108        config.setAppId(appId);
109        config.setAppSecret(appSecret);
110        config.setToken(token);
111        return config;
112    }
113}