You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Libs\FeiePrintClient;
  5. use Hyperf\HttpServer\Contract\RequestInterface;
  6. use Hyperf\HttpServer\Annotation\AutoController;
  7. use Hyperf\Utils\Coroutine;
  8. use Hyperf\Utils\ApplicationContext;
  9. use Hyperf\Task\TaskExecutor;
  10. use Hyperf\Task\Task;
  11. use App\TaskWorker\SSDBTask;
  12. use App\Commons\Log;
  13. /**
  14. * @AutoController()
  15. * Class TestController
  16. * @package App\Controller
  17. */
  18. class TestController extends AbstractController
  19. {
  20. private $name = 'default action';
  21. protected $client = null;
  22. public function index1(RequestInterface $request)
  23. {
  24. // $container = ApplicationContext::getContainer();
  25. // $exec = $container->get(TaskExecutor::class);
  26. // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()]));
  27. // $client = ApplicationContext::getContainer()->get(SSDBTask::class);
  28. // $result = $client->exec("set","bar","1234");
  29. // $result = $client->exec("get","bar");
  30. // $client = ApplicationContext::getContainer()->get(MethodTask::class);
  31. // $result = $client->handle("set");
  32. // //$log = ApplicationContext::getContainer()->get(Log::class);
  33. // $log = $this->log;
  34. //
  35. // $log->push(['test'=>1,'user_id'=>290,'msg'=>'order']);
  36. // $log->event('t1',['test'=>1,'user_id'=>290,'msg'=>'order']);
  37. //
  38. // //$this->name = 'index1 action '. $result;
  39. // return $this->name;
  40. $time = time();
  41. $msgInfo = array(
  42. 'user' => '13161443713@163.com',
  43. 'stime' => $time,
  44. 'sig' => sha1('13161443713@163.com' . 'XsaHzgePdyWTfcMX' . $time),
  45. 'apiname' => 'Open_printMsg',
  46. 'sn' => '920527381',
  47. 'content' => '1111',
  48. 'times' => 1//打印次数
  49. );
  50. $this->client = new FeiePrintClient('api.feieyun.cn', 80);
  51. if (!$this->client->post('/Api/Open/', $msgInfo)) {
  52. return '12';
  53. } else {
  54. //服务器返回的JSON字符串,建议要当做日志记录起来
  55. $result = $this->client->getContent();
  56. return $result;
  57. }
  58. }
  59. public function index2(RequestInterface $request)
  60. {
  61. $this->name = 'index2 action';
  62. return $this->name;
  63. }
  64. public function index3(RequestInterface $request)
  65. {
  66. return $this->name;
  67. }
  68. }