/**
* version 1.1.7
*/
import Config from '../config/config'
import $ from '../helpers/util'
import store from "../store";
class apiconfig {
constructor(config = {})
{
this.baseurl = 'https://test.lancerdt.com/index.php';
this.merchcode = 'cb0ac353f02a73a7c45885a862fe4de1';
this.pathconfig = {
login: "apicom/user/login", ///第三方登录,
regist: "apicom/user/regist", ///第三方注册,
checklogout: "apicom/user/checklogout", ///第三方注册,
registClientid: "/apicom/chat/registchater",///注册聊天通道,
initInfo: "apicom/commapi/initinfo",///获取用户个人信息 [usign=34],
sendMessage: 'apicom/commapi/sendmessageapp',///发送数据
getMessagelog: 'apicom/chatlog/mochatlog',///获取历史记录,
upload_image: this.baseurl + '/apicom/commapi/upload_image',///图片上传地址,
upload_voice: this.baseurl + '/apicom/commapi/upload_voice',///图片上传地址,
searchuser: '/apicom/commapi/searchapp',///图片上传地址,
getUinfoByid: '/apicom/set/getuserinfoByid',///图片上传地址,
sendInvite: '/apicom/commapi/savemsgapp',///图片上传地址,
getMsgbox: '/apicom/commapi/msgbox',///获取消息盒子的信息,
getlevemsg: '/apicom/commapi/levemsg',///获取与某个好友的留言信息,这样在第一次加载对话的时候就去检测一次
handlefirend: '/apicom/set/changeHandle',///同意好友请求,
createGroup: 'apicom/set/createGroup',
updateuserinfo: 'apicom/set/update',
getrecentmsg: 'apicom/chatlog/mochatlog',///最近20条记录
};
var alt = ["[微笑]", "[嘻嘻]", "[哈哈]", "[可爱]", "[可怜]", "[挖鼻]", "[吃惊]", "[害羞]", "[挤眼]", "[闭嘴]", "[鄙视]", "[爱你]", "[泪]", "[偷笑]", "[亲亲]", "[生病]", "[太开心]", "[白眼]", "[右哼哼]", "[左哼哼]", "[嘘]", "[衰]", "[委屈]", "[吐]", "[哈欠]", "[抱抱]", "[怒]", "[疑问]", "[馋嘴]", "[拜拜]", "[思考]", "[汗]", "[困]", "[睡]", "[钱]", "[失望]", "[酷]", "[色]", "[哼]", "[鼓掌]", "[晕]", "[悲伤]", "[抓狂]", "[黑线]", "[阴险]", "[怒骂]", "[互粉]", "[心]", "[伤心]", "[猪头]", "[熊猫]", "[兔子]", "[ok]", "[耶]", "[good]", "[NO]", "[赞]", "[来]", "[弱]", "[草泥马]", "[神马]", "[囧]", "[浮云]", "[给力]", "[围观]", "[威武]", "[奥特曼]", "[礼物]", "[钟]", "[话筒]", "[蜡烛]", "[蛋糕]"];
let arr = {};
alt.forEach(function(item, index){
arr[item] = 'https://static.lancerdt.com/xcxfile/appicon/im/face/'+ index + '.gif';
});
//表情库
this.faces = arr;
}
///把存聊天缓存放主文件里面 可全局调用 cacheid 缓存的对象的id cachetype对象类型(user,group)
cacheMessage(val, cachetype, cacheid, tempmy)
{
console.info('cacheMessage');
////聊天记录存入缓存
let msg = val;
uni.getStorage({
key: 'chatim',
fail(res)
{
if (res.data == '' || typeof (res.data) == 'undefined')
{
///如果没有缓存
let tempcache = new Object();
let chatlog = new Object();
let temparr = new Array();
temparr.push(msg);
if (cachetype == 'group')
{
chatlog['group'.concat(cacheid)] = temparr;
}
else
{
chatlog['friend'.concat(cacheid)] = temparr;
}
tempcache[tempmy.id] = {chatlog: chatlog};
uni.setStorage({
key: 'chatim',
data: tempcache
})
}
},
success(res)
{
console.log(res.data)
if (typeof (res.data[tempmy.id]) == 'undefined')
{
///处理同一台设备登录过多个账户
res.data[tempmy.id] = new Object();
}
///如果有
//1判断有没有对应该用户的聊天记录 有没有都添加
if (typeof (res.data[tempmy.id]['chatlog']) == 'undefined')
{
res.data[tempmy.id]['chatlog'] = new Object();
if (cachetype == 'group')
{
res.data[tempmy.id]['chatlog']['group' + cacheid] = new Array();
res.data[tempmy.id]['chatlog']['group' + cacheid].push(msg)
res.data[tempmy.id]['chatlog']['group' + cacheid] = res.data[tempmy.id]['chatlog']['group' + cacheid].slice(-10);
}
else
{
res.data[tempmy.id]['chatlog']['friend' + cacheid] = new Array();
res.data[tempmy.id]['chatlog']['friend' + cacheid].push(msg)
res.data[tempmy.id]['chatlog']['friend' + cacheid] = res.data[tempmy.id]['chatlog']['friend' + cacheid].slice(-10);
}
}
else
{
if (cachetype == 'group')
{
if (typeof (res.data[tempmy.id]['chatlog']['group' + cacheid]) == 'undefined')
{
res.data[tempmy.id]['chatlog']['group' + cacheid] = new Array();
}
res.data[tempmy.id]['chatlog']['group' + cacheid].push(msg)
res.data[tempmy.id]['chatlog']['group' + cacheid] = res.data[tempmy.id]['chatlog']['group' + cacheid].slice(-10);////只存10条记录
}
else
{
if (typeof (res.data[tempmy.id]['chatlog']['friend' + cacheid]) == 'undefined')
{
res.data[tempmy.id]['chatlog']['friend' + cacheid] = new Array();
}
res.data[tempmy.id]['chatlog']['friend' + cacheid].push(msg)
res.data[tempmy.id]['chatlog']['friend' + cacheid] = res.data[tempmy.id]['chatlog']['friend' + cacheid].slice(-10);
}
}
uni.setStorage({
key: 'chatim',
data: res.data
})
}
})
}
getrecentmsg_f(params, callback)
{
var that = this
$.request({
url: Config.URL.user.msg_chat_lists,
data: params,
loading:false,
success: function (data, status, msg, code) {
if (status == 200)
{
//$.alert(Lang.__("已关注!"))
callback && callback(data, status, msg, code)
}
else
{
//$.alert(msg)
callback && callback(data, status, msg, code)
}
}
})
return true;
}
getlevemsg_f(config)
{
return request.post(this.pathconfig.getlevemsg, config);
}
updateuserinfo_f(config)
{
return request.post(this.pathconfig.updateuserinfo, config);
}
createGroup_f(config)
{
return request.post(this.pathconfig.createGroup, config);
}
handlefirend_f(config)
{
return request.post(this.pathconfig.handlefirend, config);
}
getMsgbox_f(config)
{
return request.post(this.pathconfig.getMsgbox, config);
}
sendInvite_f(config)
{
return request.post(this.pathconfig.sendInvite, config);
}
getUinfoByid_f(config)
{
return request.post(this.pathconfig.getUinfoByid, config);
}
searchuser_f(config)
{
return request.post(this.pathconfig.searchuser, config);
}
login_f(config)
{
return request.post(this.pathconfig.login, config);
}
regist_f(config)
{
return request.post(this.pathconfig.regist, config);
}
checklogout_f(config)
{
return request.post(this.pathconfig.checklogout, config);
}
registClientid_f(config)
{
return request.post(this.pathconfig.registClientid, config);
}
initInfo_f(config)
{
return request.post(this.pathconfig.initInfo, config);
}
sendMessage_f(params, callback)
{
console.info(params);
var that = this
if (store.state.userInfo)
{
if(params.type === 'group'){
var url = Config.URL.user.zonemsg_add_msg;
} else {
var url = Config.URL.user.msg_add;
}
$.request({
type: 'post',
url: url,
data: params,
dataType: 'json',
loading:false,
success: (data, status, msg, code) => {
if (status == 200)
{
callback && callback(data, status, msg, code)
}
else
{
callback && callback(data, status, msg, code)
}
}
});
}
return true;
}
setMsgRead(msg_id, callback)
{
var that = this;
let params = {message_id:msg_id};
$.request({
type: 'post',
url: Config.URL.user.msg_set_read,
data: params,
dataType: 'json',
success: (data, status, msg, code) => {
if (status == 200)
{
callback && callback(data, status, msg, code)
}
else
{
callback && callback(data, status, msg, code)
}
}
});
return true;
}
getMessagelog_f(config)
{
return request.post(this.pathconfig.getMessagelog, config);
}
im_decode(content){
let that = this;
//支持的html标签
var html = function(end){
return new RegExp('\\n*\\['+ (end||'') +'(code|pre|div|span|p|table|thead|th|tbody|tr|td|ul|li|ol|li|dl|dt|dd|h2|h3|h4|h5)([\\s\\S]*?)\\]\\n*', 'g');
};
content = (content||'').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
//.replace(//g, '>').replace(/'/g, ''').replace(/"/g, '"') //XSS
.replace(/@(\S+)(\s+?|$)/g, '@$1$2') //转义@
.replace(/face\[([^\s\[\]]+?)\]/g, function(face){ //转义表情
var alt = face.replace(/^face/g, '');
return '';
})
.replace(/img\[([^\s]+?)\]/g, function(img){ //转义图片
//return '
';
return '
音频消息