注册与验证
注册
1) 获取临时签名
https://www.yuelili.com/api/get_nonce/?json=get_nonce&controller=user&method=register
返回:
{"status":"ok","controller":"user","method":"register","nonce":"e05487d734"}
2) 注册
https://www.yuelili.com/api/user/register/?username=用户名&email=邮箱&nonce=临时签名&user_pass=密码
返回
{"status":"ok","cookie":"hhh|1658103551|fj2wNuLkpEWvaFqat9wwZCZ1xEYDxLqDtuIPb4v85mG|0158438708e173bb5cc1994fc4064094e5bf5a269ea527e15dfd9846096449b5","cookie_admin":"hhh|1658103551|EWJU4knjQfMlHPOr98VQmmrWZr5uAfk29DIsdzFLj0l|be78770bd52a3469d8dd18550bd6013a8fc9433f846a410722471001e991b263","cookie_name":"wordpress_logged_in_e93d33a6c5174cf3b638175359ffc7f5","user_id":1388,"username":"hhh"}
用户信息
get_userinfo 获取用户信息
https://www.yuelili.com/api/user/get_userinfo/?user_id=1
get_order 获取用户支付情况
https://www.yuelili.com/api/user/get_order/?product=文字ID&order_id=订单号
网站公开信息
get_categories 获取分类
https://www.yuelili.com/api/user/get_categories/
get_authors 获取所有作者
https://www.yuelili.com/api/user/get_authors/
商城
查询购买信息(同时获取登录cookie)
https://www.yuelili.com/api/user/generate_auth_cookie/?username=用户名&password=密码&product=文章ID
查询购买信息(同时验证本机mac)
https://www.yuelili.com/api/user/get_produt_auth/?username=用户名&password=密码&product=文章ID&mac=本机MAC
https://www.yuelili.com/api/user/register/?username=用户名&email=邮箱&nonce=临时签名&user_pass=密码
javascript
// 获取nonce
fetch('https://www.yuelili.com/api/get_nonce/?json=get_nonce&controller=user&method=register', {
'Content-Type': 'application/json',
'Accept': 'application/json'
}).then(function(response) {
return response.json()
}).then(function(res) {
console.log(res.nonce)
})
// 注册
fetch("https://www.yuelili.com/api/user/register/?username=用户名&email=邮箱&nonce=临时签名&user_pass=密码", {
"Content-Type": "application/json",
Accept: "application/json",
method: "POST",
})
.then(function (response) {
return response.json();
})
.then(function (res) {
console.log(res.nonce);
});
// 获取文章信息(可以加参数)
fetch('https://www.yuelili.com/wp-json/wp/v2/posts', {
'Content-Type': 'application/json',
'Accept': 'application/json'
}).then(function(response) {
return response.json()
}).then(function(posts) {
console.log(posts)
})
// 获取cookie/token
fetch('https://www.yuelili.com/wp-json/jwt-auth/v1/token', {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
username: "用户名",
password: "密码"
})
}).then(function(response) {
return response.json()
}).then(function(user) {
console.log(user.token)
// 储存在本地
localStorage.setItem('jwt', user.token)
})
// 发布文章
// 各种内容参数:https://blog.csdn.net/weixin_38633659/article/details/105924225
fetch('https://www.yuelili.com/wp-json/wp/v2/posts', {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': Bearer${localStorage.getItem('jwt')}
},
body:JSON.stringify({
title:"测试",
content:"测试内容",
status:"publish"
})
}).then(function(response) {
return response.json()
}).then(function(post) {
console.log(post)
})
// 修改文章
fetch('https://www.yuelili.com/wp-json/wp/v2/posts/文章ID', {
method: "PUT",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': Bearer${localStorage.getItem('jwt')}
},
// 要修改的内容
body:JSON.stringify({
title:"测试",
content:"测试内容",
status:"publish"
})
}).then(function(response) {
return response.json()
}).then(function(post) {
console.log(post)
})
// 删除文章
fetch('https://www.yuelili.com/wp-json/wp/v2/posts/21640', {
method: "DELETE",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': Bearer${localStorage.getItem('jwt')}
},
body:JSON.stringify({
force:false // false移动到回收站,true则永久删除
})
}).then(function(response) {
return response.json()
}).then(function(res) {
console.log(res)
})