const OPENID_KEY = 'WECHAT_OPENID'

export function setOpenid(openid){
  window.sessionStorage.setItem(OPENID_KEY,openid || '')
}

export function getOpenid(){
  return window.sessionStorage.getItem(OPENID_KEY) || ''
}

export function removeOpenid(){
  return window.sessionStorage.removeItem(OPENID_KEY)
}

export function getParameterByName(name) {
  var url = window.location.href;
  name = name.replace(/[\[\]]/g, '\\$&');
  var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
  var results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
