Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
d046aa8e
Commit
d046aa8e
authored
Jan 26, 2016
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
社区分享
parent
ab6de49e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
97 deletions
+142
-97
forumShare.js
app/controllers/mobile/forumShare.js
+139
-97
config.js
config/config.js
+3
-0
No files found.
app/controllers/mobile/forumShare.js
View file @
d046aa8e
...
@@ -3,6 +3,7 @@ var express = require('express'),
...
@@ -3,6 +3,7 @@ var express = require('express'),
router
=
express
.
Router
(),
router
=
express
.
Router
(),
_
=
require
(
'lodash'
),
_
=
require
(
'lodash'
),
then
=
require
(
'thenjs'
),
then
=
require
(
'thenjs'
),
request
=
require
(
'request'
),
mongoose
=
require
(
'mongoose'
);
mongoose
=
require
(
'mongoose'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
),
var
forumThreadService
=
require
(
'../../service/forumThreadService'
),
...
@@ -236,11 +237,15 @@ router.get('/:ent_code/share/singlemessage', function(req, res, next) {
...
@@ -236,11 +237,15 @@ router.get('/:ent_code/share/singlemessage', function(req, res, next) {
}
}
});
});
});
});
function
getWXV2
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
id
,
type
,
forumThread
)
{
function
getWXV2
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
id
,
type
,
forumThread
,
fullurl
)
{
//['{板块名称}','{文章标题}','{话题名称}','{照片墙标题}'];
//['{板块名称}','{文章标题}','{话题名称}','{照片墙标题}'];
//share_type:是否使用默认设置:1使用默认分享设置 2.使用自己的分享设置
//share_type:是否使用默认设置:1使用默认分享设置 2.使用自己的分享设置
link
=
config
.
service
+
link
+
"&mid="
+
mid
;
if
(
fullurl
){
link
=
link
+
"&mid="
+
mid
;
}
else
{
link
=
config
.
service
+
link
+
"&mid="
+
mid
;
}
if
(
type
===
"Info"
)
{
if
(
type
===
"Info"
)
{
forumInfoService
.
getInfoById
(
id
,
function
(
err
,
forumInfo
)
{
forumInfoService
.
getInfoById
(
id
,
function
(
err
,
forumInfo
)
{
if
(
err
||
forumInfo
<
1
)
{
if
(
err
||
forumInfo
<
1
)
{
...
@@ -298,106 +303,143 @@ router.get('/sharev2.js', function(req, res, next) {
...
@@ -298,106 +303,143 @@ router.get('/sharev2.js', function(req, res, next) {
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
//板块微信接口
if
(
type
&&
type
===
'index'
){
if
(
!
type
||
!
id
){
then
.
parallel
([
console
.
error
(
'请求参数错误'
)
function
(
cont
){
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
));
//type为index时的,默认link
}
else
if
(
type
===
'Info'
)
{
link
=
config
.
service
+
'/app/forum/'
+
ent_code
+
'/mediashequn'
+
'?uId='
+
uId
;
//分享记录对象
request
.
get
({
url
:
config
.
rest_api
+
'/v1.0/internal/forum/config/enter/byentcode?entCode='
+
ent_code
,
body
:{},
json
:
true
},
function
(
e
,
r
,
result
)
{
share_log
.
type
=
2
;
if
(
result
.
data
){
share_log
.
info
=
id
;
if
(
result
.
data
.
indexOf
(
'?'
)
===
-
1
){
//替换分享log内容
link
=
result
.
data
+
'?uId='
+
uId
;
req
.
session
.
shareLog
=
share_log
;
}
else
{
link
=
result
.
data
+
'&uId='
+
uId
;
forumInfoService
.
getInfoById
(
id
,
function
(
err
,
forumInfo
)
{
}
if
(
err
)
{
}
console
.
error
(
err
);
cont
();
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
BUSY
));
});
}
else
{
},
function
(
cont
){
if
(
forumInfo
.
share_type
&&
forumInfo
.
share_type
==
1
){
request
.
get
({
url
:
config
.
rest_api
+
'/v1.0/internal/forum/config/share/byentcode?entCode='
+
ent_code
,
body
:{},
json
:
true
},
function
(
e
,
r
,
result
)
{
var
shareInfo
=
forumInfo
.
share
||
{};
if
(
result
.
data
){
title
=
shareInfo
.
title
,
desc
=
shareInfo
.
description
,
imgUrl
=
shareInfo
.
icon
;
try
{
}
else
{
var
obj
=
JSON
.
parse
(
result
.
data
);
title
=
forumInfo
.
name
,
desc
=
forumInfo
.
description
,
imgUrl
=
forumInfo
.
icon
;
title
=
obj
.
shareTitle
||
''
;
}
desc
=
obj
.
shareDescription
||
''
;
link
=
link
+
'index&infoId='
+
id
+
'&uId='
+
uId
;
imgUrl
=
obj
.
sharePictureUrl
||
''
;
getWXV2
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
id
,
type
,
null
);
}
catch
(
err
){
console
.
log
(
err
);
}
}
cont
();
});
}
}
]).
then
(
function
(
cont
,
datas
)
{
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
{
}
else
if
(
type
===
'Thread'
)
{
//板块微信接口
then
(
function
(
cont
)
{
if
(
!
type
||
!
id
){
//获得文章
console
.
error
(
'请求参数错误'
)
forumThreadService
.
getThreadByIdSimple
({
_id
:
id
},
cont
);
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
));
}).
then
(
function
(
cont
,
thread
)
{
}
else
if
(
type
===
'Info'
)
{
if
(
!
thread
){
//分享记录对象
//文章不存在
share_log
.
type
=
2
;
cont
(
'分享文章不存在'
);
share_log
.
info
=
id
;
}
else
{
//替换分享log内容
share_log
.
type
=
3
;
req
.
session
.
shareLog
=
share_log
;
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内容
req
.
session
.
shareLog
=
share_log
;
//组装分享路径与判断分享类型
forumInfoService
.
getInfoById
(
id
,
function
(
err
,
forumInfo
)
{
var
baseParamsUrl
=
'&infoId='
+
thread
.
info
.
_id
+
'&ent_code='
+
ent_code
+
'&tId='
+
thread
.
_id
+
'&uId='
+
uId
;
if
(
err
)
{
var
share_type
=
''
;
console
.
error
(
err
);
switch
(
thread
.
type
){
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
BUSY
));
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
(
/ /g
,
""
).
replace
(
/
\t
/g
,
""
).
replace
(
/
\n
/g
,
""
):
''
;
// 分享图标:帖子带图片则使用第一张图片,否则使用发帖者的头像
if
(
thread
.
images
&&
thread
.
images
[
0
]){
imgUrl
=
thread
.
images
[
0
].
urlFileName
;
}
else
{
}
else
{
imgUrl
=
thread
.
from
.
displayIcon
||
thread
.
from
.
icon
||
thread
.
info
.
icon
;
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
);
}
}
});
link
+=
baseParamsUrl
;
}
else
if
(
type
===
'Thread'
)
{
//获取分享设置
then
(
function
(
cont
)
{
if
(
thread
.
share_type
!==
2
)
{
//获得文章
//文章默认分享
forumThreadService
.
getThreadByIdSimple
({
_id
:
id
},
cont
);
getWXV2
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
thread
.
_id
,
type
,
thread
);
}).
then
(
function
(
cont
,
thread
)
{
}
else
if
(
thread
.
share
){
if
(
!
thread
){
getWXV2
(
res
,
thread
.
share
.
title
,
thread
.
share
.
description
,
link
,
thread
.
share
.
icon
,
mid
,
ent_code
,
thread
.
_id
,
type
,
thread
);
//文章不存在
}
else
{
cont
(
'分享文章不存在'
);
getWXV2
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
thread
.
_id
,
type
,
thread
);
}
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内容
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
(
/ /g
,
""
).
replace
(
/
\t
/g
,
""
).
replace
(
/
\n
/g
,
""
):
''
;
// 分享图标:帖子带图片则使用第一张图片,否则使用发帖者的头像
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
)
{
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
)
);
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
)
);
}
);
}
);
}
}
}
});
});
\ No newline at end of file
config/config.js
View file @
d046aa8e
...
@@ -9,6 +9,7 @@ var config = {
...
@@ -9,6 +9,7 @@ var config = {
app
:
{
app
:
{
name
:
'pisns-forum-api'
name
:
'pisns-forum-api'
},
},
rest_api
:
'http://localhost:8080'
,
service
:
'http://localhost'
,
service
:
'http://localhost'
,
port
:
3011
,
port
:
3011
,
mongodb
:
{
mongodb
:
{
...
@@ -38,6 +39,7 @@ var config = {
...
@@ -38,6 +39,7 @@ var config = {
app
:
{
app
:
{
name
:
'pisns-forum-api'
name
:
'pisns-forum-api'
},
},
rest_api
:
'http://rest.wxpai.cn'
,
service
:
'http://sandbox.wxpai.cn'
,
service
:
'http://sandbox.wxpai.cn'
,
port
:
3011
,
port
:
3011
,
mongodb
:
{
mongodb
:
{
...
@@ -67,6 +69,7 @@ var config = {
...
@@ -67,6 +69,7 @@ var config = {
app
:
{
app
:
{
name
:
'pisns-forum-api'
name
:
'pisns-forum-api'
},
},
rest_api
:
'https://rest.wxpai.cn'
,
service
:
'http://piplus.wxpai.cn'
,
service
:
'http://piplus.wxpai.cn'
,
port
:
3011
,
port
:
3011
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment