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
134b62e3
Commit
134b62e3
authored
Apr 14, 2015
by
邓军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信分享接口
parent
a04eda39
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
712 additions
and
399 deletions
+712
-399
forumShare.js
app/controllers/mobile/forumShare.js
+171
-0
forumShareConfig.js
app/models/forumShareConfig.js
+26
-0
forumShareConfigService.js
app/service/forumShareConfigService.js
+30
-0
forumShareService.js
app/service/forumShareService.js
+17
-0
forumThreadService.js
app/service/forumThreadService.js
+468
-399
No files found.
app/controllers/mobile/forumShare.js
0 → 100644
View file @
134b62e3
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumShareConfigService
=
require
(
'../../service/forumShareConfigService'
);
var
forumShareService
=
require
(
'../../service/forumShareService'
);
var
config
=
require
(
'../../../config/config'
);
var
then
=
require
(
'thenjs'
);
//var forumInfoService = require('../../service/forumInfoService');
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
function
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
)
{
link
=
config
.
service
+
link
;
res
.
writeHead
(
200
,
{
'Content-Type'
:
'text/javascript'
,
'Cache-Control'
:
'no-cache'
,
'Pragma'
:
'no-cache'
});
// result.debug = 'true' === isDebug ? true : false;
// result.jsApiList = jsApiList;
res
.
write
(
'$(function(){'
);
// var title = type+'类型分享',
// link = 'http://sandbox.wxpai.cn/app/aubywx/100041',
// imgUrl = 'http://dev.fs.wxpai.cn/upload/100001_2015410_1428671539587_40.jpg',
// desc = '测试描述';
// var string = '';
var
string
=
'wx.onMenuShareTimeline({'
+
'
\
"title
\
":
\
"'
+
title
+
'
\
",'
+
'
\
"link
\
":
\
"'
+
link
+
'
\
",'
+
'
\
"imgUrl
\
":
\
"'
+
imgUrl
+
'
\
", '
+
'success: function(){},'
+
'cancel: function () {}'
+
' });'
+
' wx.onMenuShareAppMessage({'
+
'
\
"title
\
":
\
"'
+
title
+
'
\
", '
+
'
\
"desc
\
":
\
"'
+
desc
+
'
\
", '
+
'
\
"link
\
":
\
"'
+
link
+
'
\
", '
+
'
\
"imgUrl
\
":
\
"'
+
imgUrl
+
'
\
", '
+
'
\
"type
\
":
\'\'
,'
+
'
\
"dataUrl
\
":
\'\'
, '
+
'success: function(){},'
+
'cancel: function () { '
+
'}'
+
' });'
res
.
write
(
'wx.ready(function(){'
+
string
+
'});'
);
res
.
write
(
'wx.error(function(res){console.log(res);});'
);
res
.
write
(
'});'
);
res
.
end
();
}
//微信分享接口
router
.
get
(
'/:ent_code/share.js'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
var
type
=
req
.
query
.
type
;
var
id
=
req
.
query
.
id
;
var
ent_code
=
req
.
params
.
ent_code
;
var
link
=
'/app/forum/'
+
ent_code
+
'/index/'
;
if
(
type
)
{
//板块微信接口
if
(
type
===
'Info'
)
{
then
(
function
(
cont
)
{
forumShareConfigService
.
getByEntCode
(
ent_code
,
function
(
err
,
result
)
{
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
if
(
result
)
{
for
(
var
i
=
0
;
i
<
result
.
length
;
i
++
)
{
if
(
result
[
i
].
meta_key
===
'share_info_title'
)
{
title
=
result
[
i
].
meta_value
;
}
else
if
(
result
[
i
].
meta_key
===
'share_info_description'
)
{
desc
=
result
[
i
].
meta_value
;
}
else
if
(
result
[
i
].
meta_key
===
'share_info_icon'
)
{
imgUrl
=
result
[
i
].
meta_value
;
}
}
link
=
link
+
'index.html?infoId='
+
id
;
getWX
(
res
,
desc
,
title
,
link
,
imgUrl
);
}
else
{
cont
(
err
);
}
});
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
res
.
json
({
result
:
false
,
code
:
'10002'
});
});
}
else
if
(
!
id
)
{
console
.
error
(
"ID不能为空"
);
res
.
json
({
message
:
'ID不能为空'
,
result
:
false
,
code
:
'10002'
});
}
else
if
(
type
===
'Thread'
)
{
then
(
function
(
cont
)
{
//获得文章
forumThreadService
.
getById
(
id
,
function
(
err
,
result
)
{
if
(
result
)
{
cont
(
null
,
result
);
}
else
{
cont
(
err
);
}
});
}).
then
(
function
(
cont
,
result
)
{
//如果没有share值则用默认值
if
(
!
result
.
share
)
{
forumShareConfigService
.
getByEntCode
(
ent_code
,
function
(
err
,
sc
)
{
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
if
(
sc
)
{
var
key
=
''
;
//1、文章 2、话题 3、照片墙
if
(
result
.
type
===
1
||
(
result
.
type
===
2
&&
result
.
level
===
2
))
{
link
=
link
+
'main.html?infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
key
=
'article'
;
}
else
if
(
result
.
type
===
2
&&
result
.
level
===
1
)
{
link
=
link
+
'hot_topic.html?infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
key
=
'topic'
;
}
else
if
(
result
.
type
===
3
)
{
link
=
link
+
'photo.html?infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
key
=
'photo'
;
}
for
(
var
i
=
0
;
i
<
sc
.
length
;
i
++
)
{
if
(
sc
[
i
].
meta_key
===
'share_'
+
key
+
'_title'
)
{
title
=
sc
[
i
].
meta_value
;
}
else
if
(
sc
[
i
].
meta_key
===
'share_'
+
key
+
'_description'
)
{
desc
=
sc
[
i
].
meta_value
;
}
else
if
(
sc
[
i
].
meta_key
===
'share_'
+
key
+
'_icon'
)
{
imgUrl
=
sc
[
i
].
meta_value
;
}
}
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
);
}
else
{
cont
(
err
);
}
});
}
else
{
//如果有分享设置,则返回分享设置
forumShareService
.
getById
(
result
.
share
,
function
(
err
,
forumShare
)
{
//1、文章 2、话题 3、照片墙
if
(
result
.
type
===
1
||
(
result
.
type
===
2
&&
result
.
level
===
2
))
{
link
=
link
+
'main.html?infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
// key = 'article';
}
else
if
(
result
.
type
===
2
&&
result
.
level
===
1
)
{
link
=
link
+
'hot_topic.html?infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
//key = 'topic';
}
else
if
(
result
.
type
===
3
)
{
link
=
link
+
'photo.html?infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
//key = 'photo';
}
getWX
(
res
,
forumShare
.
title
,
forumShare
.
description
,
link
,
forumShare
.
icon
);
});
}
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
res
.
json
({
result
:
false
,
code
:
'10002'
});
});
}
}
else
{
res
.
json
({
result
:
false
,
code
:
'10002'
});
}
});
app/models/forumShareConfig.js
0 → 100644
View file @
134b62e3
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//分享内容
var
ForumShareConfigSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
require
:
true
,
index
:
true
},
meta_key
:
{
type
:
String
,
index
:
true
},
meta_value
:
{
type
:
Object
,
require
:
true
}
},
{
'collection'
:
'pisns_forum_share_config'
});
module
.
exports
=
mongoose
.
model
(
'ForumShareConfig'
,
ForumShareConfigSchema
);
app/service/forumShareConfigService.js
0 → 100644
View file @
134b62e3
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
ForumShareConfig
=
mongoose
.
model
(
'ForumShareConfig'
);
var
async
=
require
(
'async'
);
//创建配置信息
exports
.
createForumShareConfig
=
function
(
entity
,
callback
){
var
forumShareConfig
=
new
ForumShareConfig
(
entity
);
forumShareConfig
.
save
(
function
(
err
,
forumShareConfig
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
forumShareConfig
);
}
});
};
//根据ent_code获取配置信息
exports
.
getByEntCode
=
function
(
ent_code
,
callback
){
ForumShareConfig
.
find
({
ent_code
:
ent_code
},
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
};
\ No newline at end of file
app/service/forumShareService.js
0 → 100644
View file @
134b62e3
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
ForumShare
=
mongoose
.
model
(
'ForumShare'
);
//根据ID获取分享设置
exports
.
getById
=
function
(
id
,
callback
)
{
ForumShare
.
findOne
({
_id
:
id
},
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
}
\ No newline at end of file
app/service/forumThreadService.js
View file @
134b62e3
This diff is collapsed.
Click to expand it.
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