在使用消息推送服務器,推送消息的返回結果可能不是咱們想要的,這時候就得對消息返回結果進行封裝。java
//返回成功格式:{taskId=OSS-0316_d261997c9778384b3520cbeb7c95cddc, result=ok, status=successed_offline}
//錯誤格式:{result=AppidError}服務器
//封裝返回信息 //返回成功格式:{taskId=OSS-0316_d261997c9778384b3520cbeb7c95cddc, result=ok, status=successed_offline} //錯誤格式:{result=AppidError} GTResultVo gTResultVo = new GTResultVo(); String result = ret.getResponse().toString(); result = result.replace("{", ""); result = result.replace("}", ""); if(result.contains("result=ok")){ String[] attributeGroup = result.split(","); for(String str : attributeGroup){ String attribute = str.trim(); if(StringUtils.areNotEmpty(attribute)){ String name = attribute.split("=")[0]; String value = attribute.split("=")[1]; try { //首字母大寫 Character c = Character.toUpperCase(name.charAt(0)); String classMethod = c.toString().concat(name.substring(1)); Method m = gTResultVo.getClass().getDeclaredMethod("set" + classMethod, String.class); m.invoke(gTResultVo, value); } catch (Exception e) { e.printStackTrace(); } } } }else{ String name = result.split("=")[0]; String value = result.split("=")[1]; try { //首字母大寫 Character c = Character.toUpperCase(name.charAt(0)); String classMethod = c.toString().concat(name.substring(1)); Method m = gTResultVo.getClass().getDeclaredMethod("set" + classMethod, String.class); m.invoke(gTResultVo, value); } catch (Exception e) { e.printStackTrace(); } } return gTResultVo; |
/** /** private String taskId; |