Solution to the problem of "overseas main domain name cannot be registered - but you still want to use WeChat API for sharing".

Table of Contents

Problem Description

Many friends share the same problem as me—their domains are located overseas and no longer support real-name authentication. Even if they are transferred back to China, they still cannot pass real-name authentication, thus preventing them from being registered. However, WeChat's API usage list requires a registered domain.

At this point, using WeChat's API, especially when sharing with descriptions and images, becomes extremely difficult.

Solution

After considering several methods, I finally chose to use JavaScript to determine the User Agent (UA) and then redirect to a WeChat-specific domain name registered in China. The code is as follows (note the need to replace the domain name).

if (navigator . userAgent . indexOf('MicroMessenger') !== - 1 && window . location . hostname . indexOf('blog.jing.do') !== - 1) { window . location = 'https://wechatdomain.com' + window . location . pathname + window . location . search + window . location . hash; } else if (navigator . userAgent . indexOf('MicroMessenger') == - 1 && window . location . hostname . indexOf('blog.jing.do') == - 1) { window . location = 'https://blog.jing.do' + window . location . pathname + window . location . search + window . location . hash; }

PS:

I previously considered using IP address identification; if the IP was in China, I could directly redirect to the registered domain, solving the problem once and for all. However, I encountered the following issues: 1. This would cause SEO problems if two domains accessed the same resource. 2. WeChat has overseas servers, making complete protection against blocking impossible.

I also considered working on the CDN directly. Cloudflare allows you to write workers and make direct judgments, which is much more efficient than writing JS on the execution page. However, unfortunately, this solution requires purchasing two workers for two domains. If anyone is interested, I'll work on it and share it with you later.

This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:

Original author:Jake Tao,source:"A solution to the problem of 'overseas main domain name cannot be registered – but you still want to share using WeChat API'"

212
0 0 212

Further Reading

Post a reply

Log inYou can only comment after that.
Share this page
Back to top