字符串转成base64格式

function b64Encode (str) { 
    return btoa(encodeURIComponent(str));
}

解决中文乱码

function getEncode64(str){   
      return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function toSolidBytes(match, p1) {
              return String.fromCharCode('0x' + p1);
      }));
}