4223c732695bc36edebbab39808c8d28d2af5d1e.svn-base 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.yihu.platform.utils;
  2. import com.coreframework.vo.ReturnValue;
  3. import com.yihu.wsgw.api.AsyncBus;
  4. import com.yihu.wsgw.api.ServiceBus;
  5. import net.sf.json.JSONObject;
  6. /**
  7. * API返回接口
  8. *
  9. * @author wengsb
  10. * @company yihu.com 2013年11月25日下午5:55:35
  11. */
  12. public class ApiUtil {
  13. /**
  14. * 返回结果
  15. *
  16. * @param code
  17. * @param msg
  18. * @return
  19. */
  20. public static JSONObject getRespJSON(int code, String msg) {
  21. JSONObject obj = new JSONObject();
  22. obj.put("Code", code);
  23. obj.put("Message", msg);
  24. return obj;
  25. }
  26. /**
  27. * 同步调用
  28. *
  29. * @param name
  30. * @param param
  31. * @return
  32. * @throws Exception
  33. */
  34. public static JSONObject call(String name, JSONObject param) throws Exception {
  35. JSONObject o = new JSONObject();
  36. if (param != null) {
  37. o = param;
  38. }
  39. //同步
  40. String resp = ServiceBus.getInstance(ConfigUtil.getInstance().getCenterServerUrl().toString(), Constant.CLIENTID_UserPlatform).call(name, o.toString());
  41. return JSONObject.fromObject(resp);
  42. }
  43. /**
  44. * 异步调用
  45. *
  46. * @param name
  47. * @param param
  48. * @param async
  49. * @return
  50. * @throws Exception
  51. */
  52. public static JSONObject asyncCall(String name, JSONObject param, boolean async) throws Exception {
  53. JSONObject o = new JSONObject();
  54. if (param != null) {
  55. o = param;
  56. }
  57. //异步调用
  58. ReturnValue returnValue = AsyncBus.get(ConfigUtil.getInstance().getCenterServerUrl().toString(), Constant.CLIENTID_UserPlatform).sendCall(name, o.toString());
  59. JSONObject obj = new JSONObject();
  60. obj.put("Code", returnValue.getCode());
  61. obj.put("Message", returnValue.getMessage());
  62. return obj;
  63. }
  64. }