给你的网站添加谷歌AMP、百度MIP、神马MIP链接自动提交功能

我们在做网站的时候,经常会听到别人说SEO优化,网站优化等等。但是我们经常听的云里雾里的,但是经过我们运营一段时间之后,我们慢慢的就会熟悉了,知道什么是SEO。
SEO中文译名为搜索引擎优化,既然是叫搜索引擎优化,那么肯定的是从各个方面对网站的链接和内容进行优化了。
在移动互联网高速发达的今天,仅仅只是依靠PC端的网页展示是不够的,还需要针对移动端进行优化和展示,在这里我给大家普及一下,SEO的中AMP、MIP和熊掌号的几个知识点。

1.AMP(Accelerated Mobile Pages),是谷歌的一项开放源代码计划,可在移动设备上快速加载的轻便型网页,旨在使网页在移动设备上快速加载并且看起来非常美观。

2.MIP(Mobile Instant Page - 移动网页加速器),是一套应用于移动网页的开放性技术标准。通过提供MIP-HTML规范、MIP-JS运行环境以及MIP-Cache页面缓存系统,实现移动网页加速。

3.熊掌号,是百度熊掌号是内容和服务提供者入驻百度生态的实名账号。通过历史内容接口,每天可提交最多500万条有价值的内容,所提交内容会进入百度搜索统一处理流程。

好了,以上知识点内容普及完了,接下来即将开始上干货了。

我今天在网上使用站长工具查看本网站SEO信息的时候,看到几个不常用的权重,其中就是神马权重和头条权重。

 

 

 头条的权重我不清楚,但是我知道他说的应该是今日头条,但是神马权重,我就不是很清楚了,不知道神马权重是啥,然后在百度上一搜索,才知道有一个神马搜索引擎的。

 

 

 

好吧,虽然不知道这是一个什么样的搜索引擎,但是既然是在站长工具上看到的,即使流量再小,也还是不要放过。

进到神马搜索引擎站长工具里面,我们会看到有站长相关的工具,其中有一栏为 MIP数据提交 。

 

 

 

既然有这个接口那我们就不要放过。

然后我们查看一下,如果使用PHP来做MIP数据的提交以及如何进行判断数据是否提交成功了。

使用PHP进行MIP数据提交的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$urls = array(
    'http://www.example.com/1.html',
    'http://www.example.com/2.html',
);
$api = 'http://data.zhanzhang.sm.cn/push?site=www.ddsiot.cn&user_name=xxxxx@qq.com&resource_name=mip_add&token=xx';
$ch = curl_init();
$options array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("\n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;

查看推送反馈:
推送成功:

{
    "returnCode" : 200, //接收成功,但需要进一步校验提交的内容是否正确
    "errorMsg" : ""
}

推送失败:

1
2
3
4
{
    "returnCode" : 201, // 201: token不合法; 202: 当日流量已用完; 400: 请求参数有误; 500: 服务器内部错误
    "errorMsg" : ""
}

 嗯,我们已经知道如何进行MIP数据推送,也知道怎么判断数据是否推送成功,我们现在针对Typecho的网站,添加一个MIP链接自动提交的插件。

1
2
3
4
5
6
7
8
9
10
11
12
13
<div class="row typecho-page-main" role="main">
                <form action="<?php $options->adminUrl('extending.php?panel=AMP/Links.php&send=1'); ?>" method="POST">
                    <div class="operate" style="text-align: center;">
                        <select name="type" style="width:200px;text-align-last: center;">
                            <option value="amp">百度AMP</option>
                            <option value="mip">百度MIP</option>
                            <option value="smmip">神马MIP</option>
                            <option value="batch">熊掌号</option>
                        </select>
                        <button type="submit" class="btn btn-s"><?php _e('开始提交'); ?></button>
                    </div>
                </form>
                <div>

我们制作的这个Typecho插件支持百度MIP、百度AMP、神马MIP、熊掌号链接的自动提交。

插件提交界面预览:

 

 插件提交结果提示代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
if (isset($_GET['send'])) {
    $http = Typecho_Http_Client::get();
    $db = Typecho_Db::get();
 
    //URL分页
    if (isset($_GET['page'])) {
        $page = (int)($_GET['page']);
    } else {
        $page = 1;
    }
    //URL类型
    if ((isset($_GET['type']) and $_GET['type'] == 'amp') OR (isset($_POST['type']) and $_POST['type'] == 'amp')) {
        $sendtype = 'amp';
        $type = 'amp';
    } elseif ((isset($_GET['type']) and $_GET['type'] == 'mip') OR (isset($_POST['type']) and $_POST['type'] == 'mip')) {
        $sendtype = 'mip';
        $type = 'mip';
    } elseif ((isset($_GET['type']) and $_GET['type'] == 'smmip') OR (isset($_POST['type']) and $_POST['type'] == 'smmip')) {
        $sendtype = 'mip';
        $type = 'smmip';
    } elseif ((isset($_GET['type']) and $_GET['type'] == 'batch') OR (isset($_POST['type']) and $_POST['type'] == 'batch')) {
        $sendtype = 'mip';
        $type = 'batch';
        if (isset(Helper::options()->plugin('AMP')->baiduAPPID) and isset(Helper::options()->plugin('AMP')->baiduTOKEN)) {
            $appid = Helper::options()->plugin('AMP')->baiduAPPID;
            $token = Helper::options()->plugin('AMP')->baiduTOKEN;
            $api = "http://data.zz.baidu.com/urls?appid={$appid}&token={$token}&type=batch";
        } else {
            throw new Typecho_Widget_Exception('未设置熊掌号参数!');
        }
    } else {
        $sendtype = 'mip';
        $type = 'mip';
    }
 
    $articleList = Typecho_Widget::widget('AMP_Action')->MakeArticleList($sendtype, $page, 20);
 
 
    //接口类型
    if (!isset($api))
    {
        if(('mip' == $type)||('amp' == $type) ||('batch' ==  $type))
        {
            if (empty(Helper::options()->plugin('AMP')->baiduAPI)) {
                throw new Typecho_Widget_Exception('未设置MIP/AMP推送接口调用地址!');
            } else {
                $api = Helper::options()->plugin('AMP')->baiduAPI;
                $api = preg_replace("/&type=[a-z]+/", "&type={$sendtype}", $api);//替换接口中的类型
 
            }
        }else if('smmip' == $type){
            if (empty(Helper::options()->plugin('AMP')->SMAPI)) {
                throw new Typecho_Widget_Exception('神马未设置MIP推送接口调用地址!');
            } else {
                $api = Helper::options()->plugin('AMP')->SMAPI;
            }
        }
 
    }
 
    $urls = array();
    foreach ($articleList AS $article) {
        if(Helper::options()->plugin('AMP')->PostURL !== Helper::options()->index){
            $article['permalink']=str_replace(Helper::options()->index,Helper::options()->plugin('AMP')->PostURL,$article['permalink']);//替换提交的前缀
        }
        echo '正在提交:' . $article['permalink'] . " <br>";
        $urls[] = $article['permalink'];
    }
 
 
    if (count($urls) > 0) {
        $http->setData(implode("\n", $urls));
        $http->setHeader('Content-Type', 'text/plain');
        try {
            $result = $http->send($api);
        } catch (Exception $e) {
            throw new Typecho_Plugin_Exception(_t('对不起, 您的主机不支持远程访问。<br>请检查 curl 扩展、allow_url_fopen和防火墙设置!<br><hr>出错信息:'.$e->getMessage()));
        }
 
//    string '{"remain":4999960,"success":0,"not_valid":[""]}'
//    string '{"success_mip":20,"remain_mip":9980}' (length=36)
//    $result='{"success_amp":20,"remain_amp":9980}';
//    string(43) "{"success_batch":20,"remain_batch":4999960}"
 
        $obj = json_decode($result, true);
 
 
        if(('mip' == $type)||('amp' == $type) ||('batch' ==  $type))
        {
            $name = "success_{$type}";
            if (isset($obj[$name])) {
 
                echo '<hr>';
                echo "第{$page}页提交成功,";
                print_r($obj);
                $count = $obj["remain_{$type}"];
                echo "还可提交{$count}条URL,准备提交下一页>>>";
                $page += 1;
 
                ?>
                <script language="JavaScript">
                    window.setTimeout("location='<?php $options->adminUrl('extending.php?panel=AMP/Links.php' . "&send=1&type={$type}&page={$page}");
                        ?>'", 2000);
                </script>
                未自动跳转请点击<a
                        href="<?php $options->adminUrl('extending.php?panel=AMP/Links.php' . "&send=1&type={$type}&page={$page}"); ?>">这里</a>
                <?php
            } else {
                echo "<hr>错误提示:";
                print_r($obj);
                echo "<br>提交失败,请检查提交地址。如有必要,请将错误提示<a href='https://github.com/xiaodingding/Typecho-AMP/issues'>反馈给作者</a>";
            }
        }else if('smmip' == $type)
        {
            if(200 == isset($obj["returnCode"] ))
            {
                echo '<hr>';
                echo "第{$page}页提交成功,";
                echo "准备提交下一页>>>";
                $page += 1;
 
                ?>
                <script language="JavaScript">
                    window.setTimeout("location='<?php $options->adminUrl('extending.php?panel=AMP/Links.php' . "&send=1&type={$type}&page={$page}");
                        ?>'", 2000);
                </script>
                未自动跳转请点击<a
                        href="<?php $options->adminUrl('extending.php?panel=AMP/Links.php' . "&send=1&type={$type}&page={$page}"); ?>">这里</a>
                <?php
            }else{
                echo "<hr>错误提示:";
                print_r($obj);
                echo "<br>提交失败,请检查提交地址。如有必要,请将错误提示<a href='https://github.com/xiaodingding/Typecho-AMP/issues'>反馈给作者</a>";
            }
        }
    } else {
        echo "已全部提交完成";
        ?>
        <script language="JavaScript">
            window.setTimeout("location='<?php $options->adminUrl('extending.php?panel=AMP/Links.php');?>'", 2000);
        </script>
        未自动跳转请点击<a href="<?php $options->adminUrl('extending.php?panel=AMP/Links.php'); ?>">这里</a>
        <?php
    }

插件神马MIP提交结果预览:

 

 

神马MIP提交成功,大公告成。

插件源码下载链接:https://www.ddsiot.cn/archives/310.html

 

食用方法:

将插件下载之后,放在Typecho的Plugins目录下面,并将文件夹重命名为AMP。

 

 

 

posted @   badwell  阅读(2669)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示