package com.sqx.config;

import com.jfinal.weixin.sdk.api.ApiConfig;
import com.jfinal.wxaapp.WxaConfig;
import com.sqx.modules.common.service.CommonInfoService;
import net.dreamlu.weixin.config.WxConfigLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;
import java.util.List;

/**
 * API文档: https://gitee.com/jfinal/jfinal-weixin/wikis/pages?title=Home
 */
@Configuration
public class WxConfigDatabaseConfig implements WxConfigLoader {

    @Autowired
    private CommonInfoService commonInfoService;

    @Override
    public List<ApiConfig> loadWx() {
        String appId = commonInfoService.findOne(5).getValue();
        String token = commonInfoService.findOne(16).getValue();
        String appSecret = commonInfoService.findOne(21).getValue();
        ApiConfig wxConf = new ApiConfig();
        wxConf.setAppId(appId);
        wxConf.setAppSecret(appSecret);
        wxConf.setToken(token);
        wxConf.setEncryptMessage(false);
        return Collections.singletonList(wxConf);
    }

    @Override
    public List<WxaConfig> loadWxa() {
        return Collections.emptyList();
    }
}
