123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 'use strict';
- const crypto = require('crypto');
- const request = require('request');
- // 这里填写AK和请求
- const ak_id = 'LTAI4FwEgBELQHDhfEnQPb6F';
- const ak_secret = 'dSiZ0O0XS9m6xKrfYeB9B5G4DnWkYg';
- // eslint-disable-next-line no-unused-vars
- const md5 = function(buffer) {
- let hash;
- // eslint-disable-next-line prefer-const
- hash = crypto.createHash('md5');
- hash.update(buffer);
- return hash.digest('base64');
- };
- // eslint-disable-next-line no-unused-vars
- const sha1 = function(stringToSign, secret) {
- // eslint-disable-next-line no-unused-vars
- let signature;
- // eslint-disable-next-line no-return-assign
- return signature = crypto.createHmac('sha1', secret).update(stringToSign).digest()
- .toString('base64');
- };
- function callback(error, response, body) {
- const { ctx } = this;
- return new Promise((resolve, reject) => {
- if (error) {
- // console.log('error', error);
- ctx.logger.error('error', error);
- reject(error);
- }
- // console.log('step4-response body:', response.statusCode, body);
- ctx.logger.error('step4-response body:', response.statusCode, body);
- resolve(body);
- });
- }
- // function httpRequest(option) {
- // return new Promise((resolve, reject) => {
- // request(option, function(error, response, body) {
- // if (!error && response.statusCode == 200) {
- // resolve(body);
- // } else {
- // reject(error);
- // }
- // });
- // });
- // }
- module.exports = {
- ak_id,
- ak_secret,
- md5,
- sha1,
- // httpRequest,
- callback,
- };
|