Baidufast.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\common\extend\urlsend;
  3. use think\Cache;
  4. class Baidufast {
  5. public $name = '百度推送快速';
  6. public $ver = '1.0';
  7. public function submit($data)
  8. {
  9. $token = $GLOBALS['config']['urlsend']['baidufast']['token'];
  10. $site = $GLOBALS['http_type'] . $GLOBALS['config']['site']['site_url'];
  11. $api = 'http://data.zz.baidu.com/urls?site='.$site.'&token='.$token.'&type=daily';
  12. $head = ['Content-Type: text/plain'];
  13. $post = implode("\n", $data['urls']);
  14. $r = mac_curl_post($api, $post, $head);
  15. $json = json_decode($r,true);
  16. if(!$json){
  17. return ['code'=>101,'msg'=>'请求失败,请重试'];
  18. }
  19. elseif($json['error']){
  20. return ['code'=>102,'msg'=>'发生错误:'. $json['message'] ];
  21. }
  22. elseif($json['remain'] ==0 && $json['success']>0){
  23. $data = array_slice($data['urls'], 0, $json['success'],true );
  24. $keys = array_keys($data);
  25. $this->_lastid = end($keys);
  26. $data = implode("\n", $data);
  27. $r = mac_curl_post($api, $data, $head);
  28. $json = json_decode($r,true);
  29. if(!$json){
  30. return ['code'=>103,'msg'=>'请求失败,请重试2'];
  31. }
  32. elseif($json['error']){
  33. return ['code'=>104,'msg'=>'发生错误2:'. $json['message'] ];
  34. }
  35. }
  36. return ['code'=>1,'msg'=>'推送'.$json['remain'].'条;剩余可推送'.$json['success'].'条.' ];
  37. }
  38. }