Starting in 2016, if you want to share a link with friends or Moments, if you do not use the official API, the picture and introduction will not be displayed, which makes the sharing experience a lot worse. And if you want to use the official API, you not only need a certified WeChat ID, but also a domain name bound to the background for registration. There are two troubles here: one is that the domain name needs to be registered, and the other is that only three can be bound.
Starting from January 1, 2018, domain name registration requires real-name authentication. All overseas domain name providers do not have this function, which means that you must transfer the domain name back to the domestic operator before you can register it. Overseas domain names basically cannot be registered. Today I came up with a solution to allow WeChat sharing to display introductions and pictures without changing the existing domain name and system.
First you need:
- A certified WeChat ID for sharing API
- A registered domain name, just buy one and register it
- Use the API to run the sharing program on a website with a registered domain name
The basic principle is actually very simple, that is, use curl to obtain the website under the registered domain name, and then share it. When users check, they will see the original website under the registered domain name, but when performing operations, they will return to the original domain name. When sharing on WeChat, the domain name called by the WeChat API is the registered domain name. I posted the code directly and wrote some notes without explaining it. Since the website is GBK, the GBK conversion is added, but it is actually not necessary.
GetSignPackage(); //get url and set gbk(optional) header('Content-type: text/html; charset=GBK'); $url=$_GET['url']; //curl page $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); // get title, desc, keyword $doc = new DOMDocument(); @$doc->loadHTML($data); $nodes = $doc->getElementsByTagName('title'); $title = $nodes->item(0)->nodeValue; $metas = $doc->getElementsByTagName('meta'); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if($meta->getAttribute('name') == 'description') $description = $meta->getAttribute('content'); if($meta->getAttribute('name') == 'keywords') $keywords = $meta->getAttribute('content'); } print_r($data); ?> If you don’t know how to use WeChat JDK, I will write a simple tutorial later.
In addition, the original shared website needs to regenerate each QR code. For example, if your registered domain name is sbicp.com, then the QR code shared by your original website needs to be: http://sbicp.com/share.php?url=oldurl.com/path/
As for how to generate a QR code, there are quite a few online. I used this one:https://www.jianshu.com/p/dfefe14d9f2f
It works for personal testing, please leave a message if you have any questions.
This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)". Please keep the following tags for sharing and interpretation:
Original author:Jake Tao,source:"Let WeChat share unregistered domain name URLs with introduction and pictures"
Comment list (10)
I’m not very good at using WeChat JDK. When you have time, can you write a simple tutorial?
@Story :WeChat has official documentation, you can check it out: https://developers.weixin.qq.com/doc/
Is this invalid now?
@Story :No. Theoretically it will not fail
Master, is there any way to share without WeChat authentication number?
@ Being kicked small tea:No, it is only possible that the domain name has not been registered. . .
@Jake Tao:I have an unregistered domain name and I want to share it with pictures. Can you help me get it? Pay
@anonymous:You need to have at least one registered domain name for redirection. It is recommended to register one first
I have a domain name registered in China, but when sharing a WeChat link, I can only include pictures and titles. The introduction is a URL link. Is there any way to change the introduction to the head content of the article? This way the user experience is much better.
@ Being kicked small tea:Refer to the code above:
window.share_config = {
'share': {
'imgUrl': imgurl,
'desc' : desc,
'title' : title,
'link': window.location.href,
success: function (res) {
}
}
};