将 base64 中的字符串编码到 Shopify 中

Encode string in base64 into Shopify

如何在 Shopify 中将字符串编码为 base 64?

我需要将买家电子邮件 ({{customer.email}}) 和订单 ({{order_name}}) 进行 base64 加密

将 trustedbadge*.de 按钮添加到电子邮件中的范围,并且他们正在请求休闲 url 格式:

www . trustedshops/buyerrating/rate_XFD9974BBC558C007CD46
431D056DF230.html&buyerEmail="[base64 buyerEmail]: "&
shopOrderID=" [base64 Order] "&channel=cmF0ZW5vd2J1dHRvbg"

有什么方法可以将这两个值转换成 base64 格式吗?

感谢您的宝贵时间!

Base64 不是 加密 -- 它被称为编码。

据我所知,没有适用于 base64 的 shopify 液体过滤器,因此您必须在 javascript 中执行此操作。

液体: HTML:

    <a href="#" onclick="window.open('https://www.trustedshops/buyerrating/rate_XFD9974BBC558C007CD46431D056DF230.html&buyerEmail=' + encodeURIComponent(btoa({{ order.email | json }})) + '&shopOrderID=' + encodeURIComponent(btoa('{{ order.order_number }}')) + '&channel=cmF0ZW5vd2J1dHRvbg')">
        Open order on trustedshops.com
    </a>

而这段代码只是解释了 javascript 中的 onclick

Javascript:

    // The btoa function is the javascript function to encode a string as base64
    // Since base64 encoded strings can't go directly in a url, we then 
    // need to use encodeURIComponent to make it ok to use in a url.
    var encodedEmail = encodeURIComponent(btoa('hello@example.com')); // aGVsbG9AZXhhbXBsZS5jb20%3D
    var encodedOrderId = encodeURIComponent(btoa('1234567890')); // MTIzNDU2Nzg5MA%3D%3D
    // we can now construct the full url
    var url = 'https://www.trustedshops/buyerrating/rate_XFD9974BBC558C007CD46431D056DF230.html&buyerEmail=' + encodedEmail + '&shopOrderID=' + encodedOrderId + '&channel=cmF0ZW5vd2J1dHRvbg';
    // use window.open to open the url in a new tab
    window.open(url);
    // or use window.location.href = url if you'd like it 
    // to be the same tab