Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website

Trước đây link chat Zalo thường có dạng https://zalo.me/{sđt}, mỗi cái không rõ vì lý do gì đó, vài tháng nay Zalo đổi cơ chế, nếu ấn vào link thế sẽ báo lỗi “Tài khoản này tạm thời không thể sử dụng chức năng này”, giải pháp khi mình search thì 1 số người nói do tài khoản chưa nâng cấp, nên tính năng đó bị chặn, có thể dùng QR code của Zalo để thay thế

Đây là hướng dẫn từ levantoan.com, tác giả là một lập trình viên rất giỏi của Việt Nam, trước đây mình cũng dùng qua khá nhiều plugin liên quan tới WordPress WooCommerce của anh ấy 😀 dùng thích lắm

Do mình đang dùng theo hướng dẫn về QR code Zalo, nên viết thành 1 bài cho vào Toolbox, chủ yếu giới thiệu, quảng cáo thêm cho họ 😀 chứ nội dung bài thì đơn giản quá để viết thành 1 bài

1. Lấy mã QR code Zalo từ điện thoại

Vào trang cá nhân trên Zalo, sẽ thấy dấu 3 chấm ở góc trên bên phải, ấn vào sẽ thấy tùy chọn Mã QR của tôi

2023 10 12 19 36 28

Dùng camera điện thoại quét QR code này, sẽ ra 1 link dạng

https://zaloapp.com/qr/p/qu8ifitjj72m

Chỉ quan tâm đoạn cuối cùng qu8ifitjj72m, đây là QR code của minh

2. Sử dụng Code Snippets tạo 1 file php với nội dung:

  • Thay số điện thoại và QR code của bạn vào (nội dung dòng 10)
/*
* Code sửa lỗi link zalo.me/{sđt}
* Author: levantoan.com
*/
add_action('wp_footer', 'devvn_fix_zalome', 999999);
function devvn_fix_zalome(){
    ?>
    <script>
        var zalo_acc = {
            "0967876400" : "qu8ifitjj72m",
   
        };
        function devvnCheckLinkAvailability(link, successCallback, errorCallback) {
            var hiddenIframe = document.querySelector("#hiddenIframe");
            if (!hiddenIframe) {
                hiddenIframe = document.createElement("iframe");
                hiddenIframe.id = "hiddenIframe";
                hiddenIframe.style.display = "none";
                document.body.appendChild(hiddenIframe);
            }
            var timeout = setTimeout(function () {
                errorCallback("Link is not supported.");
                window.removeEventListener("blur", handleBlur);
            }, 2500);
            var result = {};
            function handleMouseMove(event) {
                if (!result.x) {
                    result = {
                        x: event.clientX,
                        y: event.clientY,
                    };
                }
            }
            function handleBlur() {
                clearTimeout(timeout);
                window.addEventListener("mousemove", handleMouseMove);
            }
            window.addEventListener("blur", handleBlur);
            window.addEventListener(
                "focus",
                function onFocus() {
                    setTimeout(function () {
                        if (document.hasFocus()) {
                            successCallback(function (pos) {
                                if (!pos.x) {
                                    return true;
                                }
                                var screenWidth =
                                    window.innerWidth ||
                                    document.documentElement.clientWidth ||
                                    document.body.clientWidth;
                                var alertWidth = 300;
                                var alertHeight = 100;
                                var isXInRange =
                                    pos.x - 100 < 0.5 * (screenWidth + alertWidth) &&
                                    pos.x + 100 > 0.5 * (screenWidth + alertWidth);
                                var isYInRange =
                                    pos.y - 40 < alertHeight && pos.y + 40 > alertHeight;
                                return isXInRange && isYInRange
                                    ? "Link can be opened."
                                    : "Link is not supported.";
                            }(result));
                        } else {
                            successCallback("Link can be opened.");
                        }
                        window.removeEventListener("focus", onFocus);
                        window.removeEventListener("blur", handleBlur);
                        window.removeEventListener("mousemove", handleMouseMove);
                    }, 500);
                },
                { once: true }
            );
            hiddenIframe.contentWindow.location.href = link;
        }
        Object.keys(zalo_acc).map(function(sdt, index) {
            let qrcode = zalo_acc[sdt];
            const zaloLinks = document.querySelectorAll('a[href*="zalo.me/'+sdt+'"]');
            zaloLinks.forEach((zalo) => {
                zalo.addEventListener("click", (event) => {
                    event.preventDefault();
                    const userAgent = navigator.userAgent.toLowerCase();
                    const isIOS = /iphone|ipad|ipod/.test(userAgent);
                    const isAndroid = /android/.test(userAgent);
                    let redirectURL = null;
                    if (isIOS) {
                        redirectURL = 'zalo://qr/p/'+qrcode;
                        window.location.href = redirectURL;
                    } else if (isAndroid) {
                        redirectURL = 'zalo://zaloapp.com/qr/p/'+qrcode;
                        window.location.href = redirectURL;
                    } else {
                        redirectURL = 'zalo://conversation?phone='+sdt;
                        zalo.classList.add("zalo_loading");
                        devvnCheckLinkAvailability(
                            redirectURL,
                            function (result) {
                                zalo.classList.remove("zalo_loading");
                            },
                            function (error) {
                                zalo.classList.remove("zalo_loading");
                                redirectURL = 'https://chat.zalo.me/?phone='+sdt;
                                window.location.href = redirectURL;
                            }
                        );
                    }
                });
            });
        });
        //Thêm css vào site để lúc ấn trên pc trong lúc chờ check chuyển hướng sẽ không ấn vào thẻ a đó được nữa
        var styleElement = document.createElement("style");
        var cssCode = ".zalo_loading { pointer-events: none; }";
        styleElement.innerHTML = cssCode;
        document.head.appendChild(styleElement);
    </script>
    <?php
}

Lúc này các link cũ, dạng https://zalo.me/{sđt} sẽ hoạt động bình thường

2023 10 12 19 42 26

Trên trang bibica.net thì bạn có thể nhìn wiget bên phải connect with us 😀 ấn vào sẽ thấy tác dụng, nó tự chạy app Zalo chứ không báo lỗi như trước đây 😀

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback.
Notes: However, those deemed to be spam or solely promotional will be deleted.

You can create a Gravatar account, add avatar, then use that email to comment here, your account will have a more beautiful Avatar, easier to recognize with other members.

Please use real emails, you can receive notifications when comments are replied