(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define([], factory);
	else {
		var a = factory();
		for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
	}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

	'use strict';

	var _stringify = __webpack_require__(1);

	var _stringify2 = _interopRequireDefault(_stringify);

	var _proxyRequirst = __webpack_require__(4);

	var _proxyRequirst2 = _interopRequireDefault(_proxyRequirst);

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

	var callbacks = {},
	    callbackIndex = 0,
	    defaultEventHandlers = {},
	    eventPrefix = "custom_event_",
	    firstEnter = false,
	    handlers = {},
	    tage = 0,
	    showWarning = false,
	    apphash = __wxConfig__.apphash,
	    appid = __wxConfig__.appid,
	    appname = __wxConfig__.appname,
	    webviewID = 10000,
	    __id = 0; //指定固定值
	function isLimitedApi(event) {
	  var limitedApi = ['openAddress', 'chooseContact'];
	  if (~limitedApi.indexOf(event)) {
	    return true;
	  }
	}
	function isLockSDK(apiName) {
	  return "navigateTo" === apiName || "redirectTo" === apiName;
	}

	function isSyncSDK(apiName) {
	  return "getSystemInfo" === apiName || /Sync$/.test(apiName);
	};

	var callSystemCmd = function callSystemCmd(sdkName, args, callbackID) {
	  var config = {
	    sdkName: sdkName,
	    args: args,
	    callbackID: callbackID
	  };
	  isSyncSDK(sdkName) ? doSyncCommand(config) : doCommand(config);
	};
	var doSyncCommand = function doSyncCommand(config) {
	  //通过prompt交互
	  config.command = "COMMAND_FROM_ASJS";
	  config.appid = appid;
	  config.appname = appname;
	  config.apphash = apphash;
	  config.webviewID = webviewID;
	  var res = systemBridge.doSyncCommand(config);
	  var //command = res.command,//GET_ASSDK_RES
	  msg = res.msg || {},
	      ext = res.ext || {};
	  invokeCallbackHandler(ext.callbackID, msg);
	};

	var doCommand = function doCommand(config) {
	  //postMessage notice e
	  config.to = "backgroundjs";
	  config.comefrom = "webframe";
	  config.command = "COMMAND_FROM_ASJS";
	  config.appid = apphash;
	  config.appname = appname;
	  config.apphash = apphash;
	  config.webviewID = webviewID;
	  config.__id = __id;
	  __id++;
	  systemBridge.doCommand(config);
	};
	var userApi = {
	  login: function login(event, temp, sendMsg) {
	    sendMsg({
	      errMsg: "login:ok",
	      code: "the code is a mock one"
	    });
	  },
	  authorize: function authorize(event, temp, sendMsg) {
	    sendMsg({
	      errMsg: "authorize:fail"
	    });
	  },
	  operateWXData: function operateWXData(event, temp, sendMsg) {
	    var obj = __wxConfig__.userInfo;
	    sendMsg({
	      errMsg: "operateWXData:ok",
	      data: {
	        data: (0, _stringify2.default)({
	          nickName: obj.nickName,
	          avatarUrl: obj.headUrl,
	          gender: "male" === obj.sex ? 1 : 2,
	          province: obj.province,
	          city: obj.city,
	          country: obj.country
	        })
	      }
	    });
	  }
	};
	var invoke = function invoke(eventName, params, callback) {
	  if (~['reportKeyValue', 'reportIDKey'].indexOf(eventName)) {
	    return;
	  }
	  if (userApi.hasOwnProperty(eventName)) {
	    userApi[eventName](eventName, params, callback);
	    return;
	  } else if (!isLimitedApi(eventName)) {
	    var lockSDK = isLockSDK(eventName),
	        time = +new Date();
	    if (!(lockSDK && time - tage < 200)) {
	      //非连续不到200ms切换页面及非受限接口
	      tage = lockSDK ? time : 0;

	      if (_proxyRequirst2.default[eventName]) {
	        _proxyRequirst2.default[eventName].apply(this, arguments);
	      } else {

	        var callbackId = ++callbackIndex;
	        callbacks[callbackId] = callback, callSystemCmd(eventName, params, callbackId); //eventName->sdkName
	      }
	    }
	  } else if (!showWarning) {
	    showWarning = true;
	    var callbackId = ++callbackIndex;
	    var callbackRes = function callbackRes(params) {};
	    callbacks[callbackId] = callbackRes;
	    callSystemCmd('showModal', {
	      title: '请注意，转成h5以后，依赖微信相关的接口调用将无法支持，请自行改造成h5的兼容方式',
	      content: "",
	      confirmText: "确定",
	      cancelText: "取消",
	      showCancel: !0,
	      confirmColor: "#3CC51F",
	      cancelColor: "#000000"
	    }, callbackId); //eventName->sdkName
	  }
	},
	    invokeCallbackHandler = function invokeCallbackHandler(callbackId, params) {
	  var callback = callbacks[callbackId];
	  "function" == typeof callback && callback(params), delete callbacks[callbackId];
	},
	    publish = function publish(eventName, data, webviewIds, flag) {
	  /*
	      var filterEvent = ["appDataChange","pageInitData","__updateAppData"];
	      filterEvent.indexOf(eventName)=== -1 || flag || doCommand({
	        appData: __wxAppData,
	        sdkName: "send_app_data"
	      });
	  */
	  doCommand({
	    eventName: eventPrefix + eventName, //对应view subscribe
	    data: data,
	    webviewIds: webviewIds,
	    sdkName: "publish"
	  });
	},
	    on = function on(eventName, handler) {
	  if ("onAppEnterForeground" === eventName) {
	    if (!firstEnter) {
	      handler && handler({});
	      firstEnter = true;
	    }
	  }

	  defaultEventHandlers[eventName] = handler;
	},
	    subscribe = function subscribe(eventName, handler) {
	  handlers[eventPrefix + eventName] = handler;
	},
	    subscribeHandler = function subscribeHandler(eventName, data, webviewId, reportParams) {
	  //执行注册的回调
	  var handler;
	  handler = eventName.indexOf(eventPrefix) != -1 ? handlers[eventName] : defaultEventHandlers[eventName], "function" == typeof handler && handler(data, webviewId, reportParams);
	};

	window.DeviceOrientation = function (x, y, z) {
	  defaultEventHandlers['onAccelerometerChange'] && defaultEventHandlers['onAccelerometerChange']({
	    x: x,
	    y: y,
	    z: z
	  });
	};

	window.ServiceJSBridge = {
	  doCommand: doCommand,
	  invoke: invoke,
	  invokeCallbackHandler: invokeCallbackHandler,
	  on: on,
	  publish: publish,
	  subscribe: subscribe,
	  subscribeHandler: subscribeHandler
	};

/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

	module.exports = { "default": __webpack_require__(2), __esModule: true };

/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

	var core  = __webpack_require__(3)
	  , $JSON = core.JSON || (core.JSON = {stringify: JSON.stringify});
	module.exports = function stringify(it){ // eslint-disable-line no-unused-vars
	  return $JSON.stringify.apply($JSON, arguments);
	};

/***/ }),
/* 3 */
/***/ (function(module, exports) {

	var core = module.exports = {version: '2.4.0'};
	if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef

/***/ }),
/* 4 */
/***/ (function(module, exports) {

	"use strict";

	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
	var webSocket = null,
	    requestIndex = 0;
	var jsonp = function jsonp(params, callback, networkTimeout) {
	    var jsonpName = "jsonp_" + Date.now() + "_" + Math.random().toString().substr(2),
	        callbackName = "callback",
	        url = params.url,
	        timeOut,
	        script = document.createElement("script");

	    url += (url.indexOf("?") === -1 ? "?" : "&") + callbackName + "=" + jsonpName;
	    script.src = url;
	    if ("number" == typeof networkTimeout) {
	        timeOut = setTimeout(function () {
	            window[jsonpName] = function () {};
	            callback && callback({
	                errMsg: "request:fail"
	            });
	        }, networkTimeout);
	    }

	    window[jsonpName] = function (response) {
	        try {
	            timeOut && clearTimeout(timeOut);
	            callback && callback({
	                errMsg: "request:ok",
	                data: response,
	                statusCode: 200
	            });
	        } finally {
	            delete window[jsonpName];
	            script.parentNode.removeChild(script);
	        }
	    };
	    document.body.appendChild(script);
	};
	var request = function request(event, params, callback) {
	    requestIndex++;
	    var url = params.url,
	        header = params.header || {},
	        timeOut,
	        requestObj = new XMLHttpRequest(),
	        method = params.method || "POST",
	        networkTimeout = 3e4;
	    if (__wxConfig__ && __wxConfig__.weweb && __wxConfig__.weweb.requestProxy) {
	        requestObj.open(method, __wxConfig__.weweb.requestProxy, true);
	        requestObj.onreadystatechange = function () {
	            if (3 == requestObj.readyState, 4 == requestObj.readyState) {
	                requestObj.onreadystatechange = null;
	                var statusCode = requestObj.status;
	                if (0 != statusCode) {
	                    requestIndex--;
	                    timeOut && clearTimeout(timeOut);
	                    callback && callback({
	                        errMsg: "request:ok",
	                        data: requestObj.responseText,
	                        statusCode: statusCode
	                    });
	                }
	            }
	        };
	        requestObj.onerror = function () {
	            callback && callback({
	                errMsg: "request:fail"
	            });
	        };
	        requestObj.setRequestHeader('X-Remote', params.url);
	        var attrCount = 0;
	        for (var attr in header) {
	            "content-type" === attr.toLowerCase() && attrCount++;
	        }
	        attrCount >= 2 && delete header["content-type"];
	        var typeTag = false;
	        for (var headerAttr in header) {
	            if (header.hasOwnProperty(headerAttr)) {
	                var headerStr = headerAttr.toLowerCase();
	                typeTag = "content-type" == headerStr || typeTag;
	                if ("cookie" === headerStr) {
	                    requestObj.setRequestHeader("_Cookie", header[headerAttr]);
	                } else {
	                    requestObj.setRequestHeader(headerAttr, header[headerAttr]);
	                }
	            }
	        }"POST" != method || typeTag || requestObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	        requestObj.setRequestHeader("X-Requested-With", "requestObj");
	        if ("number" == typeof networkTimeout) {
	            timeOut = setTimeout(function () {
	                requestObj.abort("timeout");
	                params.complete && params.complete();
	                params.complete = null;
	                requestIndex--;
	                callback && callback({
	                    errMsg: "request:fail"
	                });
	            }, networkTimeout);
	        }

	        var tempData = "string" == typeof params.data ? params.data : null;
	        try {
	            requestObj.send(tempData);
	        } catch (y) {
	            requestIndex--;
	            callback && callback({
	                errMsg: "request:fail"
	            });
	        }
	    } else {
	        jsonp(params, callback, networkTimeout);
	    }
	};

	var connectSocket = function connectSocket(event, temp, callback) {
	    var url = temp.url,
	        header = temp.header;
	    /*安全域名检测
	        if (!loadFile.checkUrl(url, "webscoket")) {
	            return void(callback && callback({
	                errMsg: "connectSocket:fail"
	            }));
	        }
	    */
	    webSocket = new WebSocket(url);
	    for (var attr in header) {
	        header.hasOwnProperty(attr);
	    };
	    webSocket.onopen = function (data) {
	        ServiceJSBridge.subscribeHandler("onSocketOpen", data);
	    };
	    webSocket.onmessage = function (data) {
	        ServiceJSBridge.subscribeHandler("onSocketMessage", {
	            data: data.data
	        });
	    };
	    webSocket.onclose = function (data) {
	        ServiceJSBridge.subscribeHandler("onSocketClose", data);
	    };
	    webSocket.onerror = function (data) {
	        ServiceJSBridge.subscribeHandler("onSocketError", data);
	    };
	    callback && callback({
	        errMsg: "connectSocket:ok"
	    });
	};
	var closeSocket = function closeSocket(event, temp, callback) {
	    if (webSocket) {
	        webSocket.close();
	        webSocket = null;
	        callback && callback({
	            errMsg: "closeSocket:ok"
	        });
	    } else {
	        callback && callback({
	            errMsg: "closeSocket:fail"
	        });
	    }
	};
	var sendSocketMessage = function sendSocketMessage(event, temp, callback) {
	    var data = temp.data;
	    if (webSocket) {
	        try {
	            webSocket.send(data);
	            callback && callback({
	                errMsg: "sendSocketMessage:ok"
	            });
	        } catch (Event) {
	            callback && callback({
	                errMsg: "sendSocketMessage:fail " + Event.message
	            });
	        }
	    } else {
	        callback && callback({
	            errMsg: "sendSocketMessage:fail"
	        });
	    }
	};
	exports.default = {
	    request: request,
	    connectSocket: connectSocket,
	    sendSocketMessage: sendSocketMessage,
	    closeSocket: closeSocket
	};

/***/ })
/******/ ])
});
;