JunziqianClientInit.java
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;
}
}