BaiduController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\admin\controller;
  3. use cmf\controller\AdminBaseController;
  4. use think\Db;
  5. use tree\Tree;
  6. class BaiduController extends AdminBaseController{
  7. // 百度链接自动提交
  8. public function baidu(){
  9. $param = $this->request->param();
  10. if (isset($param['ids'])) {
  11. $ids = $param['ids'];
  12. $where = [];
  13. $where[] = ['id','in', $ids];
  14. // $field = 'a.id,a.baidu,a.post_title,b.category_id,c.alias';
  15. // $artRes = Db::name('jiameng')->alias('a')->field($field)
  16. // ->join('brand_category_post b','a.id = b.post_id')
  17. // ->join('brand_category c','b.category_id = c.id')
  18. // ->where($where)
  19. // ->order('a.create_time', 'DESC')
  20. // ->select()->toArray();
  21. $artRes = Db::name('jiameng')->where($where)->select()->toArray();
  22. }
  23. // print_r($artRes);die;
  24. $urls = array();
  25. $dataRes = array();
  26. $local = $_SERVER['SERVER_NAME'];
  27. foreach ($artRes as $k => &$v) {
  28. $v['arcurl'] = 'http://'.$local.'/b'.$v['id']."/";
  29. if($v['baidu']==0){
  30. $urls[] = $v['arcurl'];
  31. $dataRes[$v['id']] = $v['post_title'];
  32. }
  33. }
  34. $site_info = cmf_get_option('site_info');
  35. // print_r($site_info);die;
  36. if($site_info['site_tj_pc'] == ''){
  37. $this->error("请设置百度提交参数!",'');
  38. }
  39. $site_baidu = $site_info['site_tj_pc'];
  40. $site_baidu = explode('&amp;', $site_baidu);
  41. $site_baidu = implode('&', $site_baidu);
  42. $site_baidu = str_replace(PHP_EOL, '', $site_baidu);
  43. // dump($dataRes);die;
  44. if(count($urls)>0 && trim($site_baidu)!=''){
  45. $api = $site_baidu;
  46. $ch = curl_init();
  47. $options = array(
  48. CURLOPT_URL => $api,
  49. CURLOPT_POST => true,
  50. CURLOPT_RETURNTRANSFER => true,
  51. CURLOPT_POSTFIELDS => implode("\n", $urls),
  52. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  53. );
  54. curl_setopt_array($ch, $options);
  55. $curlresult = curl_exec($ch);
  56. $cuarray = json_decode($curlresult,true);
  57. // dump($cuarray);die;
  58. if($cuarray['success']>0){
  59. //如果提交过并且成功的将其状态标记为1
  60. foreach ($dataRes as $k => $v) {
  61. Db::name('brand_post')->where('id',$k)->update(['baidu' => '1']);
  62. }
  63. $this->success("共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条','');
  64. }else{
  65. $this->error("今天提交已经到上线,明天再来吧!",'');
  66. }
  67. }else{
  68. $this->success("没有新百度Pc连接提交",'');
  69. }
  70. }
  71. // 百度手机链接自动提交
  72. public function shouji(){
  73. $param = $this->request->param();
  74. if (isset($param['ids'])) {
  75. $ids = $param['ids'];
  76. $where[] = ['id','in', $ids];
  77. $artRes = Db::name('jiameng')->where($where)->select()->toArray();
  78. }
  79. $urls = array();
  80. $dataRes = array();
  81. $local = $_SERVER['SERVER_NAME'];
  82. $host = explode('.', $local);
  83. if(count($host)==3){
  84. $host = $host[1].'.'.$host[2];
  85. }else{
  86. $host = $host[1].'.'.$host[2].'.'.$host[3];
  87. }
  88. $local = 'm.'.$host;
  89. foreach ($artRes as $k => &$v) {
  90. $v['arcurl'] = 'http://'.$local.'/b'.$v['id']."/";
  91. if($v['shouji']==0){
  92. $urls[] = $v['arcurl'];
  93. $dataRes[$v['id']] = $v['post_title'];
  94. }
  95. }
  96. $site_info = cmf_get_option('site_info');
  97. if($site_info['site_tj_mobile'] == ''){
  98. $this->error("请设置百度提交参数!",'');
  99. }
  100. $site_shouji = $site_info['site_tj_mobile'];
  101. $site_shouji = explode('&amp;', $site_shouji);
  102. $site_shouji = implode('&', $site_shouji);
  103. $site_shouji = str_replace(PHP_EOL, '', $site_shouji);
  104. // print_r($urls);exit;
  105. if(count($urls)>0 && trim($site_shouji)!=''){
  106. $api = $site_shouji;
  107. $ch = curl_init();
  108. $options = array(
  109. CURLOPT_URL => $api,
  110. CURLOPT_POST => true,
  111. CURLOPT_RETURNTRANSFER => true,
  112. CURLOPT_POSTFIELDS => implode("\n", $urls),
  113. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  114. );
  115. curl_setopt_array($ch, $options);
  116. $curlresult = curl_exec($ch);
  117. $cuarray = json_decode($curlresult,true);
  118. // dump($cuarray);die;
  119. if($cuarray['success']>0){
  120. //如果提交过并且成功的将其状态标记为1
  121. foreach ($dataRes as $k => $v) {
  122. Db::name('brand_post')->where('id',$k)->update(['shouji' => '1']);
  123. }
  124. $this->success("<br/>共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条<br/>','');
  125. }else{
  126. $this->error("今天提交已经到上线,明天再来吧!".'');
  127. }
  128. }else{
  129. $this->success("没有新手机百度连接提交",'');
  130. }
  131. }
  132. // 百度链接自动提交
  133. public function bear(){
  134. $param = $this->request->param();
  135. $param = $this->request->param();
  136. if (isset($param['ids'])) {
  137. $ids = $param['ids'];
  138. $where[] = ['id','in', $ids];
  139. $artRes = Db::name('jiameng')->where($where)->select()->toArray();
  140. }
  141. //dump($artRes);die;
  142. $urls = array();
  143. $dataRes = array();
  144. $local = $_SERVER['SERVER_NAME'];
  145. foreach ($artRes as $k => &$v) {
  146. $v['arcurl'] = 'http://'.$local.'/b'.$v['id']."/";
  147. if($v['xiongzhang']==0){
  148. $urls[] = $v['arcurl'];
  149. $dataRes[$v['id']] = $v['post_title'];
  150. }
  151. }
  152. // dump($urls);exit;
  153. $site_info = cmf_get_option('site_info');
  154. //dump($site_info);die;
  155. if($site_info['site_tj_xiongzhang'] == ''){
  156. $this->error("请设置熊掌号提交参数!",'');
  157. }
  158. $site_xiongzhang = $site_info['site_tj_xiongzhang'];
  159. $site_xiongzhang = explode('&amp;', $site_xiongzhang);
  160. $site_xiongzhang = implode('&', $site_xiongzhang);
  161. $site_xiongzhang = str_replace(PHP_EOL, '', $site_xiongzhang);
  162. // dump($dataRes);die;
  163. if(count($urls)>0 && trim($site_xiongzhang)!=''){
  164. $api = trim($site_xiongzhang);
  165. $ch = curl_init();
  166. $options = array(
  167. CURLOPT_URL => $api,
  168. CURLOPT_POST => true,
  169. CURLOPT_RETURNTRANSFER => true,
  170. CURLOPT_POSTFIELDS => implode("\n", $urls),
  171. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  172. );
  173. curl_setopt_array($ch, $options);
  174. $curlresult = curl_exec($ch);
  175. $cuarray = json_decode($curlresult,true);
  176. // dump($cuarray);die;
  177. if($cuarray['success']>0){
  178. //如果提交过并且成功的将其状态标记为1
  179. foreach ($dataRes as $k => $v) {
  180. Db::name('brand_post')->where('id',$k)->update(['xiongzhang' => '1']);
  181. }
  182. $this->success("<br/>共提交".$cuarray['success']."条。今日自动提交剩余".$cuarray['remain'].'条<br/>','');
  183. }else{
  184. $this->error("今天提交已经到上线,明天再来吧!",'');
  185. }
  186. }else{
  187. $this->success("没有新熊掌天级连接提交",'');
  188. }
  189. }
  190. }