java 环信集成

引入jar包:

        
            
                org.glassfish.jersey
                jersey-bom
                pom
                import
                2.15
            
        



    org.easymock
    easymock
    3.4


    org.apache.httpcomponents
    httpclient
    4.3.3


    org.apache.httpcomponents
    httpmime
    4.3.3


    org.apache.commons
    commons-lang3
    3.3.2


    org.glassfish.jersey.core
    jersey-client


    org.glassfish.jersey.media
    jersey-media-json-jackson


    org.glassfish.jersey.media
    jersey-media-multipart



引入环信代码:

下载添加到程序中。

public static String hxRegister(String teacherPhone){
		EasemobRestAPIFactory factory = ClientContext.getInstance().init(ClientContext.INIT_FROM_PROPERTIES).getAPIFactory();
		IMUserAPI user = (IMUserAPI)factory.newInstance(EasemobRestAPIFactory.USER_CLASS);
		
		BodyWrapper userBody = new IMUserBody("t_hx_"+teacherPhone, "123456", "");
		Object obj = user.createNewIMUserSingle(userBody);
		
		String responseStr = obj.toString().substring(obj.toString().indexOf("Response Body")+15,obj.toString().length());
		Map responseMap = JSON.parseObject(responseStr, Map.class);
		
		String entity = responseMap.get("entities").toString();
		Map emtityMap = JSON.parseObject(entity.substring(1,entity.length()-1), Map.class);
		
		return emtityMap.get("username").toString();
	}


还要引入证书、config.properties文件。


证书的路径使用的是相对路径,如果找不到的话使用绝对路径。


你可能感兴趣的:(JAVA,环信)