add WebQQ support.

This commit is contained in:
dennydai 2016-02-15 02:13:17 +08:00
parent 0297df5d37
commit cd61f21a92
4 changed files with 126 additions and 0 deletions

48
classes/WebQQ/Base.php Normal file
View File

@ -0,0 +1,48 @@
<?php
class Base
{
public function exec($raw)
{
echo $raw;
return true;
}
public function post($url,$postfields)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_ENCODING, 'gzip');
curl_setopt($ch,CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch,CURLOPT_COOKIE, WQ_Cookie);
curl_setopt($ch,CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0');
curl_setopt($ch,CURLOPT_REFERER, 'http://d1.web2.qq.com/proxy.html');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public function msg($id, $msg)
{
global $isgroup;
$sp = [];
if (floor(strlen($msg)/200) > 1) {
$sp_num = floor(strlen($msg)/300);
for ($i=0; $i < $sp_num; $i++) {
$sp[$i] = substr($msg,$i*300,300);
}
foreach ($sp as $sps) {
if($isgroup){
$this->post('http://d1.web2.qq.com/channel/send_qun_msg2','r={"group_uin":'.$id.',"content":"[\"'.$sps.'\",[\"font\",{\"name\":\"\",\"size\":10,\"style\":[0,0,0],\"color\":\"000000\"}]]","face":0,"clientid":53999199,"msg_id":0,"psessionid":""}');
}else{
$this->post('http://d1.web2.qq.com/channel/send_buddy_msg2','r={"to":'.$id.',"content":"[\"'.$sps.'\",[\"font\",{\"name\":\"\",\"size\":10,\"style\":[0,0,0],\"color\":\"000000\"}]]","face":0,"clientid":53999199,"msg_id":0,"psessionid":""}');
}
}
}else{
if($isgroup){
$this->post('http://d1.web2.qq.com/channel/send_qun_msg2','r={"group_uin":'.$id.',"content":"[\"'.$msg.'\",[\"font\",{\"name\":\"\",\"size\":10,\"style\":[0,0,0],\"color\":\"000000\"}]]","face":0,"clientid":53999199,"msg_id":0,"psessionid":""}');
}else{
$this->post('http://d1.web2.qq.com/channel/send_buddy_msg2','r={"to":'.$id.',"content":"[\"'.$msg.'\",[\"font\",{\"name\":\"\",\"size\":10,\"style\":[0,0,0],\"color\":\"000000\"}]]","face":0,"clientid":53999199,"msg_id":0,"psessionid":""}');
}
}
return 1;
}
}

View File

@ -0,0 +1,61 @@
<?php
ignore_user_abort();
set_time_limit(0);
include "../../config.php";
function post($url,$postfields){
global $COOKIE;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_ENCODING,'gzip');
curl_setopt($ch,CURLOPT_POSTFIELDS,$postfields);
curl_setopt($ch,CURLOPT_COOKIE, WQ_Cookie);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0');
curl_setopt($ch,CURLOPT_REFERER,'http://d1.web2.qq.com/proxy.html');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function Heartbeats(){
$data = post('http://d1.web2.qq.com/channel/poll2','r={"ptwebqq":"","clientid":53999199,"psessionid":"","key":""}');
if ($data == '{"errmsg":"","retcode":0}'."\n"){
Heartbeats();
return;
}
$json = json_decode($data,true);
$poll_type = $json['result'][0]['poll_type'];
switch ($poll_type){
case 'message':
$_content = $json['result'][0]['value']['content'];
unset($_content[0]);
$content = convert_multi_array($_content);
$from_uin=$json['result'][0]['value']['from_uin'];
post(ROOT_URL.'WebQQ.php',json_encode(array('type' => 0, 'uin' => $from_uin, 'msg' => $content)));
echo json_encode(array('type' => 0, 'uin' => $from_uin, 'msg' => $content));
Heartbeats();
break;
case 'group_message':
$_content=$json['result'][0]['value']['content'];
unset($_content[0]);
$content=convert_multi_array($_content);
$from_uin=$json['result'][0]['value']['from_uin'];
post(ROOT_URL.'WebQQ.php',json_encode(array('type' => 0, 'uin' => $from_uin, 'msg' => $content)));
echo json_encode(array('type' => 1, 'uin' => $from_uin, 'msg' => $content));
Heartbeats();
break;
default:
Heartbeats();
break;
}
}
function convert_multi_array($array) {
$out = implode(array_map(function($a) {if (is_array($a)){return '';} return $a;},$array));//ignore old qq emoticon...
return $out;
}
Heartbeats();
?>

13
classes/WebQQ/init.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$BOT = new Base;
$GET = json_decode(file_get_contents("php://input"),true);
//is group?
if ($GET['type'] = 0) {
$isgroup = false;
}else{
$isgroup = true;
}
$from = $GET['uin'];
$text = $GET['msg'];

View File

@ -5,6 +5,7 @@ define('OWNER_NAME', 'YOUR_NAME');
define('BOT_NAME', 'D_bot'); //Now For Telegram-Bot Only define('BOT_NAME', 'D_bot'); //Now For Telegram-Bot Only
define('HELP_BEGIN', "The_Sentence_Before_Help_Command"); define('HELP_BEGIN', "The_Sentence_Before_Help_Command");
define('HELP_END', "The_Sentence_After_Help_Command"); define('HELP_END', "The_Sentence_After_Help_Command");
define('ROOT_URL', "THE_URL_TO_THIS_PATH");
$TAGs = array('\'','#','/','!'); //array for commands $TAGs = array('\'','#','/','!'); //array for commands
@ -15,6 +16,9 @@ define('TB_API_URL', 'https://api.telegram.org/bot'.TB_TOKEN.'/'); //DO NOT CHAN
//For Wechat-MP //For Wechat-MP
define('WC_UserName', 'YOUR_WECHAT_USERNAME_HERE'); define('WC_UserName', 'YOUR_WECHAT_USERNAME_HERE');
//For WebQQ
define('WQ_Cookie', 'YOUR_WEBQQ_COOKIE_HERE');
//For plugins //For plugins
define('PLUGIN_GITHUB_TOKEN', 'YOUR_GITHUB_TOKEN_HERE'); define('PLUGIN_GITHUB_TOKEN', 'YOUR_GITHUB_TOKEN_HERE');
define('PLUGIN_STEAM_KEY', 'YOUR_STEAM_KEY_HERE'); define('PLUGIN_STEAM_KEY', 'YOUR_STEAM_KEY_HERE');