Before.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /// +----------------------------------------------------------------------
  2. // | HTTP 全局监听口[监听远程执行之前]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016-2017 ,Lioc All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  7. // +----------------------------------------------------------------------
  8. // | Author: Mr Table <admin@hjf.pw>
  9. // +----------------------------------------------------------------------
  10. import store from "../../store";
  11. import md5 from "../vendor/md5.js";
  12. import global from "../../config/global.js";
  13. import { v4 as uuidv4 } from "uuid";
  14. class Before {
  15. app = null;
  16. http = null;
  17. constructor(http) {
  18. this.app = getApp();
  19. }
  20. /**
  21. * [监听]和[拦截]
  22. */
  23. create() {
  24. var salt = global.putoken;
  25. var app = getApp();
  26. var post = {};
  27. post['token'] = store.state.user != null ? store.state.user.token : "";
  28. //设备号
  29. post['deviceId'] = store.state.uuid;
  30. //设备类型
  31. post["deviceType"] = app.$device.platform == 'ios' ? 2 : 1;
  32. //#ifdef APP-PLUS
  33. post["fromApp"] = "app";
  34. //#endif
  35. //#ifndef APP-PLUS
  36. post["fromApp"] = "h5";
  37. //#endif
  38. post["mobileType"] = app.$device.model + "(" + app.$device.system + ")";
  39. //版本号
  40. post["version"] = global.version;
  41. //内部版本号
  42. post['appCode'] = global.app_code;
  43. //校验标码
  44. post['noction'] = uuidv4();
  45. //访问时间戳
  46. post["timestamp"] = Date.parse(new Date());
  47. var signAr = [];
  48. for(var i in post) {
  49. signAr.push(i + "=" + post[i]);
  50. }
  51. var signStr = md5(salt + signAr.join(','));
  52. post['sign'] = signStr;
  53. for(var i in post) {
  54. this.setHeader(i,post[i]);
  55. }
  56. }
  57. }
  58. export default Before;