Skip to content

Commit ab35a34

Browse files
committed
更新文章调用API接口
1 parent d413560 commit ab35a34

File tree

3 files changed

+54
-59
lines changed

3 files changed

+54
-59
lines changed

utils/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ module.exports = {
3737

3838
},
3939

40-
// 获取指定分类20的文章数据
40+
// 获取指定分类ID:20(首页:网友推荐)的文章数据
4141
getPostsByCategory: function (obj) {
42-
var url = HOST_URI + 'posts?per_page=7&orderby=date&order=desc&page=1&categories=20';
42+
var url = HOST_URI + 'posts?per_page=7&orderby=date&order=desc&page=1&categories=23';
4343
return url;
4444

4545
},
4646

47-
// 获取指定分类4的文章数据
47+
// 获取指定分类ID:4(首页:编辑推荐)的文章数据
4848
getPostsByCategory2: function (obj) {
4949
var url = HOST_URI + 'posts?per_page=7&orderby=date&order=desc&page=1&categories=4';
5050
return url;

utils/auth.js

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,61 +15,56 @@ var wxRequest = require('wxRequest.js')
1515
var Api = require('api.js');
1616
var app = getApp();
1717
module.exports = {
18-
//获取用户信息和openid
19-
getUsreInfo: function (userInfoDetail) {
20-
var wxLogin = wxApi.wxLogin();
21-
var jscode = '';
22-
23-
wxLogin().then(response => {
24-
jscode = response.code
25-
if (userInfoDetail ==null)
26-
{
27-
var userInfo = wxApi.wxGetUserInfo();
28-
return userInfo();
29-
}
30-
else
31-
{
32-
return userInfoDetail;
33-
}
34-
35-
36-
}).
37-
//获取用户信息
38-
then(response => {
39-
console.log(response.userInfo);
40-
console.log("成功获取用户信息(公开信息)");
41-
app.globalData.userInfo = response.userInfo;
42-
app.globalData.isGetUserInfo = true;
18+
//获取用户信息和openid
19+
getUsreInfo: function(userInfoDetail) {
20+
var wxLogin = wxApi.wxLogin();
21+
var jscode = '';
4322

44-
var data = {
45-
js_code: jscode,
46-
encryptedData: response.encryptedData,
47-
iv: response.iv,
48-
avatarUrl: response.userInfo.avatarUrl,
49-
nickname: response.userInfo.nickName
50-
}
51-
this.getOpenId(data);
52-
}).catch(function (error) {
53-
console.log('error: ' + error.errMsg);
54-
})
55-
},
56-
getOpenId(data)
57-
{
58-
var url = Api.getOpenidUrl();
59-
var postOpenidRequest = wxRequest.postRequest(url, data);
60-
//获取openid
61-
postOpenidRequest.then(response => {
62-
if (response.data.status == '200') {
63-
//console.log(response.data.openid)
64-
console.log("openid 获取成功");
65-
app.globalData.openid = response.data.openid;
66-
app.globalData.isGetOpenid = true;
23+
wxLogin().then(response => {
24+
jscode = response.code
25+
if (userInfoDetail == null) {
26+
var userInfo = wxApi.wxGetUserInfo();
27+
return userInfo();
28+
} else {
29+
return userInfoDetail;
30+
}
6731

68-
}
69-
else {
70-
console.log(response);
71-
}
72-
})
73-
}
32+
33+
}).
34+
//获取用户信息
35+
then(response => {
36+
console.log(response.userInfo);
37+
console.log("成功获取用户信息(公开信息)");
38+
app.globalData.userInfo = response.userInfo;
39+
app.globalData.isGetUserInfo = true;
40+
41+
var data = {
42+
js_code: jscode,
43+
encryptedData: response.encryptedData,
44+
iv: response.iv,
45+
avatarUrl: response.userInfo.avatarUrl,
46+
nickname: response.userInfo.nickName
47+
}
48+
this.getOpenId(data);
49+
}).catch(function(error) {
50+
console.log('error: ' + error.errMsg);
51+
})
52+
},
53+
getOpenId(data) {
54+
var url = Api.getOpenidUrl();
55+
var postOpenidRequest = wxRequest.postRequest(url, data);
56+
//获取openid
57+
postOpenidRequest.then(response => {
58+
if (response.data.status == '200') {
59+
//console.log(response.data.openid)
60+
console.log("openid 获取成功");
61+
app.globalData.openid = response.data.openid;
62+
app.globalData.isGetOpenid = true;
63+
64+
} else {
65+
console.log(response);
66+
}
67+
})
68+
},
7469

7570
}

utils/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var MINAPPTYPE="1";//小程序的类型,如果是企业小程序请填:0 ,
1818
var WEBSITENAME="叶赫先生"; //网站名称
1919
var ABOUTID = 100; //wordpress网站"页面"的id,注意这个"页面"是wordpress的"页面",不是"文章"
2020
var PAGECOUNT='10'; //每页文章数目
21-
var CATEGORIESID='all' //专题页显示全部的分类
22-
//var CATEGORIESID2= '4';//指定专题页显示的分类的id
21+
//var CATEGORIESID='all' //专题页显示全部的分类
22+
var CATEGORIESID= '1,2,3,4,8,20';//指定专题页显示的分类的id
2323
var INDEXLISTTYPE="all" //首页显示所有分类
2424
//var INDEXLISTTYPE ="1" //指定首页显示分类的id
2525
var PAYTEMPPLATEID = 'I43RuJVof3esUpH6b26wYJ5cZFgQ91wCBrbusA6zsEE';//支持作者消息模版id

0 commit comments

Comments
 (0)