php5类,用于easybots

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php5类,用于easybots相关的知识,希望对你有一定的参考价值。

  1. <?php
  2.  
  3. /* EasyBots<http://www.easybots.cn> class by xuanyan <[email protected]> */
  4.  
  5. // example:
  6. // receive user message:
  7. // $token = 'xxxxx';
  8. // $param = EasyBots::getParam();
  9. // if ($param['token'] == $token)
  10. // {
  11. // // var_dump($param);
  12. // }
  13. // //exit;
  14. // ----------------------------
  15. // send message to user:
  16. // $oapi_id = 'xxxxx';
  17. // $ack = 'xxxxx';
  18. // $bot = new EasyBots($oapi_id, $ack, 'gtalk:[email protected]');
  19. // $bot->send('palapla');
  20. // // or
  21. // $bot2 = new EasyBots($oapi_id, $ack,
  22. // array(
  23. // 'gtalk:[email protected]',
  24. // ));
  25. // $bot2->send('palapla');
  26.  
  27. class EasyBots
  28. {
  29. const URL = 'http://www.easybots.cn/oapi_mo.net';
  30. private $oapi_id = null;
  31. private $ack = null;
  32. private $im = '';
  33.  
  34. public function __construct($oapi_id, $ack, $im)
  35. {
  36. $this->oapi_id = intval($oapi_id);
  37. $this->ack = trim($ack);
  38. $this->im = implode(',', (array)$im);
  39. }
  40.  
  41. public function send($msg)
  42. {
  43. $data = array(
  44. 'oapi_id' => $this->oapi_id,
  45. 'ack' => $this->ack,
  46. 'im' => $this->im,
  47. 'msg' => trim($msg)
  48. );
  49. $data = http_build_query($data);
  50. $opts = array (
  51. 'http' => array (
  52. 'method' => 'POST',
  53. 'header'=> "Content-type: application/x-www-form-urlencoded
  54. " .
  55. "Content-Length: " . strlen($data) . "
  56. ",
  57. 'content' => $data
  58. )
  59. );
  60.  
  61. $context = stream_context_create($opts);
  62. $html = @file_get_contents(self::URL, false, $context);
  63.  
  64. return (100 == intval($html));
  65. }
  66.  
  67. public static function getParam()
  68. {
  69. return array(
  70. 'e' => isset($_POST['e']) ? trim($_POST['e']) : '',
  71. 'msg' => isset($_POST['msg']) ? trim($_POST['msg']) : '',
  72. 'im' => isset($_POST['im']) ? trim($_POST['im']) : '',
  73. 'token' => isset($_POST['token']) ? trim($_POST['token']) : ''
  74. );
  75. }
  76. }
  77.  
  78. ?>

以上是关于php5类,用于easybots的主要内容,如果未能解决你的问题,请参考以下文章

Appsync 的 graphql 订阅不适用于 PHP5

php5-fpm 的 display_errors 不适用于 nginx

PHP PHP5 Singleton类

PHP PHP5中的简单类示例

PHP PHP5 Session Wraper类

PHP5程序中新增加日期(date)函数的常量