云信IM

package com.hpm.blog.jdpush.utils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.hpm.blog.jdpush.utils.CheckSumBuilder;
import com.hpm.blog.mapper.UserMapper;

public class YunXinServerImpl {
      private static final Logger LOGGER = LoggerFactory.getLogger(YunXinServerImpl.class);        
      
        public static String register(String username) {
            // TODO Auto-generated method stub

            String accid= username;

            DefaultHttpClient httpClient = new DefaultHttpClient();
            String url ="https://api.netease.im/nimserver/user/create.action";

            HttpPost httpPost = new HttpPost(url);

            String appKey ="xxxxxxxxx";
            String appSecret = "xxxxxxxxx";
            String nonce =  "12345";
            String curTime = String.valueOf((new Date()).getTime() / 1000L);
            String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码

            // 设置请求的header
            httpPost.addHeader("AppKey", appKey);
            httpPost.addHeader("Nonce", nonce);
            httpPost.addHeader("CurTime", curTime);
            httpPost.addHeader("CheckSum", checkSum);
            httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

            // 设置请求的参数
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("accid", accid));
            try {
                httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            // 执行请求
            HttpResponse response = null;
            try {
                response = httpClient.execute(httpPost);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // 返回结果
            String result = "";
            try {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
            }catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println(result);

            return result;
        }
        
        public static String registupdate(String username) {
            // TODO Auto-generated method stub

            String accid= username;

            DefaultHttpClient httpClient = new DefaultHttpClient();
            String url ="https://api.netease.im/nimserver/user/refreshToken.action";

            HttpPost httpPost = new HttpPost(url);

            String appKey ="xxxxxxxxxx";
            String appSecret = "xxxxxxxx";
            String nonce =  "12345";
            String curTime = String.valueOf((new Date()).getTime() / 1000L);
            String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码

            // 设置请求的header
            httpPost.addHeader("AppKey", appKey);
            httpPost.addHeader("Nonce", nonce);
            httpPost.addHeader("CurTime", curTime);
            httpPost.addHeader("CheckSum", checkSum);
            httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

            // 设置请求的参数
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("accid", accid));
            try {
                httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            // 执行请求
            HttpResponse response = null;
            try {
                response = httpClient.execute(httpPost);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // 返回结果
            String result = "";
            try {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
            }catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println(result);

            return result;
        }

        public static String registerUpdate(String phoneNuber,String nickName,String avatar) {
            // TODO Auto-generated method stub

            String accid= phoneNuber;
            String name = nickName;
            String icon = avatar;
            DefaultHttpClient httpClient = new DefaultHttpClient();
            String url ="https://api.netease.im/nimserver/user/updateUinfo.action";

            HttpPost httpPost = new HttpPost(url);

            String appKey ="xxxxxxxx";
            String appSecret = "xxxxxxxxx";
            String nonce =  "12345";
            String curTime = String.valueOf((new Date()).getTime() / 1000L);
            String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码

            // 设置请求的header
            httpPost.addHeader("AppKey", appKey);
            httpPost.addHeader("Nonce", nonce);
            httpPost.addHeader("CurTime", curTime);
            httpPost.addHeader("CheckSum", checkSum);
            httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

            // 设置请求的参数
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("accid", accid));
            nvps.add(new BasicNameValuePair("name", name));
            nvps.add(new BasicNameValuePair("icon", icon));
            try {
                httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            // 执行请求
            HttpResponse response = null;
            try {
                response = httpClient.execute(httpPost);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // 返回结果
            String result = "";
            try {
                result = EntityUtils.toString(response.getEntity(), "utf-8");
            }catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println(result);

            return result;
        }
/*        public UserVo saveAccidAndToken(String username, String accid, String token) {

            UserVo user = userMapper.findByUsername(username);
            user.setAccid(accid);
            user.setToken(token);
            return userMapper.save(user);

        }*/
}

由于前端安卓那边说云信聊天和百度地图公用一个插件起冲突,最后导致项目放弃已经做好的云信改用极光IM。

所有如果聊天中要用到地图导航功能的话,用云信可能会出现我们团队遇到的情况。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值