faceUtils.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. const crypto = require('crypto');
  3. const request = require('request');
  4. // 这里填写AK和请求
  5. const ak_id = 'LTAI4FwEgBELQHDhfEnQPb6F';
  6. const ak_secret = 'dSiZ0O0XS9m6xKrfYeB9B5G4DnWkYg';
  7. // eslint-disable-next-line no-unused-vars
  8. const md5 = function(buffer) {
  9. let hash;
  10. // eslint-disable-next-line prefer-const
  11. hash = crypto.createHash('md5');
  12. hash.update(buffer);
  13. return hash.digest('base64');
  14. };
  15. // eslint-disable-next-line no-unused-vars
  16. const sha1 = function(stringToSign, secret) {
  17. // eslint-disable-next-line no-unused-vars
  18. let signature;
  19. // eslint-disable-next-line no-return-assign
  20. return signature = crypto.createHmac('sha1', secret).update(stringToSign).digest()
  21. .toString('base64');
  22. };
  23. function callback(error, response, body) {
  24. const { ctx } = this;
  25. return new Promise((resolve, reject) => {
  26. if (error) {
  27. // console.log('error', error);
  28. ctx.logger.error('error', error);
  29. reject(error);
  30. }
  31. // console.log('step4-response body:', response.statusCode, body);
  32. ctx.logger.error('step4-response body:', response.statusCode, body);
  33. resolve(body);
  34. });
  35. }
  36. // function httpRequest(option) {
  37. // return new Promise((resolve, reject) => {
  38. // request(option, function(error, response, body) {
  39. // if (!error && response.statusCode == 200) {
  40. // resolve(body);
  41. // } else {
  42. // reject(error);
  43. // }
  44. // });
  45. // });
  46. // }
  47. module.exports = {
  48. ak_id,
  49. ak_secret,
  50. md5,
  51. sha1,
  52. // httpRequest,
  53. callback,
  54. };