|
cookie 获取方法:
1、打开 https://kg.qq.com/ 扫码登录
2、F12 >> 控制台输入“document.cookie” >> 回车即可获取
获取到的cookie填写到程序里,然后添加监控,1分钟
- <?php
- $kg = new Kg;
- $kg->cookie = ''; // 填写您的cookie
- $kg->cron();
-
- Class Kg
- {
- public $cookie = '';
- public $config = array(
- 'cache_path' => __DIR__.'/kg_cache/',
- 'cwxrobot' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=0d9b8dc4-46db-46e2-95b5-**************', // 企业微信通知
- );
-
- public function cron(){
- $this->comm_store(); // K歌花园兑换
- $this->garden(); // K歌花园播种
- }
-
- // K歌花园
- private function garden(){
- $cache = $this->cache('kg_garden_'.$this->uid());
- if($cache){return $cache;}
- $garden = $this->garden__webapp__info();
- if($garden['code'] == 0)
- {
- $landList = $garden['data']['garden.webapp.info']['garden']['landList'];
- $cron_garden = 60;
- foreach ($landList as $k => $v) {
- if($v['isActived'] == 1){ // 激活
- $leftTime = $v['seed']['leftTime']; // 剩余时间
- if($leftTime == 0){ // 一旦有空位/成熟 直接 一键收 + 一键播
- $this->garden__webapp__harvest(); // 一键收
- $rs = $this->garden__webapp__plant(); // 一键播
- if($rs['subcode'] == '-10003'){
- $this->cache('kg_garden_'.$this->uid(), $landList, 43200); // 没种子啦 12小时内不执行
- }
- return $rs;
- }
- // 预估下次执行时间
- $cron_garden = $leftTime > $cron_garden ? $leftTime : $cron_garden;
- }
- }
- $this->cache('kg_garden_'.$this->uid(), $landList, $cron_garden);
- }else{
- $this->send('error: '.$this->uid()." cookie Invalid !");
- }
- }
-
- private function comm_store(){
- $cache = $this->cache('kg_garden_comm_store_'.$this->uid());
- if($cache){return ['message'=>'今日不会再兑换了'];}
- $rs = $this->comm_store__webapp__list();
- if($rs['code'] == 0){
- $balance = $rs['data']['comm_store.webapp.list']['balance']; $leftNum = 0;
- $storeItemList = $rs['data']['comm_store.webapp.list']['storeItemList'];
- foreach ($storeItemList as $key => $v) {
- $leftNum += $v['leftNum'];
- if($v['leftNum'] > 0){
- if($v['cost'] * $v['leftNum'] < $balance){
- $res = $this->comm_store__webapp__exchange($v['itemId'], $v['leftNum']);
- $balance = $balance - $v['cost'] * $v['leftNum'];
- }else{
- $this->cache('kg_garden_comm_store_'.$this->uid(), $storeItemList, strtotime(date('Y-m-d H:i:s')) + 86400 - time());
- return false; // 意思是最少需要有2000金币 不然不会执行兑换 只能自己兑换
- }
- }
- }
- $leftNum == 0 ? $this->cache('kg_garden_comm_store_'.$this->uid(), $storeItemList, strtotime(date('Y-m-d H:i:s')) + 86400 - time()) : '';
- }
- }
-
- // 兑换种子
- private function comm_store__webapp__exchange($t_itemId, $t_num)
- {
- $url = 'https://node.kg.qq.com/webapp/proxy?t_storeId=8&t_uid=' . $this->uid() . '&t_itemId=' . $t_itemId . '&t_num=' . $t_num . '&ns=proto_comm_store_webapp&cmd=comm_store.webapp.exchange&ns_inbuf=&cmdPrefix=&mapExt=JTdCJTIyZmlsZSUyMiUzQSU3QiUyMmZpbGVQYXRoUmVsYXRpdmVPdXRwdXQlMjIlM0ElMjJqY2VfbmV3JTJGa2clMkZjb21tX3N0b3JlJTJGcHJvdG9fY29tbV9zdG9yZV93ZWJhcHBfdjIuanMlMjIlMkMlMjJkZXBGaWxlUGF0aFJlbGF0aXZlT3V0cHV0JTIyJTNBJTVCJTVEJTdEJTJDJTIyY21kTmFtZSUyMiUzQSUyMlN0b3JlRXhjaGFuZ2VSZXElMjIlMkMlMjJ3bnNEaXNwYXRjaGVyJTIyJTNBdHJ1ZSU3RA%3D%3D&g_tk=5381&g_tk_openkey=245581372';
- $headers = array(
- 'Host: node.kg.qq.com',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
- 'Accept: application/json, text/plain, */*',
- 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
- 'Accept-Encoding: gzip, deflate, br',
- 'Referer: https://kg.qq.com/',
- 'Origin: https://kg.qq.com',
- 'Sec-Fetch-Dest: empty',
- 'Sec-Fetch-Mode: cors',
- 'Sec-Fetch-Site: same-site',
- 'Connection: keep-alive',
- 'Cookie: ' . $this->cookie,
- );
- $rs = json_decode($this->request($url, $headers),true);
- return $rs;
- }
-
- // 查询剩余可兑换种子
- private function comm_store__webapp__list(){
- $url = 'https://node.kg.qq.com/webapp/proxy?t_storeId=8&t_uid=' . $this->uid() . '&t_num=20&t_typeId=1&t_passback=&ns=proto_comm_store_webapp&cmd=comm_store.webapp.list&ns_inbuf=&cmdPrefix=&mapExt=JTdCJTIyZmlsZSUyMiUzQSU3QiUyMmZpbGVQYXRoUmVsYXRpdmVPdXRwdXQlMjIlM0ElMjJqY2VfbmV3JTJGa2clMkZjb21tX3N0b3JlJTJGcHJvdG9fY29tbV9zdG9yZV93ZWJhcHBfdjIuanMlMjIlMkMlMjJkZXBGaWxlUGF0aFJlbGF0aXZlT3V0cHV0JTIyJTNBJTVCJTVEJTdEJTJDJTIyY21kTmFtZSUyMiUzQSUyMkNvbW1TdG9yZUxpc3RSZXElMjIlMkMlMjJ3bnNEaXNwYXRjaGVyJTIyJTNBdHJ1ZSU3RA%3D%3D&g_tk=5381&g_tk_openkey=245581372';
- $headers = array(
- 'Host: node.kg.qq.com',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
- 'Accept: application/json, text/plain, */*',
- 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
- 'Accept-Encoding: gzip, deflate, br',
- 'Referer: https://kg.qq.com/',
- 'Origin: https://kg.qq.com',
- 'Sec-Fetch-Dest: empty',
- 'Sec-Fetch-Mode: cors',
- 'Sec-Fetch-Site: same-site',
- 'Connection: keep-alive',
- 'Cookie: ' . $this->cookie,
- );
- $rs = json_decode($this->request($url, $headers),true);
- return $rs;
- }
-
- // K歌花园 获取种植信息
- private function garden__webapp__info(){
- $url = 'https://node.kg.qq.com/webapp/proxy';
- $url .= '?t_uid=' . $this->uid();
- $url .= '&ns=proto_garden_webapp&cmd=garden.webapp.info&g_tk=5381&g_tk_openkey=1469557487';
- $url .= '&mapExt=JTdCJTIyZmlsZSUyMiUzQSU3QiUyMmZpbGVQYXRoUmVsYXRpdmVPdXRwdXQlMjIlM0ElMjJqY2VfbmV3JTJGa2clMkZnYXJkZW4lMkZwcm90b19nYXJkZW5fd2ViYXBwX3YyLmpzJTIyJTJDJTIyZGVwRmlsZVBhdGhSZWxhdGl2ZU91dHB1dCUyMiUzQSU1QiUyMmpjZV9uZXclMkZrZyUyRnVuaV9wYXlfcHJveHklMkZ1bmlfcGF5X3Byb3h5X3YyLmpzJTIyJTVEJTdEJTJDJTIyY21kTmFtZSUyMiUzQSUyMkdhcmRlbkluZm9SZXElMjIlMkMlMjJ3bnNEaXNwYXRjaGVyJTIyJTNBdHJ1ZSU3RA=='; // 好大一个包
- //$url .= '&t_source=&t_deviceInfo=&ns_inbuf=&cmdPrefix=';
- $headers = array(
- 'Host: node.kg.qq.com',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
- 'Accept: application/json, text/plain, */*',
- 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
- 'Accept-Encoding: gzip, deflate, br',
- 'Referer: https://kg.qq.com/',
- 'Origin: https://kg.qq.com',
- 'Sec-Fetch-Dest: empty',
- 'Sec-Fetch-Mode: cors',
- 'Sec-Fetch-Site: same-site',
- 'Connection: keep-alive',
- 'Cookie: ' . $this->cookie,
- );
- $rs = json_decode($this->request($url, $headers),true); // ['data']['garden.webapp.info']['garden']['landList']
- return $rs;
- }
-
- // K歌花园 指定收获 多此一举...
- private function garden__webapp__timer_report($t_landId=''){
- $url = 'https://node.kg.qq.com/webapp/proxy?t_landId='.$t_landId.'&t_passback=&t_deviceInfo=&ns=proto_garden_webapp&cmd=garden.webapp.timer_report&ns_inbuf=&cmdPrefix=&mapExt=JTdCJTIyZmlsZSUyMiUzQSU3QiUyMmZpbGVQYXRoUmVsYXRpdmVPdXRwdXQlMjIlM0ElMjJqY2VfbmV3JTJGa2clMkZnYXJkZW4lMkZwcm90b19nYXJkZW5fd2ViYXBwX3YyLmpzJTIyJTJDJTIyZGVwRmlsZVBhdGhSZWxhdGl2ZU91dHB1dCUyMiUzQSU1QiUyMmpjZV9uZXclMkZrZyUyRnVuaV9wYXlfcHJveHklMkZ1bmlfcGF5X3Byb3h5X3YyLmpzJTIyJTVEJTdEJTJDJTIyY21kTmFtZSUyMiUzQSUyMlRpbWVyUmVwb3J0UmVxJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q%3D&g_tk=5381&g_tk_openkey=1469557487';
- $headers = array(
- 'Host: node.kg.qq.com',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
- 'Accept: application/json, text/plain, */*',
- 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
- 'Accept-Encoding: gzip, deflate, br',
- 'Referer: https://kg.qq.com/',
- 'Origin: https://kg.qq.com',
- 'Sec-Fetch-Dest: empty',
- 'Sec-Fetch-Mode: cors',
- 'Sec-Fetch-Site: same-site',
- 'Connection: keep-alive',
- 'Cookie: ' . $this->cookie,
- );
- $rs = json_decode($this->request($url, $headers),true);
- return $rs;
- }
-
- // K歌花园 一键收获
- private function garden__webapp__harvest(){
- $url = 'https://node.kg.qq.com/webapp/proxy?t_uid='.$this->uid().'&t_deviceInfo=&t_oneClick=1&ns=proto_garden_webapp&cmd=garden.webapp.harvest&ns_inbuf=&cmdPrefix=&mapExt=JTdCJTIyZmlsZSUyMiUzQSU3QiUyMmZpbGVQYXRoUmVsYXRpdmVPdXRwdXQlMjIlM0ElMjJqY2VfbmV3JTJGa2clMkZnYXJkZW4lMkZwcm90b19nYXJkZW5fd2ViYXBwX3YyLmpzJTIyJTJDJTIyZGVwRmlsZVBhdGhSZWxhdGl2ZU91dHB1dCUyMiUzQSU1QiUyMmpjZV9uZXclMkZrZyUyRnVuaV9wYXlfcHJveHklMkZ1bmlfcGF5X3Byb3h5X3YyLmpzJTIyJTVEJTdEJTJDJTIyY21kTmFtZSUyMiUzQSUyMkdhcmRlbkhhcnZlc3RSZXElMjIlMkMlMjJ3bnNEaXNwYXRjaGVyJTIyJTNBdHJ1ZSU3RA%3D%3D&g_tk=5381&g_tk_openkey=1469557487';
- $headers = array(
- 'Host: node.kg.qq.com',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
- 'Accept: application/json, text/plain, */*',
- 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
- 'Accept-Encoding: gzip, deflate, br',
- 'Referer: https://kg.qq.com/',
- 'Origin: https://kg.qq.com',
- 'Sec-Fetch-Dest: empty',
- 'Sec-Fetch-Mode: cors',
- 'Sec-Fetch-Site: same-site',
- 'Connection: keep-alive',
- 'Cookie: ' . $this->cookie,
- );
- $rs = json_decode($this->request($url, $headers),true);
- return $rs;
- }
-
- // K歌花园 一键播种
- private function garden__webapp__plant(){
- $url = 'https://node.kg.qq.com/webapp/proxy?t_uid='.$this->uid().'&t_seedId=0&t_landId=0&t_deviceInfo=&t_oneClick=1&ns=proto_garden_webapp&cmd=garden.webapp.plant&ns_inbuf=&cmdPrefix=&mapExt=JTdCJTIyZmlsZSUyMiUzQSU3QiUyMmZpbGVQYXRoUmVsYXRpdmVPdXRwdXQlMjIlM0ElMjJqY2VfbmV3JTJGa2clMkZnYXJkZW4lMkZwcm90b19nYXJkZW5fd2ViYXBwX3YyLmpzJTIyJTJDJTIyZGVwRmlsZVBhdGhSZWxhdGl2ZU91dHB1dCUyMiUzQSU1QiUyMmpjZV9uZXclMkZrZyUyRnVuaV9wYXlfcHJveHklMkZ1bmlfcGF5X3Byb3h5X3YyLmpzJTIyJTVEJTdEJTJDJTIyY21kTmFtZSUyMiUzQSUyMkdhcmRlblBsYW50UmVxJTIyJTJDJTIyd25zRGlzcGF0Y2hlciUyMiUzQXRydWUlN0Q%3D&g_tk=5381&g_tk_openkey=1469557487';
- $headers = array(
- 'Host: node.kg.qq.com',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
- 'Accept: application/json, text/plain, */*',
- 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
- 'Accept-Encoding: gzip, deflate, br',
- 'Referer: https://kg.qq.com/',
- 'Origin: https://kg.qq.com',
- 'Sec-Fetch-Dest: empty',
- 'Sec-Fetch-Mode: cors',
- 'Sec-Fetch-Site: same-site',
- 'Connection: keep-alive',
- 'Cookie: ' . $this->cookie,
- );
- $rs = json_decode($this->request($url, $headers),true);
- return $rs;
- }
-
- // 获取 uid
- private function uid(){
- $cookie = explode("; ", $this->cookie); $cookie_array = array();
- foreach ($cookie as $key => $value) {
- $va = explode("=", $value);
- $cookie_array[$va[0]] = $va[1];
- }
- if(!isset($cookie_array['uid'])){exit("cookie is invalid");}
- return $cookie_array['uid'];
- }
-
- // 发送通知
- private function send($message){
- $mess = array(
- 'msgtype' => 'text',
- 'text' => array(
- 'content' => $message,
- ),
- );
- $result = $this->request($this->config['cwxrobot'],['Content-Type: application/json'],json_encode($mess),"POST");
- return $result;
- }
-
- private function cache($name, $value ='', $expires_in='')
- {
- if(!is_dir($this->config['cache_path'])){mkdir($this->config['cache_path']);}
- $key = md5($name);
- $cache_file = $this->config['cache_path'].$key.'.txt';
- if($value == '' && $expires_in == ''){
- if(is_file($cache_file)){
- $cache = unserialize(file_get_contents($cache_file));
- if($cache['expires_in'] > time()){
- return $cache['data'];
- }
- }
- return false;
- }elseif($value != '' && $value != null){
- $cache = array('data' => $value, 'expires_in' => time() + $expires_in);
- file_put_contents($cache_file, serialize($cache));
- }elseif($value == null){
- is_file($cache_file) ? unlink($cache_file) : '';
- }
- }
-
- private function request($Url, $Header = null, $Data = null, $Method = "GET"){
- $ch = curl_init();
- $Header = $Header ? $Header : array("Content-Type:application/json;charset=utf-8;","Accept:application/json");
- curl_setopt($ch, CURLOPT_URL, $Url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- if($Method == 'GET'){
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
- curl_setopt($ch, CURLOPT_POST, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
- }
- if($Method == 'POST'){
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
- }
- if($Method == 'PUT'){
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
- }
- if($Method == 'DELETE'){
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
- }
- if($Method == 'PATCH'){
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $Data);
- }
- curl_setopt($ch, CURLOPT_TIMEOUT, 3);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $Header);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
-
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- }
-
- ?>
复制代码
|
|