Angular 5 整合容联云 即时通讯

1.首先要登录容联云官网,注册帐号。然后建立应用,获取appid

2.下载容联云sdk,在项目中引用。

  1.     在index.html中引用 <script src="https://app.cloopen.com/im50/ytx-web-im-min-new-5.4.0.js"></script>
  2.     在typings.d.ts文件中,声明调用对象 declare var RL_YTX: any;
  3.     在自己的component中,添加sdk的初始化,注意在初始化成功函数内,调用登录函数。注意init函数的参数,改成自己的appid
    var resp = RL_YTX. init( '8a216da862fc745c01632005f49a0sdas');
    console. log( "resp.code", resp. code);
    if ( 170002 == resp. code) {
    //缺少必要参数,详情见msg参数
    //用户逻辑处理
    } else if ( 174001 == resp. code) {
    //不支持HTML5,关闭页面//用户逻辑处理}
    } else if ( 200 == resp. code) {
    //初始化成功
    //用户逻辑处理
    //判断不支持的功能,屏蔽页面展示
    var unsupport = resp. unsupport;
    this. success();
    }

    4.登录函数,sig的计算方式 appid+userid+时间戳+token  appid和token一定要换成自己的

success() {
//账号登录参数设置
var loginBuilder = new RL_YTX. LoginBuilder();
//登录类型 1账号登录,3voip账号密码登录
loginBuilder. setType( 1);
//设置用户名
loginBuilder. setUserName( this. userInfo. name);
//type值为1时,密码可以不赋值
loginBuilder. setPwd( this. userInfo. pass);
//设置sig
let timeType = this. getTimeStamp();
let need = '8a216da862fc745c01632005f49a0sdas' + this. userInfo. name + timeType + 'a65feab231a35caeb56a02253724807b';
let md5 = Md5. hashStr( need). toString();
loginBuilder. setSig( md5);
//设置时间戳
loginBuilder. setTimestamp( timeType);
//执行用户登录
let _this = this;
RL_YTX. login( loginBuilder, this. onMessageR, function ( obj) {
console. log( "错误码:", obj);
});
}

    5.时间戳计算函数

getTimeStamp() {
let now = new Date();
let timestamp = now. getFullYear() + '' + (( now. getMonth() + 1) >= 10 ? "" + ( now. getMonth() + 1) : "0" + ( now. getMonth() + 1)) + ( now. getDate() >= 10 ? now. getDate() : "0" + now. getDate()) + ( now. getHours() >= 10 ? now. getHours() : "0" + now. getHours()) + ( now. getMinutes() >= 10 ? now. getMinutes() : "0" + now. getMinutes()) + ( now. getSeconds() >= 10 ? now. getSeconds() : "0" + now. getSeconds());
return timestamp;
}

    6.注意引用md5 加密函数

    7.最终实现效果,发送接收消息可看官方文档实现。

    


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值