12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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<String ,String> changeToMap(String params){
- Map<String, String> paramMap=new HashMap<String, String>();
- JSONObject json = JSONObject.fromObject(params);
- Iterator<String> 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;
- }
-
- }
|