[关闭]
@ranger-01 2019-06-16T00:46:33.000000Z 字数 2396 阅读 804

Library API specification

mimi_program


0. Structure

image_1br1fb5eu1im4g0q9b3d1d1gsu9.png-120.9kB

1. 小程序发往豆瓣的API

豆瓣图书API URL prefix: https://api.douban.com/v2/book/

1. Get book detail by id

  1. URL: /:book_id?apikey=0df993c66c0c636e29ecbb5344252a4a
  2. method: GET
  3. ret {
  4. ...
  5. }
  6. 返回结果直接参考:https://api.douban.com/v2/book/33411838?apikey=0df993c66c0c636e29ecbb5344252a4a

2. Get book by ISBN (扫描图书条码)

  1. URL: /isbn/:book_id?apikey=0df993c66c0c636e29ecbb5344252a4a
  2. method: GET
  3. ret {
  4. ...
  5. }
  6. 返回结果直接参考:https://api.douban.com/v2/book/isbn/9787521204569?apikey=0df993c66c0c636e29ecbb5344252a4a

3. search book

  1. URL: /search/tag=<text>?apikey=0df993c66c0c636e29ecbb5344252a4a
  2. or
  3. URL: /search/q=<text>?apikey=0df993c66c0c636e29ecbb5344252a4a
  4. method: GET
  5. ret {
  6. ...
  7. }
  8. 返回结果直接参考:
  9. https://library.pipiju.net/douban/v2/book/search?tag=%E7%BC%96%E7%A8%8B&apikey=0df993c66c0c636e29ecbb5344252a4a
  10. https://library.pipiju.net/douban/v2/book/search?q=ai&apikey=0df993c66c0c636e29ecbb5344252a4a

2. 小程序发完后台的API

1. API 列表

  1. # 进入小程序后,该微信用户需要向后台认证
  2. url(r'^api/wxlogin/$', views.wx_login)
  3. url(r'^api/v1/buy/$', views.buy),
  4. url(r'^api/v1/wish/$', views.make_wish),
  5. url(r'^api/v1/borrow_book/$', views.borrow_book),
  6. url(r'^api/v1/return_book/$', views.return_book),
  7. # 获取图书馆中已经购买的图书
  8. url(r'^api/v1/books/$', views.get_book_list),
  9. # 获取心愿单中的图书
  10. url(r'^api/v1/wish/books/$', views.get_wish_book_list),
  11. # 由于豆瓣API有调用次数限制,后台缓存了图书详情
  12. url(r'^api/v1/books/(?P<pk>[0-9]+)/$', views.get_book_info)

2. API detail

  1. # login from mini program
  2. URL: /api/v1/wxlogin/
  3. method: POST
  4. Data:
  5. {
  6. 'code': 'xxxxxxx',
  7. 'userinfo': {
  8. {
  9. "nickName": "NICKNAME",
  10. "gender": GENDER,
  11. "city": "CITY",
  12. "province": "PROVINCE",
  13. "country": "COUNTRY",
  14. "avatarUrl": "AVATARURL",
  15. }
  16. }
  17. ret:
  18. {
  19. "token": token.token,
  20. "token_type": "Bearer",
  21. "user_type": pu.type,
  22. "user_id": u.id
  23. }
  24. # operation on a book
  25. URL: /api/v1/book/
  26. operation: 'wish, buy, borrow, return',
  27. method: POST
  28. Data:
  29. {
  30. 'book_id': '123'
  31. }
  32. ret:
  33. {
  34. 'book_info': book_info,
  35. 'status': book.status,
  36. 'owner': book_owner,
  37. 'wishers': book.wishers.all().values(
  38. 'id', 'pyuser__nickname', 'pyuser__avatarUrl'
  39. )
  40. }
  41. # get book list info
  42. URL: /api/v1/books/
  43. method: GET
  44. type: 'wish, all',
  45. ret:
  46. {
  47. data: [
  48. {
  49. 'book_info': str_book_info,
  50. 'status': book.status,
  51. 'owner': {
  52. 'id': book.owner.id,
  53. 'nickname': book.owner.pyuser.nickname,
  54. 'avatarUrl': book.owner.pyuser.avatarUrl
  55. },
  56. 'wishers': book.wishers.all().values(
  57. 'id', 'pyuser__nickname', 'pyuser__avatarUrl'
  58. )
  59. },
  60. ]
  61. }

3. API 测试方法

  1. 登陆 https://library.pipiju.net/#!/login
    用户名密码:u_lib_admin/password123
  2. chrome F12 查看API请求详情
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注