这几天看到了一个QQ卡片的简单解决方案,于是决定稍作适配后在博客上部署。所谓QQ卡片,即使用QQ发送链接时显示为卡片,呃呃呃实际上并不明显。

通用版

<!-- QQCard BEGIN -->
<meta itemprop="name" content="标题">
<meta itemprop="image" content="图片">
<meta name="description" itemprop="description" content="描述">
<!-- QQCard END -->

handsome主题专用版

<!-- QQCard BEGIN -->
<meta itemprop="name" content="<?php Content::echoTitle($this,$this->options->title,$this->_currentPage); ?>">
<?php if($this->is('index')): ?>
<meta itemprop="image" content="https://res.ucw.moe/misaka_a.jpg">
<meta name="description" itemprop="description" content="<?php $this->options->description(); ?>">
<?php elseif($this->is('post')): ?>
<meta itemprop="image" content="<?php echo Content::returnHeaderImgSrc($this,'post',0,true); ?>">
<meta name="description" itemprop="description" content="<?php echo Content::excerpt(trim($this->fields->customSummary)!=''?$this->fields->customSummary:$this->excerpt,200); ?>">
<?php else: ?>
<meta itemprop="image" content="https://res.ucw.moe/misaka_a.jpg">
<meta name="description" itemprop="description" content="<?php $this->options->description(); ?>">
<?php endif; ?>
<!-- QQCard END -->

刷新缓存

完成插入后,我们还需要验证配置是否有效并刷新QQ的缓存,这一步通过访问https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshareget_urlinfo?url=欲检测的网址来完成,如果返回的jsonp数据中包括你设置的内容,表示设置有效且缓存已经刷新完毕。视情况可能需要多次刷新。

为简化批量操作,使用python代码,该代码来自(教程原出处,做了部分修改):无限·领域博客

#!/usr/bin/python3
import xml.etree.ElementTree as ET
import requests
xmldata=requests.get('https://ucw.moe/sitemap.xml')
root=ET.fromstring(xmldata.text)
for url in root:
    print(requests.get('https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshareget_urlinfo?url=%s'%url[0].text).text)