Commit e930587b authored by 刘文胜's avatar 刘文胜

11111111

parent 7d9ec310
......@@ -437,6 +437,230 @@ router.get('/sharev2.js', function(req, res, next) {
}
});
}else if (type === 'Thread') {
then(function(cont) {
//获得文章
forumThreadService.getThreadByIdSimple({_id:id},cont);
}).then(function(cont, thread) {
if(!thread){
//文章不存在
cont('分享文章不存在');
}else{
share_log.type = 3;
share_log.thread = id;
share_log.p_thread = thread.pid;
share_log.info = thread.info._id || thread.info;
share_log.thread_type = thread.pid?4:thread.type;
//替换分享log内容
if(!req.session.shareLog || !req.session.shareLog._v || _v >= req.session.shareLog._v){
console.log('forumshare 3',share_log);
req.session.shareLog = share_log;
}
//组装分享路径与判断分享类型
var baseParamsUrl = '&infoId=' + thread.info._id + '&ent_code=' + ent_code + '&tId=' + thread._id +'&uId='+uId;
var share_type = '';
switch(thread.type){
case 1://文章
link = link + 'detail';
share_type = 'article';
title = thread.title == '发话题'?"":thread.title;
break;
case 2://话题
if(thread.level === 2){
link += 'detail';
share_type = 'article';
title = thread.pid.title;
}else if(thread.level === 1){
link += 'topic';
share_type = 'topic';
title = thread.title;
}
break;
case 3://照片墙
if(thread.level === 2){
link += 'photoDetail';
share_type = 'photo';
title = thread.pid.title;
}else if(thread.level === 1){
link += 'photoWall';
share_type = 'photo';
title = thread.title;
}
break;
}
desc = thread.content?thread.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"").replace(/\t/g,"").replace(/\n/g,""):'';
// 分享图标:帖子设置了share_pic就使用share_pic ,否则帖子带图片则使用第一张图片,否则使用发帖者的头像
if(thread.share_pic){
imgUrl = thread.share_pic;
}else if(thread.images && thread.images[0]){
imgUrl = thread.images[0].urlFileName;
}else{
imgUrl = thread.from.displayIcon || thread.from.icon || thread.info.icon;
}
link += baseParamsUrl;
//获取分享设置
if (thread.share_type!==2) {
//文章默认分享
getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
}else if(thread.share){
getWXV2(res, thread.share.title, thread.share.description, link, thread.share.icon, mid,ent_code,thread._id,type,thread);
} else {
getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
}
}
}).fail(function(cont, err) {
console.error(err);
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
});
}else{
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
}
}
});
router.get('/sharev3.js', function(req, res, next) {
//记录分享日志
var _v = new Date().getTime();//用于sharelog 版本号
var share_log = {_v:_v};
req.session.shareLog = {_v:_v};//新的分享对象
console.log('forumshare 1',req.session.shareLog);
var rs = {},
type = req.query.type,
id = req.query.id,
uId= req.session.mobileForumUser.userId,
ent_code = req.session.user.ent_code,
mid = req.session.openUser.mid,
link = '/app/forum/' + ent_code + '/index_v3?pageUrl=';
var title = '',desc = '',imgUrl = '';
var key = ent_code + 'forum_share_index_info_v3';
if(type && type === 'index'){
var expire = 60 * 60;
redis.get(key, function(error, share){
if(share){//有缓存
try{
share = JSON.parse(share);
title=share.title;
desc=share.desc;
link=share.linkUrl;
imgUrl=share.imgUrl;
if(link.indexOf('?') === -1){
link = link + '?uId='+ uId;
}else{
link = link + '&uId='+ uId;
}
}catch(err){
console.log(err);
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null,true);
}else{
then.parallel([
function(cont){
link = link + 'newindex';
cont();
},function(cont){
request.get({url:config.rest_api+'/v1.0/internal/forum/config/share/byentcode?entCode='+ent_code,body:{},json:true}, function (e, r, result) {
if(result && result.data){
try{
var obj = JSON.parse(result.data);
title = obj.shareTitle || '';
desc = obj.shareDescription || '';
imgUrl = obj.sharePictureUrl || '';
}catch(err){
console.log(err);
}
}
cont();
});
}
]).then(function(cont, datas) {
//放入redis缓存
redis.set(key,JSON.stringify({
title:title,
desc:desc,
linkUrl:link,
imgUrl:imgUrl
}),function(){
redis.expire(key, expire);
});
if(link.indexOf('?') === -1){
link = link + '?uId='+ uId;
}else{
link = link + '&uId='+ uId;
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null,true);
}).fail(function(cont, err) {
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
});
}
});
}else{
//板块微信接口
if(!type || !id){
console.error('请求参数错误')
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
}else if(type === 'notice'){
Notice.findOne({_id:id},function(err,result){
if (err || !result) {
console.error(err);
res.json(_.assign({result:false},returnCode.BUSY));
}
link = link + 'noticeDetail&infoId=' + (result.plate || '') + '&ent_code=' + ent_code + '&tId=' + result._id +'&uId='+uId;
title = result.title;
desc = result.content?result.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"").replace(/\t/g,"").replace(/\n/g,""):'';
redis.get(key, function(error, share){
if(share){//有缓存
try{
share = JSON.parse(share);
imgUrl=share.imgUrl;
}catch(err){
console.log(err);
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}else{
request.get({url:config.rest_api+'/v1.0/internal/forum/config/share/byentcode?entCode='+ent_code,body:{},json:true}, function (e, r, result) {
if(result.data){
try{
var obj = JSON.parse(result.data);
imgUrl = obj.sharePictureUrl || '';
}catch(err){
console.log(err);
}
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
});
}
});
});
}else if (type === 'Info') {
forumInfoService.getInfoById(id, function(err, forumInfo) {
if (err) {
console.error(err);
res.json(_.assign({result:false},returnCode.BUSY));
}else{
//分享记录对象
share_log.type = 2;
share_log.info = id;
//替换分享log内容
if(!req.session.shareLog || !req.session.shareLog._v || _v >= req.session.shareLog._v){
console.log('forumshare 2',share_log);
req.session.shareLog = share_log;
}
if(forumInfo.share_type && forumInfo.share_type == 1){
var shareInfo = forumInfo.share || {};
title = shareInfo.title,desc = shareInfo.description,imgUrl = shareInfo.icon;
}else{
title = forumInfo.name,desc = forumInfo.description,imgUrl = forumInfo.icon;
}
link = link + 'index&infoId='+ id+'&uId='+uId;
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}
});
}else if (type === 'Thread') {
then(function(cont) {
//获得文章
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment