package com.yihu.platform.utils; import com.coreframework.vo.ReturnValue; import com.yihu.wsgw.api.AsyncBus; import com.yihu.wsgw.api.ServiceBus; import net.sf.json.JSONObject; /** * API返回接口 * * @author wengsb * @company yihu.com 2013年11月25日下午5:55:35 */ public class ApiUtil { /** * 返回结果 * * @param code * @param msg * @return */ public static JSONObject getRespJSON(int code, String msg) { JSONObject obj = new JSONObject(); obj.put("Code", code); obj.put("Message", msg); return obj; } /** * 同步调用 * * @param name * @param param * @return * @throws Exception */ public static JSONObject call(String name, JSONObject param) throws Exception { JSONObject o = new JSONObject(); if (param != null) { o = param; } //同步 String resp = ServiceBus.getInstance(ConfigUtil.getInstance().getCenterServerUrl().toString(), Constant.CLIENTID_UserPlatform).call(name, o.toString()); return JSONObject.fromObject(resp); } /** * 异步调用 * * @param name * @param param * @param async * @return * @throws Exception */ public static JSONObject asyncCall(String name, JSONObject param, boolean async) throws Exception { JSONObject o = new JSONObject(); if (param != null) { o = param; } //异步调用 ReturnValue returnValue = AsyncBus.get(ConfigUtil.getInstance().getCenterServerUrl().toString(), Constant.CLIENTID_UserPlatform).sendCall(name, o.toString()); JSONObject obj = new JSONObject(); obj.put("Code", returnValue.getCode()); obj.put("Message", returnValue.getMessage()); return obj; } }