getRecommend.js
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const app = require('koa')
function getRecommend(auth) {
console.log("login success", auth);
const host = 'https://localhost:23023';
const url = host+"/api/profile/recommend";
const data = { username: 'test' };
window.fetch(url, {
method: "POST",
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(res => {
console.log(res);
return res.json();
})
.then(shareToKakao);
}
const TOKEN = 'tdN03DyXDAcKGZsuiPndaU7UC2GzuEQYUhPCkDnGWXGGdiPmV15QYbFU1U5JP5EpiETIKLqOmci/RxFZTfD7FRMED0OpT+3qgEYBNf8T9/jRzHRm7rblBLtzFBVOeXeYRcluOsz4koE4JaAJaUtMtwdB04t89/1O/w1cDnyilFU='
function shareToKakao({problem_number, problem_title, solved_date}) {
console.log('getting ready to share...');
const boj_link = "https://acmicpc.net/problem/" + problem_number.toString();
window.fetch('https://www.osstest17.ml:23023/hook', {
method: "POST",
body: JSON.stringify(data),
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":eventObj.replyToken,
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
}
})
window.Kakao.Link.sendDefault({
objectType: 'text',
text: `오늘의 추천문제는 ${problem_title}`,
link: {
mobileWebUrl: boj_link,
webUrl: boj_link,
}
});
}
export {
getRecommend as default
};