package com.yihu.utils; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.yihu.base.ConfigUtil; import com.yihu.wsgw.api.ServiceBus; import net.sf.json.JSONObject; public class ApiUtil { /** * 返回结果 * * @param code * @param msg * @return */ public static JSONObject jsonResult(int code, String msg) { JSONObject obj = new JSONObject(); obj.put("Code", code); obj.put("Message", msg); return obj; } /** * 调用接口 * * @param appId 渠道号 * @param apiName api名 * @param params 参数 * @return * @throws Exception */ public static String callApi(String apiName,String params) throws Exception { return callApi(null,apiName,params); } /** * 调用接口 * * @param appId 渠道号 * @param apiName api名 * @param params 参数 * @return * @throws Exception */ public static String callApi(String appId,String apiName,String params) throws Exception { if (appId == null) { appId = ConfigUtil.getInstance().getAppId(); } String result = null; result = ServiceBus.getInstance( ConfigUtil.getInstance().getCenterServerUrl().toString(), appId).call(apiName, params, true); return result; } public static Map changeToMap(String params){ Map paramMap=new HashMap(); JSONObject json = JSONObject.fromObject(params); Iterator keys=json.keys(); while(keys.hasNext()){ String key=keys.next(); Object val= json.get(key); paramMap.put(key, val==null?null:val.toString()); } return paramMap; } }