UpdateOuter.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Modules\Book\Models\BookConfig;
  4. use App\Modules\Book\Services\BookConfigService;
  5. use GuzzleHttp\Cookie\SetCookie;
  6. use Illuminate\Console\Command;
  7. use GuzzleHttp\Client;
  8. use App\Modules\Book\Models\Book;
  9. use App\Modules\Book\Models\Chapter;
  10. use DB;
  11. class UpdateOuter extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'book:updateouter {--type=} {--bid=}';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = 'Command description';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return mixed
  38. */
  39. public function handle()
  40. {
  41. //
  42. }
  43. //微月云
  44. private function updateOneFromWyy($bid,$wyy_bid){
  45. $last_chapter = Chapter::where('bid',$bid)
  46. ->select('id','name','sequence','prev_cid','next_cid')
  47. ->orderBy('sequence','desc')
  48. ->first();
  49. $now_sequence = $last_chapter->sequence+1;
  50. $url_format = 'https://wxg6y88rwiqvjkvx.weiyueyunsc.com/ChapterContent/content/fromaid/326695218.html?bookid=%s&num=%s';
  51. $client = new Client();
  52. $cookie = 'prid=0;uid=2;user_id=268860471;user_name=we20190312pen_name妙妙;portrait=http://thirdwx.qlogo.cn/mmopen/EH4aHSGnx7EU03AbVwKkQZoHH4kd3W3iarLibW9XqQuUfTjs7ZBnsmZZaficujibBl144FH9yWfNKaRLxUWc8N4G1FHDBv9wOUH8/132;admin_id=326695218;subscribe=1;shell=8de1e2d1789ed1a7a6f1673d9373123d;OPENID=olpZ50lR6G-pLQ8WYiQXVw6Wg8U0;PHPSESSID=gdps01shh5ood1e75prvkuihp2;VALIDON=1569237596;CRC=be4cea518f4058b00a80c8ce03333178;';
  53. $last_chapter_id = $last_chapter->id;
  54. $j = 0;
  55. $word = 0;
  56. while (true){
  57. $url = sprintf($url_format,$wyy_bid,$now_sequence);
  58. $result = $client->request('get',$url,[
  59. 'headers'=>[
  60. 'cookie'=>$cookie,
  61. 'User-Agent'=>'Mozilla/5.0 (Linux; Android 8.0.0; MI 6 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 XWEB/882 MMWEBSDK/190503 Mobile Safari/537.36 MMWEBID/223 MicroMessenger/7.0.5.1420(0x27000530) Process/tools NetType/WIFI Language/zh_CN',
  62. 'X-Requested-With'=>'XMLHttpRequest'
  63. ]
  64. ])->getBody()->getContents();
  65. $result = json_decode($result,1);
  66. if(!isset($result['content_title']) || !isset($result['content_contents'])){
  67. break;
  68. }
  69. $title = $result['content_title'];
  70. $content = $result['content_contents'];
  71. $content = str_replace('</p>',"\r\n",$content);
  72. $content = str_replace('<p>',"",$content);
  73. $temp = [
  74. 'bid' => $bid,
  75. 'name' => $title,
  76. 'sequence' => $now_sequence,
  77. 'is_vip' => 1,
  78. 'prev_cid' => $last_chapter_id,
  79. 'next_cid' => '',
  80. 'recent_update_at' => date('Y-m-d H:i:s'),
  81. 'ly_chapter_id' => 0,
  82. 'content'=>$content,
  83. 'size'=>mb_strlen($content)
  84. ];
  85. $word += mb_strlen($content);
  86. $insert_res = Chapter::create($temp);
  87. $last_chapter_id = $insert_res->id;
  88. $now_sequence++;
  89. $j++;
  90. }
  91. $chapter_count = Chapter::where('bid', $bid)->count();
  92. $chapter_size = Chapter::where('bid', $bid)->sum('size');
  93. if ($j > 0) {
  94. Book::where('id', $bid)->update(['chapter_count' => $chapter_count, 'last_cid' => $last_chapter_id, 'size' => $chapter_size, 'last_chapter' => $title]);
  95. $book_info = BookConfigService::getBookById($bid);
  96. $data = [
  97. 'book_name'=>$book_info->book_name,
  98. 'channel_name'=>$book_info->category_id >=13 ? '女频':'男频',
  99. 'update_type'=>'add_chapter',
  100. 'update_chapter_count'=>0,
  101. 'update_words'=>0,
  102. ];
  103. $data['update_chapter_count'] = $j;
  104. $data['update_words'] = $word;
  105. $this->recordUpdateInfo($bid,$data);
  106. }
  107. }
  108. private function recordUpdateInfo($bid, $data)
  109. {
  110. // 2 book_updates 的更新记录
  111. DB::table('book_updates')->insert([
  112. 'bid' => $bid,
  113. 'book_name' => $data['book_name'],
  114. 'channel_name' => $data['channel_name'],
  115. 'update_date' => date('Y-m-d'),
  116. 'update_chapter_count' => $data['update_chapter_count'],
  117. 'update_words' => $data['update_words'],
  118. 'update_type' => $data['update_type'],
  119. 'created_at' => date('Y-m-d H:i:s'),
  120. 'updated_at' => date('Y-m-d H:i:s')
  121. ]);
  122. }
  123. }