在开发实时通信APP时我们经常会使用环信SDK来集成,环信目前来说是比较稳定和高效的即时聊天开发包,开发后台时我们经常需要管理环信的注册用户,删除是我们必须要有的管理手段。
下面的代码是删除环信注册账号的API使用方式:
public static int DeleteCode(String url, List> headerList) {
// TODO Auto-generated method stub
int iPostResultCode = 0;
DeleteMethod deMethod=new DeleteMethod(url);
String strPostResponseBody = "";
for(Mapm:headerList){
deMethod.setRequestHeader(m.get("headerName"), m.get("headerValue"));
}
try {
iPostResultCode = client.executeMethod(deMethod);
strPostResponseBody = deMethod.getResponseBodyAsString();
System.err.println("-->" + iPostResultCode);
System.err.println("===" + strPostResponseBody);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
deMethod.releaseConnection();
}
return iPostResultCode;
}
上面的代码是删除时调的工具方法,只要是执行删除请求的代码,下面我们来调用一下:
4String tokenUrl="http://a1.easemob.com/mdzy/*****/token";
String delUrl="http://a1.easemob.com/*****/*****/users/用户名";
MapparamMap=new HashMap();
paramMap.put("grant_type", "client_credentials");
paramMap.put("client_id", Config.hxclient_id);
paramMap.put("client_secret", Config.hxclient_secret);
MaptokenMap=JsonTools.jsonStrToMap(post(tokenUrl,paramMap));
System.out.println(JsonTools.toJson(tokenMap));
List>headerList=new ArrayList>();
Mapheader=new HashMap();
header.put("headerName", "Authorization");
header.put("headerValue", "Bearer
"+tokenMap.get("access_token").toString());
headerList.add(header);
DeleteCode(delUrl,headerList);