welcome to xlongwei.com

欢迎大家一起学习、交流、分享


QQ:9167702333 邮箱:admin@xlongwei.com

ApiStoreUtil 百度接口服务工具类


分类 Java   关键字 分享   标签 java   algorithm   发布 hongwei  1444387550557
注意 转载须保留原文链接,译文链接,作者译者等信息。  
ApiStoreUtil提供了百度接口服务调用机制,可以很方便地调用这里提供的开放API接口。

短信接口介绍是免费其实并不是的,这里的两个短信接口调用都因余额不足不能成功,还是考虑ShowApi提供的接口吧,技术和客服响应都非常及时,参考ShowApiUtil代码。

public class ApiStoreUtil {
	private static String apiStore ="http://apis.baidu.com";
	private static Logger logger = LoggerFactory.getLogger(ApiStoreUtil.class);
	
	public static boolean validate(String type, String value) {
		Map<String, String> params = new HashMap<>();
		params.put("type", type);
		params.put("value", value);
		String get = get(apiStore+"/xlongwei/open/validate", params);
		logger.info("validate response: "+get);
		return JSONUtil.getBoolean(get, "valid");
	}
	
	public static boolean smsXingqi(String mobile, String content) {
		Map<String, String> params = new HashMap<>();
		params.put("m", mobile);
		params.put("c", content);
		String get = get(apiStore+"/xingqitel/app_sms/app_sms", params);
		logger.info("smsXingqi response: "+get);
		return "1".equals(XMLObject.fromXML(get).getAttr("result"));
	}
	
	public static boolean smsLehuo(String mobile, String content) {
		Map<String, String> params = new HashMap<>();
		params.put("phone", mobile);
		params.put("content", content);
		String get = get(apiStore+"/hunanlehuotechnologyco/sms/api", params);
		logger.info("smsXingqi response: "+get);
		return JSONUtil.getInt(get, "result")==0;
	}
	
	public static String get(String service, Map<String, String> params) {
		String apikey = GlobalConfig.getProperty("apistore.apikey");
		if(StringUtil.isBlank(apikey)) return null;
		Map<String, String> headers = new HashMap<>();
		headers.put("apikey", apikey);
		return ServiceRequester.get(service, params, headers);
	}
}