httputil.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // let BASE_Server = "http://127.0.0.1:8329"
  2. // let domain = "http://ccsjkj.top:4002"
  3. let BASE_Server = "https://192.168.1.102:18080"
  4. let BASE_Server_Login = "https://192.168.1.102:19200"
  5. // let BASE_Server = "https://sookajs.top:18080"
  6. // let BASE_Server_Login = "https://sookajs.top:19200"
  7. // let BASE_Server = "http://192.168.54.126:8080"
  8. // let BASE_Server_Login = "http://192.168.54.126:9200"
  9. let app = getApp()
  10. function send_post_login(url, data, successfun) {
  11. wx.request({
  12. url: BASE_Server_Login + url, //仅为示例,并非真实的接口地址
  13. method: "POST",
  14. header: {
  15. 'content-type': 'application/json'
  16. },
  17. data: data,
  18. success(res) {
  19. successfun(res)
  20. // var d = decodeURIComponent(decodeURIComponent(res.data.data))
  21. // console.log("*****", d)
  22. // var json = JSON.parse(d)
  23. // successfun(json)
  24. }
  25. })
  26. }
  27. //-----------------------------登录,获取token-----------------------------------
  28. function init_userInfo() {
  29. if (app.globalToken == null) {
  30. wx.getUserProfile({
  31. desc: 'desc',
  32. success: (res) => {
  33. getSysUserInfo(res.userInfo)
  34. },
  35. fail: res => {
  36. console.log(res)
  37. }
  38. })
  39. }
  40. }
  41. function getSysUserInfo(info) {
  42. console.log(2222)
  43. let that = this
  44. wx.login({
  45. success(res) {
  46. var code = res.code
  47. var data = {
  48. wxCode: code,
  49. wxNickName: info.nickName,
  50. wxAvatarUrl: info.avatarUrl
  51. }
  52. // http.send_post_login("/minapp/AppLoginController/appLogin",data)
  53. send_post_login("/applogin", data, loginSuccess)
  54. },
  55. fail(res) {
  56. console.log("ffff", res)
  57. }
  58. })
  59. }
  60. function loginSuccess(res) {
  61. if (res.data.code != 200) {
  62. wx.showToast({
  63. title: res.data.msg,
  64. icon: "none"
  65. })
  66. } else {
  67. app.globalToken = res.data.data.access_token
  68. //登录成功,获取首页数据
  69. this.initIndexPage()
  70. }
  71. console.log("!!!!!", app.globalToken)
  72. }
  73. //------------------------------------------------------------------
  74. function send_post(url, data, successfun) {
  75. console.log("令牌:", app.globalToken)
  76. //如果令牌为空或过期,需要重新请求
  77. wx.request({
  78. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  79. method: "POST",
  80. header: {
  81. 'content-type': 'application/json',
  82. 'Authorization': 'Bearer ' + app.globalToken
  83. },
  84. data: data,
  85. success(res) {
  86. // var d = decodeURIComponent(decodeURIComponent(res.data.data))
  87. // var json = JSON.parse(d)
  88. successfun(res)
  89. }
  90. })
  91. }
  92. function post(url, data, successfun) {
  93. wx.request({
  94. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  95. method: "POST",
  96. header: {
  97. 'content-type': 'application/x-www-form-urlencoded',
  98. 'Authorization': 'Bearer ' + app.globalToken
  99. },
  100. data: data,
  101. success(res) {
  102. successfun(res.data)
  103. }
  104. })
  105. }
  106. function wxpost(url, data, successfun) {
  107. wx.request({
  108. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  109. method: "POST",
  110. header: {
  111. 'content-type': 'application/json',
  112. 'Authorization': 'Bearer ' + app.globalToken
  113. },
  114. data: data,
  115. success(res) {
  116. successfun(res.data)
  117. }
  118. })
  119. }
  120. function get(url, data, successfun) {
  121. wx.request({
  122. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  123. method: "Get",
  124. header: {
  125. 'content-type': 'application/x-www-form-urlencoded'
  126. },
  127. params: data,
  128. success(res) {
  129. successfun(res.data)
  130. }
  131. })
  132. }
  133. function send_postdecode(url, data, successfun) {
  134. wx.request({
  135. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  136. method: "POST",
  137. header: {
  138. 'content-type': 'application/x-www-form-urlencoded'
  139. },
  140. data: data,
  141. success(res) {
  142. var json = JSON.parse(res.data)
  143. successfun(json)
  144. }
  145. })
  146. }
  147. function send_photo(data, successfun) {
  148. var that = this
  149. for (let i = 0; i < data.length; i++) {
  150. console.log("data长度=" + data.length)
  151. console.log(data)
  152. wx.uploadFile({
  153. url: BASE_Server + "/FileUpLoadController/upload.action", //仅为示例,非真实的接口地址
  154. filePath: data[i] + "",
  155. name: 'file',
  156. success: function (res) {
  157. var json = JSON.parse(res.data)
  158. var sss = JSON.parse(decodeURIComponent(decodeURIComponent(json.data)));
  159. wx.setStorageSync('filename' + (i + 1), sss.data.filename);
  160. successfun(sss)
  161. }
  162. })
  163. }
  164. }
  165. function send(data, successfun) {
  166. var that = this
  167. wx.uploadFile({
  168. url: BASE_Server + "/CarIDScanController/carIduploadGetNumber.action", //仅为示例,非真实的接口地址
  169. filePath: data[0] + "",
  170. name: 'file',
  171. success: function (res) {
  172. var json = JSON.parse(res.data)
  173. var sss = JSON.parse(decodeURIComponent(decodeURIComponent(json.data)));
  174. // wx.setStorageSync("carnumber", sss.data.carNumber)
  175. successfun(sss)
  176. },
  177. fail: function (res) {}
  178. })
  179. }
  180. module.exports = {
  181. BASE_Server: BASE_Server,
  182. send_post: send_post,
  183. send_photo: send_photo,
  184. send: send,
  185. post: post,
  186. wxpost: wxpost,
  187. get: get,
  188. send_postdecode: send_postdecode,
  189. send_post_login,
  190. showLoading,
  191. hideLoading,
  192. }
  193. function showLoading() {
  194. wx.showLoading({
  195. title: '加载中...',
  196. mask: true,
  197. })
  198. }
  199. function hideLoading() {
  200. wx.hideLoading()
  201. }