blog / 2021 /02 /02 /serverchan.html
User Mayx
update
3eb1c3b
Raw
History Blame Contribute Delete
22.1 kB
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Begin Jekyll SEO tag v2.8.0 -->
<title>自己动手做一个Server酱·TurboMini版 | Mayx的博客</title>
<meta name="generator" content="Jekyll v3.9.5" />
<meta property="og:title" content="自己动手做一个Server酱·TurboMini版" />
<meta name="author" content="mayx" />
<meta property="og:locale" content="zh_CN" />
<meta name="description" content="一句话就能解决的问题也敢收费?" />
<meta property="og:description" content="一句话就能解决的问题也敢收费?" />
<meta property="og:site_name" content="Mayx的博客" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2021-02-02T00:00:00+08:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="自己动手做一个Server酱·TurboMini版" />
<meta name="google-site-verification" content="huTYdEesm8NaFymixMNqflyCp6Jfvd615j5Wq1i2PHc" />
<meta name="msvalidate.01" content="0ADFCE64B3557DC4DC5F2DC224C5FDDD" />
<meta name="yandex-verification" content="fc0e535abed800be" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"mayx"},"dateModified":"2021-02-02T00:00:00+08:00","datePublished":"2021-02-02T00:00:00+08:00","description":"一句话就能解决的问题也敢收费?","headline":"自己动手做一个Server酱·TurboMini版","mainEntityOfPage":{"@type":"WebPage","@id":"/2021/02/02/serverchan.html"},"publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://avatars0.githubusercontent.com/u/17966333"},"name":"mayx"},"url":"/2021/02/02/serverchan.html"}</script>
<!-- End Jekyll SEO tag -->
<link rel="canonical" href="https://mabbs.github.io/2021/02/02/serverchan.html" />
<link type="application/atom+xml" rel="alternate" href="/atom.xml" title="Mayx的博客" />
<link rel="alternate" type="application/rss+xml" title="Mayx的博客(RSS)" href="/rss.xml" />
<link rel="alternate" type="application/json" title="Mayx的博客(JSON Feed)" href="/feed.json" />
<link rel="stylesheet" href="/assets/css/style.css?v=1786013449" />
<!--[if !IE]> -->
<link rel="stylesheet" href="/Live2dHistoire/live2d/css/live2d.css" />
<link rel="stylesheet" href="/assets/css/gitalk.css" />
<script src="/assets/js/gitalk.min.js"></script>
<!-- <![endif]-->
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Mayx的博客" />
<link rel="webmention" href="https://webmention.io/mabbs.github.io/webmention" />
<link rel="pingback" href="https://webmention.io/mabbs.github.io/xmlrpc" />
<link rel="preconnect" href="https://summary.mayx.eu.org" crossorigin="anonymous" />
<link rel="prefetch" href="https://www.blogsclub.org/badge/mabbs.github.io" as="image" />
<link rel="blogroll" type="text/xml" href="/blogroll.opml" />
<link rel="me" href="https://github.com/Mabbs" />
<link type="text/plain" rel="author" href="/humans.txt" />
<script src="/assets/js/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.3/jquery.xdomainrequest.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
var lastUpdated = new Date("Thu, 06 Aug 2026 18:50:49 +0800");
var BlogAPI = "https://summary.mayx.eu.org";
var GitalkConfig = {
clientID: '36557aec4c3cb04f7ac6',
clientSecret: 'ac32993299751cb5a9ba81cf2b171cca65879cdb',
repo: 'mabbs.github.io',
owner: 'Mabbs',
admin: ['Mabbs'],
distractionFreeMode: false,
proxy: 'https://cors-anywhere.mayx.eu.org/?https://github.com/login/oauth/access_token'
};
</script>
<script src="/assets/js/main.js"></script>
<!--[if !IE]> -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-137710294-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137710294-1');
</script>
<script src="/assets/js/instant.page.js" type="module"></script>
<!-- <![endif]-->
</head>
<body>
<!--[if !IE]> --><noscript><marquee style="top: -15px; position: relative;"><small>发现当前浏览器没有启用JavaScript,这不影响你的浏览,但可能会有一些功能无法使用……</small></marquee></noscript><!-- <![endif]-->
<!--[if IE]><marquee style="top: -15px; position: relative;"><small>发现当前浏览器为Internet Explorer,这不影响你的浏览,但可能会有一些功能无法使用……</small></marquee><![endif]-->
<div class="wrapper">
<header class="h-card">
<h1><a class="u-url u-uid p-name" rel="me" href="/">Mayx的博客</a></h1>
<img src="https://avatars0.githubusercontent.com/u/17966333" fetchpriority="high" class="u-photo" alt="Logo" style="width: 90%; max-width: 300px; max-height: 300px; border-radius: 25%;" />
<p class="p-note">Mayx's Home Page</p>
<form id="search-input-all" action="/search.html">
<input type="text" name="keyword" placeholder="Search blog posts.." />&#160;<input type="submit" value="搜索" />
</form>
<br />
<p class="view"><a class="u-url" href="/Mabbs/">About me</a></p>
<ul class="downloads">
<li style="width: 270px; border-right: none;"><a href="/MayxBlog.tgz">Download <strong>TGZ File</strong></a></li>
</ul>
</header>
<section id="pjax-container" class="h-entry">
<small><time class="date dt-published" datetime="2021-02-02T00:00:00+08:00">2 February 2021</time> - 字数统计:2047 - 阅读大约需要6分钟 - Hits: <span id="/2021/02/02/serverchan.html" class="visitors">Loading...</span></small>
<h1 class="p-name">自己动手做一个Server酱·TurboMini版</h1>
<p class="view">by <a class="p-author h-card" href="//github.com/Mabbs">mayx</a></p>
<div id="outdate" style="display:none;">
<hr /><p>
这是一篇创建于 <span id="outime"></span> 天前的文章,其中的信息可能已经有所发展或是发生改变。
</p>
</div>
<script>
daysold = Math.floor((new Date().getTime() - new Date("Tue, 02 Feb 2021 00:00:00 +0800").getTime()) / (24 * 60 * 60 * 1000));
if (daysold > 90) {
document.getElementById("outdate").style.display = "block";
document.getElementById("outime").innerHTML = daysold;
}
</script>
<hr />
<b>AI摘要</b>
<p id="ai-output">这篇文章讨论了作者对于Server酱·Turbo版收费的不满,原本习惯使用Server酱的作者因其服务不稳定而转向自己开发,发现通过微信API发送模板消息非常简单,一行PHP代码就能实现,并强调自己的实现比Server酱的限制更好,每天发送量理论上可达2000次到100000次。作者在文章中提供了设置参数的步骤,并讽刺了Server酱的收费行为,认为开发者不应该为此类基础功能付费。</p>
<hr />
<ul><li><a href="#起因">起因</a></li><li><a href="#试着做一下">试着做一下</a></li><li><a href="#如何得到参数">如何得到参数?</a></li><li><a href="#结语">结语</a></li></ul>
<hr />
<main class="post-content e-content" role="main"><p>一句话就能解决的问题也敢收费?<!--more--></p>
<h1 id="起因">
<a href="#起因"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 起因
</h1>
<p>我以前经常使用Server酱给我推送日报,或者告诉我树莓派有没有正常启动之类的事情。之所以使用它是因为那个API还是挺方便的,而且我平时微信也用的多,能直接通过微信推送信息也挺不错的。 </p><p>
后来Server酱整了个什么Turbo版,不过我用普通版用的挺好就没怎么管。结果今天发了个什么通知,说他们的服务有可能要挂?我这个人最讨厌的就是服务不稳定,连个服务都整不稳定的人干脆别做服务了,做出来那不是害人嘛,像之前那个什么LeanCloud就不行,因此我还<a href="/2019/06/22/counter.html">自己写了一个博客计数器</a></p><p>
然后我就看了看他们的Server酱·Turbo版,好家伙,还是收费的,8CNY/mo有点过分啊,也不过是调用微信接口还要花钱?看了之后我说不行,这个太贵了,我倒要看看这东西到底要花多少资源。 </p><p>
之前我就看他们吹,说自己月请求数5kw,我说这有啥,我花火学园每个月请求数要上亿,也花不了几个钱,5kw就敢出来吹?还敢开课?所以今天我就来看看这所谓的“配置略显复杂”到底有多复杂。</p>
<h1 id="试着做一下">
<a href="#试着做一下"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 试着做一下
</h1>
<p>我看了下微信关于测试号的接口文档,看起来也没多复杂嘛,我估摸了一下,最多一句话就能搞定!然后就试着用PHP写了一下。 </p><p>
最终的代码如下:</p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">&lt;?php</span>
<span class="nv">$appid</span><span class="o">=</span><span class="s1">'appID'</span><span class="p">;</span>
<span class="nv">$secret</span><span class="o">=</span><span class="s1">'appsecret'</span><span class="p">;</span>
<span class="nv">$userid</span><span class="o">=</span><span class="s1">'微信号(OpenID)'</span><span class="p">;</span>
<span class="nv">$template_id</span><span class="o">=</span><span class="s1">'模板ID'</span><span class="p">;</span>
<span class="nv">$title</span><span class="o">=</span><span class="s1">'标题'</span><span class="p">;</span>
<span class="nv">$content</span><span class="o">=</span><span class="s1">'内容'</span><span class="p">;</span>
<span class="nb">file_get_contents</span><span class="p">(</span><span class="s1">'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='</span><span class="mf">.</span><span class="nb">json_decode</span><span class="p">(</span><span class="nb">file_get_contents</span><span class="p">(</span><span class="s1">'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid='</span><span class="mf">.</span><span class="nv">$appid</span><span class="mf">.</span><span class="s1">'&amp;secret='</span><span class="mf">.</span><span class="nv">$secret</span><span class="p">),</span><span class="kc">true</span><span class="p">)[</span><span class="s1">'access_token'</span><span class="p">],</span> <span class="kc">false</span><span class="p">,</span> <span class="nb">stream_context_create</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'http'</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">'method'</span><span class="o">=&gt;</span><span class="s1">'POST'</span><span class="p">,</span><span class="s1">'header'</span><span class="o">=&gt;</span><span class="s2">"Content-Type: application/json;charset=utf-8"</span><span class="p">,</span><span class="s1">'content'</span><span class="o">=&gt;</span><span class="s1">'{"touser":"'</span><span class="mf">.</span><span class="nv">$userid</span><span class="mf">.</span><span class="s1">'","template_id":"'</span><span class="mf">.</span><span class="nv">$template_id</span><span class="mf">.</span><span class="s1">'","data":{"title": {"value":"'</span><span class="mf">.</span><span class="nv">$title</span><span class="mf">.</span><span class="s1">'"},"content": {"value":"'</span><span class="mf">.</span><span class="nv">$content</span><span class="mf">.</span><span class="s1">'"}}}'</span><span class="p">))));</span>
</code></pre></div></div>
<p>写好之后测试了一下,效果还不错,和Server酱测试号的效果几乎一模一样,除了没有能点开的网页,当然要想搞也行,很简单,就插一个URL就可以了,如果你希望整些更多的特效,也可以去<a href="https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html">模板接口文档</a>里面看。 </p><p>
关于限制方面的话也要比Server酱要好,理论上我的代码每天能发送2000次,主要是因为获取access_token的接口每天只能使用2000次,不过如果能缓存access_token的话理论上每天能发送100000次,要比垃圾Server酱的1000次好得多。</p>
<h1 id="如何得到参数">
<a href="#如何得到参数"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 如何得到参数?
</h1>
<p>我写的代码是兼容Server酱的,所以跟着他们的配置指南也可以直接用,不过有人可能连Server酱是啥都不知道,我也不给他们引流了,免得浪费他们珍贵的服务器资源。 </p><p>
要做的事情很简单,首先打开<a href="https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login">申请页面</a>,然后扫码登录,成功之后就能看到测试号管理的页面了。 </p><p>
首先看到的是appID和appsecret,这样我们就已经获得了两个参数。另外两个的话就继续往下翻,找到测试号二维码,用微信扫描关注后就会出现自己的微信号,当然这个不是真正的微信号,相当于只是一个识别码,这样第三个参数也得到了。接下来是第四个参数,找到模板消息接口,点击新增测试模板,标题输入推送通知,或者你喜欢的啥都行,内容的话填:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{{title.DATA}}
{{content.DATA}}
</code></pre></div></div>
<p>之所以这样填是为了兼容Server酱,当然也可以自己改代码然后填别的也行。不过如果不想改代码在末尾加个签名也没有问题,比如说这样:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{{title.DATA}}
{{content.DATA}}
--By Mayx
</code></pre></div></div>
<p>这样第四个参数模板ID我们也得到了,这样上面的代码应该可以正常使用了。 </p><p>
需要注意的一点是由于莫名其妙的原因,有可能扫码后第一次得到的appsecret是错的,如果代码不能正常工作,可以刷新测试号管理的页面看看有没有变化,如果有就输入最新的appsecret。</p>
<h1 id="结语">
<a href="#结语"><svg class='octicon' viewBox='0 0 16 16' version='1.1' width='16' height='32' aria-hidden='true'><path fill-rule='evenodd' d='M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z'></path></svg></a> 结语
</h1>
<p>我觉得作为开发者,这种简单的小活就自己干吧,没必要给所谓不赞助就不能用功能的开发者给钱,我觉得既然叫赞助,就不能有差别待遇,不然这就叫做收费,就是商业行为,不要用赞助这种词给自己的资本家行为贴金。</p></main>
<small style="display: block">tags: <a rel="category tag" class="p-category" href="/search.html?keyword=Server"><em>Server</em></a> - <a rel="category tag" class="p-category" href="/search.html?keyword=PHP"><em>PHP</em></a> <span style="float: right;"><a href="https://gitlab.com/mayx/mayx.gitlab.io/tree/master/_posts/2021-02-02-serverchan.md">查看原始文件</a></span></small>
<h4 style="border-bottom: 1px solid #e5e5e5;margin: 2em 0 5px;">推荐文章</h4>
<p id="suggest-container">Loading...</p>
<script>
var suggest = $("#suggest-container");
$.get(BlogAPI + "/suggest?id=/2021/02/02/serverchan.html&update=" + lastUpdated.valueOf(), function (data) {
if (data.length) {
getSearchJSON(function (search) {
suggest.empty();
var searchMap = {};
for (var i = 0; i < search.length; i++) {
searchMap[search[i].url] = search[i];
}
var tooltip = $('<div class="content-tooltip"></div>').appendTo('body').hide();
for (var j = 0; j < data.length; j++) {
var item = searchMap[data[j].id];
if (item) {
var link = $('<a href="' + item.url + '">' + item.title + '</a>');
var contentPreview = item.content.substring(0, 100);
if (item.content.length > 100) {
contentPreview += "……";
}
link.hover(
function(e) {
tooltip.text($(this).data('content'))
.css({
top: e.pageY + 10,
left: e.pageX + 10
})
.show();
},
function() {
tooltip.hide();
}
).mousemove(function(e) {
tooltip.css({
top: e.pageY + 10,
left: e.pageX + 10
});
}).data('content', contentPreview);
suggest.append(link);
suggest.append(' - ' + item.date + '<br />');
}
}
});
} else {
suggest.html("暂无推荐文章……");
}
});
</script>
<br />
<div class="pagination">
<span class="prev">
<a href="/2021/01/17/picore.html">
上一篇:piCore的使用经历
</a>
</span>
<br />
<span class="next">
<a href="/2021/02/06/wechatbot.html">
下一篇:自制一个简单的微信聊天机器人
</a>
</span>
</div>
<!--[if !IE]> -->
<div id="gitalk-container" data-page-id="/2021/02/02/serverchan"></div>
<script>
var gitalk = new Gitalk($.extend({ id: '/2021/02/02/serverchan' }, GitalkConfig));
gitalk.render('gitalk-container');
</script>
<!-- <![endif]-->
</section>
<!--[if !IE]> -->
<div id="landlord" style="left:5px;bottom:0px;">
<div class="message" style="opacity:0"></div>
<canvas id="live2d" width="500" height="560" class="live2d"></canvas>
<div class="live_talk_input_body">
<form id="live_talk_input_form">
<div class="live_talk_input_name_body" >
<input type="checkbox" id="load_this" />
<input type="hidden" id="post_id" value="/2021/02/02/serverchan.html" />
<label for="load_this">
<span style="font-size: 11px; color: #fff;">&#160;想问这篇文章</span>
</label>
</div>
<div class="live_talk_input_text_body">
<input name="talk" type="text" class="live_talk_talk white_input" id="AIuserText" autocomplete="off" placeholder="要和我聊什么呀?" />
<button type="submit" class="live_talk_send_btn" id="talk_send">发送</button>
</div>
</form>
</div>
<input name="live_talk" id="live_talk" value="1" type="hidden" />
<div class="live_ico_box" style="display:none;">
<div class="live_ico_item type_info" id="showInfoBtn"></div>
<div class="live_ico_item type_talk" id="showTalkBtn"></div>
<div class="live_ico_item type_music" id="musicButton"></div>
<div class="live_ico_item type_youdu" id="youduButton"></div>
<div class="live_ico_item type_quit" id="hideButton"></div>
<input name="live_statu_val" id="live_statu_val" value="0" type="hidden" />
<audio src="" style="display:none;" id="live2d_bgm" data-bgm="0" preload="none"></audio>
<input id="duType" value="douqilai" type="hidden" />
</div>
</div>
<div id="open_live2d">召唤伊斯特瓦尔</div>
<!-- <![endif]-->
<footer>
<p>
<small>Made with ❤ by Mayx<br />Last updated at 2026-08-06 18:50:49<br /> 总字数:645545 - 文章数:185 - <a href="/rss.xml">Feed</a> - <a href="/README.html" >About</a></small>
</p>
</footer>
</div>
<script src="/assets/js/scale.fix.js"></script>
<!--[if !IE]> -->
<script src="/assets/js/main_new.js"></script>
<script src="/assets/js/blog-console.js"></script>
<script src="/Live2dHistoire/live2d/js/live2d.js"></script>
<script src="/Live2dHistoire/live2d/js/message.js"></script>
<script src="/assets/js/jquery.pjax.min.js"></script>
<script src="/assets/js/pjax.js"></script>
<!-- <![endif]-->
</body>
</html>