package com.yonge.cooleshow.config;

import com.huifu.adapay.Adapay;
import com.huifu.adapay.model.MerConfig;
import com.yonge.cooleshow.props.HuifuProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 路由配置信息
 */
@Configuration
@EnableConfigurationProperties({HuifuProperties.class})
public class HuifuConfiguration {
	private static HuifuProperties huifuProperties;
	@Bean
	public MerConfig merConfig(HuifuProperties authProperties) {
		this.huifuProperties = authProperties;

		MerConfig merConfig = new MerConfig();
		merConfig.setApiKey(authProperties.getApiKey());
		merConfig.setApiMockKey(authProperties.getMockApiKey());
		merConfig.setRSAPrivateKey(authProperties.getRsaPrivateKey());
		try {
			Adapay.initWithMerConfig(merConfig);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return merConfig;
	}

	public static HuifuProperties getHuifuProperties(){
		return huifuProperties;
	}
}
