本地获得 Token

2016-09-18  本文已影响371人  郭鵬飛on

本地获取方式/* 获取token / function getToken(userId, username) { var callback = function(ret, err) { api.setPrefs({key : 'token',value : ret.token}); rong.connect({ token : ret.token }, function(ret, err) { console.log('连接token:'+JSON.stringify(ret)); if (ret.status != "success") { showToast('聊天功能暂不可用'); } startActivity(); }); }; ajaxToRongCloud(userId, username, callback); } /自定义 和融云通信的 ajax 方法. */ function ajaxToRongCloud(userId, name, callback) { var appKey = "你的AppKey"; var appSecret = "你的AppSecret"; console.log('当前人id:'+userId+'当前人name:'+name+'得到key:' + appKey + ' ,得到Secret:' + appSecret); var nonce = Math.floor(Math.random() * 1000000); var timestamp = Date.now(); var signature = hex_sha1("" + appSecret + nonce + timestamp); var userId = userId; var name = name; var portraitUri = ""; var url = "https://api.cn.rong.io/user/getToken.json"; api.ajax({ url : url, method : "post", headers : { "RC-App-Key" : appKey, "RC-Nonce" : "" + nonce, "RC-Timestamp" : "" + timestamp, "RC-Signature" : "" + signature, "Content-Type" : "application/x-www-form-urlencoded" }, data : { values : { userId : userId, name : name, portraitUri : portraitUri } } }, function(ret, err) { if ("function" == typeof callback) { callback(ret, err) } }); }

上一篇 下一篇

猜你喜欢

热点阅读