LjHttpHelper.js 945 B

123456789101112131415161718192021222324252627282930313233343536
  1. var request = require('request');
  2. var cryptoJS = require("crypto-js");
  3. var logHelper = require("./LjLogHelper");
  4. var uuid = require('node-uuid');
  5. /**
  6. * The helper of http
  7. */
  8. class LjHttpHelper
  9. {
  10. static request(optinons, callback)
  11. {
  12. //签名
  13. var signStr = 'path=' + optinons.path + '&uid=' + optinons.uid + '&eid=' + optinons.eid + '&' + optinons.token;
  14. var sign = cryptoJS.MD5(signStr).toString();
  15. var headers = {
  16. 'Content-Type': 'application/json',
  17. 'eid': optinons.eid,
  18. 'uid': optinons.uid,
  19. 'sign': sign,
  20. 'terminal': "web",
  21. 'merchant': "angelbell",
  22. 'requestId': uuid.v1(),
  23. };
  24. var optionsObj = {};
  25. optionsObj.url = optinons.url;
  26. optionsObj.headers = headers;
  27. optionsObj.method = optinons.method;
  28. request(optionsObj, callback);
  29. }
  30. }
  31. module.exports = LjHttpHelper;