如何在Shopify中将字符串编码为以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中转换这两个值?
感谢您的宝贵时间!
答案 0 :(得分:0)
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>
这段代码只是解释了 onclick 中的javascript。
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