知识付费微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import http from './http.js'
  2. const config = {
  3. // 示例
  4. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  5. // auth : false, showLoading : true, loadingTitle : '加载中...',
  6. // limit : 1000
  7. // },
  8. getConfig : {url : '/api/getConfig', method : 'GET'},
  9. // 登录接口
  10. loginLogin: { url: '/pay-api/login/login', method: 'GET', limit : 500},
  11. //获取商品信息
  12. getPayShopOne : {url : '/pay-api/info/getPayShopOne', method : 'GET'},
  13. //创建支付订单
  14. createPayOrder : {url : '/pay-api/info/createPayOrder', method : 'POST', limit : 2000},
  15. //获取个人信息
  16. getInfo : {url : '/pay-api/info/getInfo', method : 'GET'},
  17. //获取订单列表
  18. getPayOrderPage : {url : '/pay-api/info/getPayOrderPage', method : 'GET'},
  19. //修改个人信息
  20. updateInfo : {url : '/pay-api/info/updateInfo', method : 'POST', limit : 500},
  21. //获取隐私政策
  22. getPrivacyPolicy : {url : '/pay-api/login/getPrivacyPolicy', method : 'GET', limit : 500},
  23. //获取用户协议
  24. getUserAgreement : {url : '/pay-api/login/getUserAgreement', method : 'GET', limit : 500},
  25. }
  26. export function api(key, data, callback, loadingTitle){
  27. let req = config[key]
  28. if (!req) {
  29. console.error('无效key' + key);
  30. return
  31. }
  32. if(typeof callback == 'string'){
  33. loadingTitle = callback
  34. }
  35. if(typeof data == 'function'){
  36. callback = data
  37. data = {}
  38. }
  39. // 接口限流
  40. if(req.limit){
  41. let storageKey = 'limit:' + req.url
  42. let storage = uni.getStorageSync(storageKey)
  43. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  44. return
  45. }
  46. uni.setStorageSync(storageKey, new Date().getTime())
  47. }
  48. //必须登录
  49. if (req.auth) {
  50. if (!uni.getStorageSync('token')) {
  51. uni.navigateTo({
  52. url: '/pages/login/login'
  53. })
  54. console.error('需要登录')
  55. return
  56. }
  57. }
  58. http.http(req.url, data, callback, req.method,
  59. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  60. }
  61. export default api