(function(exports) {
    var publish_version = false;
    var server;
	var agentName = "useragent"
	var userInfo = "userInfoForPay"
    if(publish_version) { // 生产环境配置
        server = ""
        
    } else { // 测试环境配置
        server = "http://fashion.ybxin.net/hlpay/index.php?s="
    }

    function httpGet(url, options) {
        //发送ajax请求
        return new Promise(function(resolve, reject) {
            $.ajax(server + url,
                $.extend({}, {
                    type: 'GET',
                    dataType: 'JSON',
                    beforeSend: function(request) {
                    	var userAgent = window.localStorage.getItem(agentName);
                    	request.setRequestHeader(agentName, userAgent);
                    },
                    error: function(res) {
                        reject(res)
                    },
                    success: function(res) {
                        resolve(res)
                    }
                }, options));
        })
    }

    function httpPost(url, options) {
        //发送ajax请求
        return new Promise(function(resolve, reject) {
            $.ajax(server + url,
                $.extend({}, {
                    type: 'POST',
                    dataType: 'JSON',
                    beforeSend: function(request) {
                    	var userAgent = window.localStorage.getItem(agentName);
                    	request.setRequestHeader(agentName, userAgent);
                    },
                    error: function(res) {
                        reject(res)
                    },
                    success: function(res) {
                        resolve(res)
                    }
                }, options));
        })
    }

    httpRequest = {
    	server: server,
    	userInfo: userInfo,
    	agentName: agentName,
        get: function(url, options) {
        	return httpGet(url, options)
        },
        post: function(url, options) {
        	return httpPost(url, options)
        }
    }

    exports.httpRequest = httpRequest;
})(window)