融云IM即时通讯服务端Server开发获取token报错签名错误,请检查

公司业务需要,开发即时通讯系统,在融云基础上进行开发,在server搭建的时候还是蛮逗比的,真的是各种不会,不过还好都会解决掉!今天遇到的问题就是获取token的问题,不停的报错:“getToken:  {"code":1004,"errorMessage":"签名错误,请检查。"}”然后在融云官网注册应用API调试获取token完全可以啊?那这是为什么呢?给了userId 和username了啊仔细检查发现appsecret的值中有空格,赶紧改掉

然后在运行代码,发现结果还是很悲催的报错,一样的错!!!!很尴尬啊

于是乎网上各种找答案,发现没有解答,那就自己想办法,把所有其他的因素排除掉,那就是appKey和appsecret的因素,于是重新创建一个应用,重新拿到一个appKey和appSecret,将新的值加进去再看看:

此刻就很开心的喝杯咖啡!

发布了19 篇原创文章 · 获赞 7 · 访问量 1万+
展开阅读全文

android连接获取token报错

06-07

package cn.hhs.aitaodian.test; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; 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 java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.security.MessageDigest; import java.util.ArrayList; import java.util.List; /** * Created by Administrator on 2017/6/6 0006. */ public class GetToken { public static String GetRongCloudToken(String userID) { StringBuffer res = new StringBuffer(); String url = "https://api.cn.ronghub.com/user/getToken.json"; String App_Key = "****"; //开发者平台分配的 App Key。 String App_Secret = "******"; String Timestamp = String.valueOf(System.currentTimeMillis() / 1000);//时间戳,从 1970 年 1 月 1 日 0 点 0 分 0 秒开始到现在的秒数。 String Nonce = String.valueOf(Math.floor(Math.random() * 1000000));//随机数,无长度限制。 String Signature = sha1(App_Secret + Nonce + Timestamp);//数据签名。 HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setHeader("App-Key", App_Key); httpPost.setHeader("Timestamp", Timestamp); httpPost.setHeader("Nonce", Nonce); httpPost.setHeader("Signature", Signature); httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1); nameValuePair.add(new BasicNameValuePair("userId",userID)); nameValuePair.add(new BasicNameValuePair("name","张三")); nameValuePair.add(new BasicNameValuePair("portraitUri","https://ss2.bdstatic.com/8_V1bjqh_Q23odCf/pacific/upload_23068489_1486463968474.jpg")); HttpResponse httpResponse = null; try { httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair,"utf-8")); httpResponse = httpClient.execute(httpPost); BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); String line = null; while ((line = br.readLine()) != null) { res.append(line); } } catch (IOException e) { e.printStackTrace(); } /* UserRespone userRespone = JSON.parseObject(res.toString(), UserRespone.class); Logger.i(userRespone.getCode()+""); return userRespone.getToken();*/ return res.substring(0,res.length()); } //SHA1加密//http://www.rongcloud.cn/docs/server.html#通用_API_接口签名规则 private static String sha1(String data){ StringBuffer buf = new StringBuffer(); try{ MessageDigest md = MessageDigest.getInstance("SHA1"); md.update(data.getBytes()); byte[] bits = md.digest(); for(int i = 0 ; i < bits.length;i++){ int a = bits[i]; if(a<0) a+=256; if(a<16) buf.append("0"); buf.append(Integer.toHexString(a)); } }catch(Exception e){ } return buf.toString(); } } 报错:404 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览