api.js 9.2 KB

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