var request = require('request');
var cryptoJS = require("crypto-js");
var logHelper = require("./LjLogHelper");
var uuid = require('node-uuid');


/**
 * The helper of http
 */
class LjHttpHelper
{
    static request(optinons, callback)
    {
        //签名
        var signStr = 'path=' + optinons.path + '&uid=' + optinons.uid + '&eid=' + optinons.eid + '&' + optinons.token;
        var sign = cryptoJS.MD5(signStr).toString();

        var headers = {
            'Content-Type': 'application/json',
            'eid': optinons.eid,
            'uid': optinons.uid,
            'sign': sign,
            'terminal': "web",
            'merchant': "angelbell",
            'requestId': uuid.v1(),
        };

        var optionsObj = {};
        optionsObj.url = optinons.url;
        optionsObj.headers = headers;
        optionsObj.method = optinons.method;

        request(optionsObj, callback);
    }
}

module.exports = LjHttpHelper;
