控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 神马操作类
  13. // +----------------------------------------------------------------------
  14. namespace addons\weburlpush\library\push\driver;
  15. use addons\weburlpush\library\push\Driver;
  16. use GuzzleHttp\Exception\ClientException;
  17. use think\Exception;
  18. class Shenma extends Driver
  19. {
  20. public function push($urls)
  21. {
  22. return $this->request($urls);
  23. }
  24. protected function request($urls)
  25. {
  26. $url = "https://data.zhanzhang.sm.cn/push?site={$this->config['site']}&user_name={$this->config['user_name']}&resource_name=mip_add&token={$this->config['token']}";
  27. try {
  28. $response = $this->getHttpClient()->post($url, [
  29. 'headers' => ['Content-Type' => 'text/plain'],
  30. 'body' => implode("\n", $urls),
  31. ]);
  32. $body = json_decode($response->getBody(), true);
  33. if ($body['returnCode'] !== 200) {
  34. throw new Exception($body['errorMsg']);
  35. }
  36. return $body;
  37. } catch (ClientException $e) {
  38. $body = json_decode($e->getResponse()->getBody(), true);
  39. throw new Exception($body['errorMsg']);
  40. }
  41. }
  42. }