JunziqianClientInit.java 2.26 KB
package com.project.demo;

import com.junziqian.api.JunziqianClient;
import org.ebaoquan.rop.thirdparty.com.google.common.collect.Maps;
import org.ebaoquan.rop.thirdparty.org.apache.commons.lang3.StringUtils;
import org.ebaoquan.rop.utils.spring.Assert;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;

/**
 * Created by wlinguo on 5/11/2016.
 */
public class JunziqianClientInit {
	// 请填入服务地址(根据环境的不同选择不同的服务地址),沙箱环境,正式环境
	public static final String SERVICE_URL = "http://api.junziqian.com/services";

	// 请填入你的APPKey
	public static final String APP_KEY = "dda683a619751e69";

	// 请填入你的APPSecret
	public static final String APP_SECRET = "34a07facdda683a619751e69c4a887b8";

	protected static Map<String, String> props = Maps.newHashMap();

	private static JunziqianClient client;

	static {

		String filePath = "/Users/xuwenhao/Documents/banner.txt";
		InputStreamReader reader;
		try {
			File file=new File(filePath);
			Assert.isTrue(file!=null&&file.exists()&&file.isFile(),filePath+",文件不存在、或地址不是一文件、或文件为空");
			reader = new InputStreamReader(new FileInputStream(new File(filePath)));
			Properties properties = new Properties();
			properties.load(reader);
			Enumeration<?> it = properties.propertyNames();
			while (it.hasMoreElements()) {
				String propName = (String) it.nextElement();
				props.put(propName, properties.getProperty(propName));
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}
//		SERVICE_URL = props.get("services_url");
//		APP_KEY = props.get("app_key");
//		APP_SECRET = props.get("app_secret");
		if (StringUtils.isBlank(SERVICE_URL)) {
			throw new RuntimeException("SERVICE_URL is null");
		}
		if (StringUtils.isBlank(APP_KEY)) {
			throw new RuntimeException("APP_KEY is null");
		}
		if (StringUtils.isBlank(APP_SECRET)) {
			throw new RuntimeException("APP_SECRET is null");
		}
		client = new JunziqianClient(SERVICE_URL, APP_KEY, APP_SECRET);
	}

	public static JunziqianClient getClient() {
		return client;
	}
}