恭喜发财,大吉大利
{{::qmoney}}.00元
{{::item.word}}
{{::user.username}}
{{::item.word}}
{{::item.showname}}
(function () { var chat = angular.module('chat', ['ngDialog']); var user=window.localStorage['chatUser']; console.log("getuser-----"+user); var chats; var across_appkey = 'c900b384c454f33a91f490ca'; var target_nickname='xuqiin1'; var target_gname='xu_test' var tim=new Date().getTime(); var auth_platform = { "appkey": "c900b384c454f33a91f490ca", "random_str": "c900b384c454f33a91f490cacnev", "signature": "", "timestamp": tim }, hkey='db4295a9330d29112de3829d', bhkey=BASE64.encoder(auth_platform.appkey+":"+hkey), test={uname:"JSCrossTest",pwd:'123456'}; auth_platform.signature=hex_md5("appkey="+auth_platform.appkey+"×tamp="+auth_platform.timestamp+"&random_str="+auth_platform.random_str+"&key="+hkey); window.JIM = new JMessage({ // debug : true }); JIM.onDisconnect(function(){ console.log("【disconnect】"); }); //异常断线监听 console.log("开始"); //获取url参数 var curl = window.location.href; function GetQueryString(curl) { var reg = new RegExp("(^|&)"+ curl +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return unescape(r[2]); return null; } var gid = GetQueryString("group") chats=window.localStorage['chatArr'+gid]; var nickname = GetQueryString("nickname") // alert("name2==="+nickname); var username=request("nickname"); function request(paras) { var url = location.href; var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {} for (i = 0; j = paraString[i]; i++) { paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length); } var returnValue = paraObj[paras.toLowerCase()]; if (typeof (returnValue) == "undefined") { return ""; } else { return returnValue; } } chat.controller('FirstDialogCtrl', function ($scope,$http, $timeout,ngDialog) { var face = GetQueryString("face") $scope.toutuimage=face; $scope.next = function () { ngDialog.close('ngdialog1'); ngDialog.open({ template: 'secondDialog', controller: 'SecondDialogCtrl', className: 'ngdialog-theme-flat ngdialog-theme-custom' }); }; }); chat.controller('SecondDialogCtrl', function ($scope,$http, $timeout,ngDialog) { var face = GetQueryString("face") $scope.stoutuimage=face; var guser = GetQueryString("openid"); var qhb={hbbh:21,userid:guser,zbid:3}; $.ajax({ url:encodeURI("http://zhibo.cnev.cn/ajax/qianghongbaoh.ashx?"), type: "GET", contentType: "application/json; charset=utf-8", dataType: "json", data:qhb, success: function (data) { console.log("抢成功1"+JSON.stringify(data)); window.localStorage["money"]=data; console.log("抢成功2--"+ window.localStorage["money"]); }, error: function (xhr, textStatus, errorThrow) { alert("抢失败"+xhr.readyState); } }); $scope.qmoney=window.localStorage["money"]; // console.log("抢成功3--"+ $scope.qmoney); }); chat.controller('hongbaoDialogCtrl', function ($scope,$http,$timeout, ngDialog) { $scope.next = function () { }; //发红包函数 $scope.hongbao = function () { ngDialog.close('ngdialog1'); console.log("发送红包"); JIM.sendGroupMsg({ 'target_gid' : gid, 'target_gname' : target_gname, 'content' : "hongbao", 'at_list' : [{'username':user.username,'appkey':across_appkey}] }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); // if(data.code=="0"){ // console.log("发送成功"); // $timeout(function(){ // $scope.charArr.push({uname:user.username,word:"hongbao"}); // $scope.input.message=""; // $("#chatcon").animate({scrollTop:$("#scroll").height()},10); // window.localStorage['chatArr'+gid]=JSON.stringify($scope.charArr); // }); // }else{ // console.log("发送失败" + JSON.stringify(data)); // } }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); }); }; }); chat.controller('SecondhongbaoCtrl', function ($scope,$http, $timeout,ngDialog) { var face = GetQueryString("face") $scope.stoutuimage=face; }); chat.controller('chatCtl', function ($http, $scope,$timeout,ngDialog) { $scope.xx= "hongbao"; // var sname=decodeURI(username); // $scope.name2= sname; // var face = GetQueryString("face"); // $scope.userimage=face; // var openid = GetQueryString("openid"); // var ttt=decodeURIComponent(face); // console.log("eeeee---"+ttt); // var yonghu={openid:openid,wxtx:face}; if(gid) { console.log("组别---"+gid); // console.log("昵称---"+sname); // console.log("头像---"+face); // console.log("openid---"+openid); // console.log("getchat-----"+chats); //初始化 setTimeout(function () { try{ JIM.init({ "appkey": "c900b384c454f33a91f490ca", "random_str": "c900b384c454f33a91f490cacnev", "signature": auth_platform.signature, "timestamp": tim, }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); if(chats){ try{ console.log('ok:' ); console.log('初始:' ); chats=JSON.parse(chats); $scope.charArr=angular.copy(chats); setTimeout(function(){$("#chatcon").animate({scrollTop:$("#scroll").height()},200)},200); }catch(e){ } }else{ console.log('初始:' ); console.log('no:' ); $scope.charArr=[]; } var oldgid= window.localStorage['oldgroup']; console.log('no:' +oldgid); console.log('no1:' +gid); if(user) { $scope.randomimage=window.localStorage['image']; user=JSON.parse(user); console.log('no3:' +user.username); $scope.user=user; JIM.register({ 'username' : user.username, 'password': '123456', 'is_md5' : false }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); console.log('注册已经好了:'); if(data){ JIM.login({ 'username' : test.uname, 'password' : test.pwd }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); if(data.code=="0"){ console.log("test login success"); console.log("add group"); JIM.addGroupMembers({'gid':gid,'member_usernames':[{'username': user.username,'appkey': across_appkey}]}). onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); console.log("检验加组成功"); //登出 JIM.loginOut(); // $scope.randomimage=window.localStorage['image']; // user=JSON.parse(user); // $scope.user=user; console.log('randomimage1:'+randomimage); //初始化 init1(); }).onFail(function(data) { console.log('检验加组失败:'); console.log('error:' + JSON.stringify(data)); //登出 JIM.loginOut(); //初始化 // $scope.randomimage=window.localStorage['image']; // user=JSON.parse(user); // $scope.user=user; console.log('randomimage2:'+randomimage); init1(); }); }else{ alert("用户授权异常"+data.message); } }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); alert("组登录失败请重新进入直播间"); }).onTimeout(function(data) { console.log('timeout:' + JSON.stringify(data)); }); }else{ alert("用户初始化"+data); } }).onFail(function(data) { console.log('已注册1:'); console.log('error:' + JSON.stringify(data)); //登录 JIM.login({ 'username' : test.uname, 'password' : test.pwd }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); if(data.code=="0"){ console.log("admin login success2"); console.log("add group2"); JIM.addGroupMembers({'gid':gid,'member_usernames':[{'username': user.username,'appkey': across_appkey}]}). onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); console.log("加组成功2"); //登出 JIM.loginOut(); // $scope.randomimage=window.localStorage['image']; // user=JSON.parse(user); // $scope.user=user; //初始化 init1(); }).onFail(function(data) { console.log('加组失败2:'); console.log('error:' + JSON.stringify(data)); //登出 JIM.loginOut(); // $scope.randomimage=window.localStorage['image']; // user=JSON.parse(user); // $scope.user=user; //初始化 init1(); }); }else{ alert("用户授权异常"+data.message); } }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); alert("组登录失败2请重新进入直播间"); }).onTimeout(function(data) { console.log('timeout:' + JSON.stringify(data)); }); }); }else { var randomimage=Math.round(Math.random()*40); var touimage="/img/"+"face/"+"face"+randomimage+".jpg"; window.localStorage['image']=touimage; window.localStorage['touimage']=randomimage; $scope.randomimage=touimage; console.log("user不存在"+touimage); var randomUser="c"+(new Date().getTime()+"").substr(7,10); // var=randomUser.substr(2,2) user={username:randomUser,password:"123456"}; setTimeout(function () { register();},500); } // var randomUser="c"+(new Date().getTime()+"").substr(7,10); // console.log('randomUser:' +randomUser); // user={username:openid,password:"123456"}; // setTimeout(function () { register();},500); }).onFail(function(data) { console.log('error:' + JSON.stringify(data)) alert("初始化失败请重新进入直播间"); }); } catch(err) { alert("初始化失败请重新进入直播间1");//在此处理错误 } }, 2000); //在此运行代码 }else { alert("参数缺失"); } //发红包函数 // $scope.hongbao = function () // { // console.log("发送红包"); // JIM.sendGroupMsg({ // 'target_gid' : gid, // 'target_gname' : target_gname, // 'content' : "hongbao", // 'at_list' : [{'username':user.username,'appkey':across_appkey}] // }).onSuccess(function(data) { // console.log('success:' + JSON.stringify(data)); // if(data.code=="0"){ // console.log("发送成功"); // $timeout(function(){ // $scope.charArr.push({uname:user.username,word:"hongbao"}); // $scope.input.message=""; // $("#chatcon").animate({scrollTop:$("#scroll").height()},10); // window.localStorage['chatArr'+gid]=JSON.stringify($scope.charArr); // }); // }else{ // console.log("发送失败" + JSON.stringify(data)); // } // }).onFail(function(data) { // console.log('error:' + JSON.stringify(data)); // }); // }; //抢红包弹窗 $scope.clickToOpen=function () { ngDialog.open({ template: 'firstDialog', controller: 'FirstDialogCtrl', className: 'ngdialog-theme-default' }); }; //发红包弹窗 $scope.clickhongbao=function () { ngDialog.open({ template: 'hongbaoDialog', controller: 'hongbaoDialogCtrl', className: 'pupo' }); }; function register(){ JIM.register({ 'username' : user.username, 'password': '123456', 'is_md5' : false }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); console.log('注册已经好了:'); if(data){ JIM.login({ 'username' : test.uname, 'password' : test.pwd }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); if(data.code=="0"){ console.log("test login success"); console.log("add group"); JIM.addGroupMembers({'gid':gid,'member_usernames':[{'username': user.username,'appkey': across_appkey}]}). onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); console.log("加组成功"); //登出 JIM.loginOut(); //初始化 init1(); }).onFail(function(data) { console.log('加组失败:'); console.log('error:' + JSON.stringify(data)); console.log('失败:'); //登出 JIM.loginOut(); //初始化 init1(); }); }else{ alert("用户授权异常"+data.message); } }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); alert("组登录失败请重新进入直播间"); }).onTimeout(function(data) { console.log('timeout:' + JSON.stringify(data)); }); }else{ alert("用户初始化"+data); } }).onFail(function(data) { console.log('已注册:'); console.log('error:' + JSON.stringify(data)); //登录 JIM.login({ 'username' : test.uname, 'password' : test.pwd }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); if(data.code=="0"){ console.log("admin login success"); console.log("add group"); JIM.addGroupMembers({'gid':gid,'member_usernames':[{'username': user.username,'appkey': across_appkey}]}). onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); console.log("加组成功2"); //登出 JIM.loginOut(); //初始化 init1(); }).onFail(function(data) { console.log('加组失败2:'); console.log('error:' + JSON.stringify(data)); //登出 JIM.loginOut(); //初始化 init1(); }); }else{ alert("用户授权异常"+data.message); } }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); alert("组登录失败2请重新进入直播间"); }).onTimeout(function(data) { console.log('timeout:' + JSON.stringify(data)); }); }); } //初始化后登录 function init1(){ setTimeout(function () { try { JIM.init({ "appkey": "c900b384c454f33a91f490ca", "random_str": "c900b384c454f33a91f490cacnev", "signature": auth_platform.signature, "timestamp": tim, }).onSuccess(function(data) { console.log('初始:' + JSON.stringify(data)); console.log('success:' + JSON.stringify(data)); //登录 login(); }).onFail(function(data) { console.log('error:' + JSON.stringify(data)) }); } catch(err) { // console.log('err:'+err); alert("初始化失败请重新进入直播间"); //在此处理错误 } }, 1000); //在此运行代码 } //$scope.login=function(){ function login() { //初始化 console.log("user login..."); JIM.login({ 'username' :user.username, 'password': '123456', }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); $timeout(function(){$scope.user=user;$scope.input.sending=false;}); window.localStorage['chatUser']=JSON.stringify(user); console.log("user success:" + JSON.stringify(data)); JIM.onMsgReceive(function(data) { console.log('接收到消息啦 : ' + JSON.stringify(data)); if(data.messages[0].content.from_id){ console.log('akak啦 : '+data.messages[0].from_gid); $timeout(function(){ var conphoto= data.messages[0].content.msg_body.text.split("*"); var pho=conphoto[1]; var shown=conphoto[2]; console.log("aminconent..."+conphoto); console.log("conent..."+conphoto[0]); console.log("photo..."+pho); console.log("name..."+shown); $scope.charArr.push({uname:data.messages[0].content.from_id,word:conphoto[0],showname:shown,showimage:pho,time:new Date().getTime()}); $("#chatcon").animate({scrollTop:$("#scroll").height()},10); window.localStorage['chatArr'+gid]=JSON.stringify($scope.charArr); }); } }); JIM.onEventNotification(function(data) { console.log('event_receive: ' + JSON.stringify(data)); }); JIM.onSyncConversation(function(data) { //离线消息同步监听 console.log('event_receive: ' + JSON.stringify(data)); }); }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); }).onTimeout(function(data) { console.log('timeout:' + JSON.stringify(data)); }); } $scope.input={sending:1}; $scope.sendMessage = function (sendMessageForm) { if(!$scope.input.message){return;} $scope.input.sending=true; console.log("发送消息"+$scope.input.message); var postcontent= $scope.input.message+"*"+$scope.randomimage+"*"+user.username; JIM.sendGroupMsg({ 'target_gid' : gid, 'target_gname' : target_gname, 'content' :postcontent, 'at_list' : [{'username':user.username,'appkey':across_appkey}] }).onSuccess(function(data) { console.log('success:' + JSON.stringify(data)); if(data.code=="0"){ console.log("发送成功"); $timeout(function(){ // console.log("name--"+name1); // console.log("image1--"+$scope.userimage); $scope.charArr.push({uname:user.username,word:$scope.input.message,showname:user.username,showimage:$scope.randomimage}); $scope.input.message=""; $scope.input.sending=false; $("#chatcon").animate({scrollTop:$("#scroll").height()},10); window.localStorage['chatArr'+gid]=JSON.stringify($scope.charArr); }); }else{ console.log("发送失败" + JSON.stringify(data)); } }).onFail(function(data) { console.log('error:' + JSON.stringify(data)); }); }; }); }());