后台注册环信IM账号

本文档介绍了如何在环信官网注册账号并创建应用,重点讲解了后台如何配置环信IM,包括编写HuanXinUtil工具类,获取hx_access_token以及使用createUser()接口创建用户的过程。
摘要由CSDN通过智能技术生成

1、https://www.easemob.com/ 环信官网注册账号
2、创建应用
这里写图片描述
3、创建完成之后点击
这里写图片描述
会出现如下信息,其中标注的为重要信息
这里写图片描述

4、编写环信工具类HuanXinUtil

package com.fh.util;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

import net.sf.json.JSONObject;

public class HuanXinUtil {

//  private   String targetURL = "https://a1.easemob.com/1177180507177107/bit/chatrooms";
    private String uri = "https://a1.easemob.com/1177180507177107/bit/";
    private   String hx_client_id = "";
    private   String hx_client_Secret = "";
    private   String hx_access_token = "";
    private   long hx_token_time = 0;
    private static String profilepath = "WEB-INF/classes/hx_key.properties";


    public HuanXinUtil(){

        String filePath = String.valueOf(Thread.currentThread().getContextClassLoader().getResource(""))+"../../";  //项目路径
        filePath = filePath.replaceAll("file:/", "");
        filePath = filePath.replaceAll("%20", " ");
        filePath = filePath.trim()+profilepath;
        //filePath = "D://hx_key.properties";

        Properties properties = new Properties();

        try {
            InputStream in = new BufferedInputStream(new FileInputStream(filePath));   
            properties.load(in);
            hx_client_id = properties.getProperty("hx_client_id");
            hx_client_Secret = properties.getProperty("hx_client_Secret");
            hx_access_token = properties.getProperty("hx_access_token");
            hx_token_time = Long.parseLong(properties.getProperty("hx_token_time"));
            in.close();
            Date date = new Date(hx_token_time);
            System.out.println(date.before(new Date()));
            if(date.before(new Date())){
                hx_access_token=this.getAccessToken(hx_client_id, hx_client_Secret);
                Calendar now = Calendar.getInstance();   
                now.setTime(new Date());   
                now.set(Calendar.DATE, now.get(Calendar.DATE) + 5); 
                hx_token_time =now.getTimeInMillis();
                FileOutputStream fileOutputStream = new FileOutputStream(filePath);
                properties.setProperty("hx_token_time", Long.toString(hx_token_time));
                properties.setProperty("hx_access_token", hx_access_token);
                properties.store(fileOutputStream, "update access_token");
                fileOutputStream.close();
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值