api.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. const GET = 'GET';
  2. const POST = 'POST';
  3. const PUT = 'PUT';
  4. const FORM = 'FORM';
  5. const DELETE = 'DELETE';
  6. // wxb299e10e65157301
  7. // wx2938132b773c7b5a
  8. // const baseURL = 'https://wx.scxjc.club';
  9. // const baseURL = 'https://test.hunanwanzhu.com';
  10. const baseURL = 'https://api.hunanwanzhu.com';
  11. function request(method, url, data) {
  12. var token='';
  13. return new Promise(function (resolve, reject) {
  14. wx.getStorage({
  15. key: 'userInfo',
  16. complete: res => {
  17. if (res.data) {
  18. token = res.data.token
  19. }
  20. let header = {
  21. 'content-type': 'application/json',
  22. 'Authorization': token
  23. };
  24. wx.request({
  25. url: baseURL + url,
  26. method: method,
  27. data: data,
  28. header: header,
  29. success(res) {
  30. //请求成功
  31. //判断状态码---errCode状态根据后端定义来判断
  32. if (res.data.code == 0||res.data.pass==1) {
  33. resolve(res);
  34. } else if (res.data.code == 403) {
  35. //未登录
  36. reject(403)
  37. }else{
  38. wx.hideNavigationBarLoading()
  39. wx.hideLoading()
  40. wx.showToast({
  41. title: res.data.message,
  42. icon:'none',
  43. duration:3000
  44. })
  45. }
  46. },
  47. fail(err) {
  48. //请求失败
  49. wx.showToast({
  50. icon:'none',
  51. title: '服务器开小差了',
  52. })
  53. reject(err)
  54. }
  55. })
  56. }
  57. })
  58. })
  59. }
  60. function uploadFile(url, filePath, name, formData, isSubDomain) {
  61. var token = '';
  62. return new Promise((resolve, reject) => {
  63. wx.getStorage({
  64. key: 'userInfo',
  65. complete: res => {
  66. if (res.data) {
  67. token = res.data.token
  68. }
  69. let header = {
  70. 'content-type': 'application/json',
  71. 'Authorization': token
  72. };
  73. wx.uploadFile({
  74. url: baseURL + url,
  75. filePath: filePath,
  76. name: name,
  77. // formData: formData,
  78. header: header,
  79. success: res => {
  80. resolve(JSON.parse(res.data))
  81. },
  82. fail(err) {
  83. //请求失败
  84. reject(err)
  85. }
  86. })
  87. }
  88. })
  89. })
  90. }
  91. function checkUser(){
  92. console.log('check is user')
  93. let user = wx.getStorageSync('user')
  94. if(!user){
  95. wx.navigateTo({
  96. url: '../login/user?type=0',
  97. })
  98. }
  99. return user
  100. }
  101. function checkUserRole(){
  102. let user = wx.getStorageSync('user')
  103. if (!user || user.role == 0) {
  104. wx.navigateTo({
  105. url: '../login/user?type=3',
  106. })
  107. return false
  108. }
  109. return true
  110. }
  111. function pushToday(e){
  112. if(checkUserRole()){
  113. wx.navigateTo({
  114. url: '../today/today?id=' + e.match_id + '&record_id=' + e.record_id + '&user_id=' + e.user_id,
  115. })
  116. }
  117. }
  118. function initUser(){
  119. API.getAuthinfo().then(res=>{
  120. console.log(res.data.data,'user11')
  121. if(res.data.code==0){
  122. wx.setStorage({
  123. key: 'user',
  124. data: res.data.data,
  125. })
  126. }
  127. })
  128. }
  129. const API = {
  130. getOpenid: (data) => request(GET, `/api/wx/openid`, data),
  131. login: (data) => request(POST, `/api/wx/v3/login`, data),
  132. bindphone: (data) => request(POST, `/api/wx/v3/phone/bind`, data),
  133. sendcode: (data) => request(POST, `/api/wx/v3/phone/code`, data),
  134. getAuthinfo: (data) => request(GET, `/api/wx/authinfo`, data),
  135. getEnumList: (data) => request(GET, `/api/wx/v2/enum/list`, data),
  136. getIndex: (data) => request(GET, `/api/wx/index`, data),
  137. getBaikeCategory: (data) => request(GET, `/api/wx/v3/baike/category/list`, data),
  138. getBaike: (data) => request(GET, `/api/wx/v3/baike/list`, data),
  139. getBaikeDetail: (data) => request(GET, `/api/wx/v3/baike/detail`, data),
  140. getBaikeRandom: (data) => request(GET, `/api/wx/v3/baike/random`, data),
  141. getRank: (data) => request(GET, `/api/wx/group/rank/list`, data),
  142. getRankList: (data) => request(GET, `/api/wx/group/rank`, data),
  143. getWinList: (data) => request(GET, `/api/wx/v3/match/winlost/top5`, data),
  144. getPlayerMatch: (data) => request(GET, `/api/wx/player/match`, data),//参赛资料
  145. updateFollow: (data) => request(POST, `/api/wx/v2/user/follow`, data),
  146. getRinrate: (data) => request(GET, `/api/wx/v2/winrate/rank`, data),
  147. getDefend: (data) => request(GET, `/api/wx/v2/defend/rank`, data),
  148. getHotbuyList: (data) => request(GET, `/api/wx/v2/hot/stock/buy/list`, data),
  149. getHotsellList: (data) => request(GET, `/api/wx/v2/hot/stock/sell/list`, data),
  150. getSellStock: (data) => request(GET, `/api/wx/v2/hot/stock/sell/players`, data),
  151. getChampionlList: (data) => request(GET, `/api/wx/v2/champion/article/list`, data),
  152. upload: (filePath, name) => uploadFile(`/api/wx/uploadfile`, filePath, name),
  153. uploadAvatar: (filePath, name) => uploadFile(`/api/wx/uploadavatar`, filePath, name),
  154. getOssSign: (data) => request(GET, `/api/wx/oss2/uploadfile/sign`, data),
  155. updateStyle: (data) => request(PUT, `/api/wx/v2/mine/style`, data),
  156. getMyStyle: (data) => request(GET, `/api/wx/v2/mine/style`, data),
  157. getMyFollow: (data) => request(GET, `/api/wx/v2/user/follow/list`, data),
  158. getMyFollowV3: (data) => request(GET, `/api/wx/v3/user/follow/list`, data),
  159. getMyMatch: (data) => request(GET, `/api/wx/player/match/list`, data),
  160. getComment: (data) => request(GET, `/api/wx/v2/wanzhu/comment/list`, data),
  161. getRecordList: (data) => request(GET, `/api/wx/player/match/record/list`, data),
  162. follow: (data) => request(POST, `/api/wx/v2/user/follow`, data),
  163. getPlayerList: (data) => request(GET, `/api/wx/v2/player/list`, data),
  164. updateRecord: (data) => request(POST, `/api/wx/player/record`, data),
  165. getRecord: (data) => request(GET, `/api/wx/player/record`, data),
  166. getCurrecord: (data) => request(GET, `/api/wx/player/currecord`, data),
  167. getArticle: (data) => request(GET, `/api/wx/v3/article/detail`, data),
  168. getStock: (data) => request(GET, `/api/wx/v3/stock`, data),
  169. getStockPlayer: (data) => request(GET, `/api/wx/v3/stock/players/list`, data),
  170. searchStock: (data) => request(GET, `/api/wx/stock/search`, data),
  171. getNotoice: (data) => request(GET, `/api/wx/v2/notices/list`, data),
  172. getDate: (data) => request(GET, `/api/wx/v2/default/date`, data),
  173. getHotFollow: (data) => request(GET, `/api/wx/v2/hot/follow/list`, data),
  174. getCalendar: (data) => request(GET, `/api/wx/v2/player/match/calendar`, data),
  175. getMatchList: (data) => request(GET, `/api/wx/v2/match/list`, data),
  176. getMineLatest: (data) => request(GET, `/api/wx/v2/mine/latest`, data),
  177. getCommentCount: (data) => request(GET, `/api/wx/v3/user/comments/count`, data),
  178. getZanCount: (data) => request(GET, `/api/wx/v3/user/zancount`, data),
  179. postcomment: (data) => request(POST, `/api/wx/v3/user/comments`, data),
  180. delcomment: (data) => request(DELETE, `/api/wx/v3/user/comments`, data),
  181. getComment: (data) => request(GET, `/api/wx/v3/user/comments/list`, data),
  182. zan: (data) => request(POST, `/api/wx/v3/user/zan`, data),
  183. getconsult: (data) => request(GET, `/api/wx/v3/user/consult/list`, data),
  184. wxpay: (data) => request(POST, `/api/wx/v3/signup/wxpay`, data),
  185. consult: (data) => request(POST, `/api/wx/v3/user/consult`, data),
  186. getsignup: (data) => request(GET, `/api/wx/v3/signup/info`, data),
  187. getsignupweb: (data) => request(GET, `/api/wx/v3/signup/web`, data),
  188. update: (data) => request(PUT, `/api/wx/v3/user/fund/modify`, data),
  189. getChoice: (data) => request(GET, `/api/wx/v3/user/choice/list`, data),
  190. addchoice: (data) => request(POST, `/api/wx/v3/user/choice`, data),
  191. deletechoice: (data) => request(DELETE, `/api/wx/v3/user/choice`, data),
  192. initfund: (data) => request(PUT, `/api/wx/player/fund`, data),
  193. getFans: (data) => request(GET, `/api/wx/v3/user/follower/list`, data),
  194. getExperience: (data) => request(GET, `/api/wx/v3/experience/list`, data),
  195. getUserMatch: (data) => request(GET, `/api/wx/v3/user/match/list`, data),
  196. getUserInfo: (data) => request(GET, `/api/wx/user/info`, data),
  197. isUserLogin: (data) => request(GET, `/api/wx/v3/authinfo`, data),
  198. getTLBlist: (data) => request(GET, `/api/wx/v3/profit/rank/list`, data),
  199. getBlacklist: (data) => request(GET, `/api/wx/v3/user/black/list`, data),
  200. cancelBlack: (data) => request(DELETE, `/api/wx/v3/user/black`, data),
  201. blackUser: (data) => request(POST, `/api/wx/v3/user/black`, data),
  202. getNbcomments: (data) => request(GET, `/api/wx/v3/stock/nbcomments/list`, data),
  203. getStockNbcomments: (data) => request(GET, `/api/wx/v3/stock/comments/list`, data),
  204. getWinLose: (data) => request(GET, `/api/wx/v3/match/group/winlose/statistic`, data),
  205. imageOcr: (data) => request(POST, `/api/wx/v3/ai/ocr`, data),
  206. getAllDay: (data) => request(GET, `/api/wx/v3/match/group/winlose/allday`, data),
  207. getAvg: (data) => request(GET, `/api/wx/v3/match/group/winlose/avg/allday`, data),
  208. getWinlossRank: (data) => request(GET, `/api/wx/v3/user/match/stock/winlossrank/list`, data),
  209. markScore: (data) => request(POST, `/api/wx/v3/user/markscore`, data),
  210. checkMark: (data) => request(GET, `/api/wx/v3/user/markscore/check`, data),
  211. getMark: (data) => request(GET, `/api/wx/v3/user/markscore/weekavg`, data),
  212. contentCheck: (data) => request(POST, `/api/wx/v3/msg/content/check`, data),
  213. initUser:() => initUser(),
  214. checkUser:() => checkUser(),
  215. checkUserRole:() => checkUserRole(),
  216. };
  217. const PUSH = {
  218. pushToday:(data) => pushToday(data),
  219. };
  220. module.exports = {
  221. API: API,
  222. PUSH: PUSH,
  223. }