123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 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;
- }
- }
|