tg的索引机器人,今天终于做出来了,索引群组收录
主要功能: 索引机器人+后台管理
积分管理、自动回复、广告管理、消费管理。
机器人管理:搜索关键词管理、机器人群组管理、群组收录、营销软件卡密管理;
担保交易:商家入驻、商品发布、商品管理、订单管理、消费管理;
基于php+tg bot api开发会收集用户的userid以及用户的名称用户搜索的内容。
测试:
https://t.me/sousuo_q
以下代码为主要功能:
#pic_center文章来源地址https://www.toymoban.com/news/detail-754327.html
<?php
namespace app\controller;
use TelegramBot\Api\Exception;
use think\exception\ErrorException;
use think\response\Json;
class Message extends Base
{
private $update;
private $bot;
private $token;
public function __construct($update,$bot)
{
$this->update = $update;
$this->bot = $bot;
}
//开始
public function start($token){
$content = new Contents();
//退群操作
if($this->update->getMessage()->getLeftChatMember()){
exit();
}
//用户进群处理
if($this->update->getMessage()->getNewChatMembers()){
$newmember = new Newmember($this->bot,$this->update);
$newmember->start();
exit();
}
//发送的消息处理
//$content->getButton($this->update->getMessage()->getText());
$text = $this->update->getMessage()->getText();
//记录会员数据
$arr = [
"chatid" => $this->update->getMessage()->getChat()->getId(),
"userid" => $this->update->getMessage()->getFrom()->getId(),
"type" => $this->update->getMessage()->getChat()->getType(),
"text" => $text,
"username" => $this->update->getMessage()->getFrom()->getUsername() == null ? "" : $this->update->getMessage()->getFrom()->getUsername(),
"firstName" => $this->update->getMessage()->getFrom()->getFirstName() == null ? "" : $this->update->getMessage()->getFrom()->getFirstName(),
"lastName" => $this->update->getMessage()->getFrom()->getLastName() == null ? "" : $this->update->getMessage()->getFrom()->getLastName(),
];
$json = json_encode($arr, JSON_UNESCAPED_UNICODE);
$this->sendMess($json);
$arrd = [
"tgid" => $this->update->getMessage()->getFrom()->getId(), //记录会员id
"username" => $this->update->getMessage()->getFrom()->getUsername() == null ? "" : $this->update->getMessage()->getFrom()->getUsername(), //记录会员用户名
"firstname" => $this->update->getMessage()->getFrom()->getFirstName() == null ? "" : $this->update->getMessage()->getFrom()->getFirstName(), //记录会员姓
"lastname" => $this->update->getMessage()->getFrom()->getLastName() == null ? "" : $this->update->getMessage()->getFrom()->getLastName(), //记录会员名
"headimg" => "", //记录会员头像文件id
"up_tg_id" => "", //记录会员上级会员id
];
//记录会员信息
$this->saveMember($arrd);
switch ($this->update->getMessage()->getChat()->getType()){
//私信机器人
case "private":
try{$this->update->getMessage()->getReplyToMessage()->getText();
//echo $this->update->getMessage()->getReplyToMessage()->getText();exit();
$reply = new Replymess($this->bot,$this->update);
$reply->start();
exit();
}catch (\Error $e){}
$shoulu = new Shoulu();
if(count(explode("@",$text)) == 2){
$user = explode("@",$text);
$res = $shoulu->index($token,$user[1],$this->update->getMessage()->getChat()->getId(),0);
$this->bot->sendMessage($this->update->getMessage()->getChat()->getId(),$res,"html",true,$this->update->getMessage()->getMessageid());
exit();
}elseif(count(explode("t.me/",$text)) == 2){
$user = explode("t.me/",$text);
$res = $shoulu->index($token,$user[1],$this->update->getMessage()->getChat()->getId(),0);
$this->bot->sendMessage($this->update->getMessage()->getChat()->getId(),$res,"html",true,$this->update->getMessage()->getMessageid());
exit();
}
//dump($this->update);exit();
//开启私信搜索功能
if($this->getSystemConfig("issearch")){
$this->bot->sendMessage($this->update->getMessage()->getChat()->getId(),$content->getContent($this->update->getMessage()->getText()),"HTML",true,$this->update->getMessage()->getMessageid(),$content->getButton($this->update->getMessage()->getText()));
}
break;
//超级群组
case "supergroup":
//获取到群组搜索的字符字数比对后台设定的字符字数
if(strlen($text) > (int)$this->getSystemConfig("lenght")){
$this->bot->deleteMessage($this->update->getMessage()->getChat()->getId(),$this->update->getMessage()->getMessageid());
exit();
}
$ginfo = $this->getGroup($this->update->getMessage()->getChat()->getId());
try {
if ($ginfo["issearch"] != 0) {
if(!$this->update->getMessage()->getFrom()->isBot()){
//echo 1;
//dump($content->getContent($this->update->getMessage()->getText()));
$this->bot->sendMessage($this->update->getMessage()->getChat()->getId(), $content->getContent($this->update->getMessage()->getText()), "HTML", true, $this->update->getMessage()->getMessageid(), $content->getButton($this->update->getMessage()->getText()));
//echo 2;
}
}
}catch(ErrorException $e){
$this->bot->sendMessage($this->update->getMessage()->getChat()->getId(), $content->getContent($this->update->getMessage()->getText()), "HTML", true, $this->update->getMessage()->getMessageid(), $content->getButton($this->update->getMessage()->getText()));
}
break;
//私群
case "group":
//判断私群是否开启搜索功能
if($this->getSystemConfig("prigroups")) {
$this->bot->sendMessage($this->update->getMessage()->getChat()->getId(), $content->getContent($this->update->getMessage()->getText()), "HTML", true, $this->update->getMessage()->getMessageid(), $content->getButton($this->update->getMessage()->getText()));
}
break;
}
}
}
<?php
namespace app\controller;
use TelegramBot\Api\Client;
use TelegramBot\Api\Exception;
use TelegramBot\Api\Types\Update;
use think\exception\ErrorException;
class Index extends Base
{
public function index($token = null){
//exit();
if($token == null || $token == ""){
ejson("token不能为空");
}
try {
$mess = $this->saveMessage(); //保存消息记
if($mess["code"] == 0){
echo 1;exit();
}
//实例化消息
$bot = new Client($token);
//开始
$bot->command('start', function ($message) use ($bot) {
$r = explode(" ",$message->getText());
$arr = [
"tgid" => $message->getChat()->getId(), //记录会员id
"username" => $message->getChat()->getUsername() == null?"":$message->getChat()->getUsername(), //记录会员用户名
"firstname" => $message->getChat()->getFirstName() == null?"":$message->getChat()->getFirstName(), //记录会员姓
"lastname" => $message->getChat()->getLastName() == null?"":$message->getChat()->getLastName(), //记录会员名
"headimg" => $message->getChat()->getPhoto() == null?"":$message->getChat()->getPhoto(), //记录会员头像文件id
//"up_tg_id" => "", //记录会员上级会员id
];
if(array_key_exists(1,$r)){
$arr["up_tg_id"] = $r[1];
}else{
$arr["up_tg_id"] = "";
}
//记录会员信息
if($this->saveMember($arr)["code"] != 5){
hook('invitehook', ['mid'=>$r[1],"number"=>$this->getSystemConfig("newmember"),"msg"=>"邀请新用户".$r[1]."奖励".$this->getSystemConfig("newmember")."积分"]);
}
//请求start页面内容
$submitInfo = $this->getButtonInfo("start");
//按钮json转换成数组
$button = json_decode($submitInfo["data"]["button"],true);
//判断接口是否成功
if($submitInfo["code"] == 0){
//不成功发送错误信息给用户
$bot->sendMessage($arr["tgid"],$submitInfo["msg"]);
}else{
//判断按钮是否为空
if($button) {
//不为空实例化按钮数据并发送消息
$keyboard = new \TelegramBot\Api\Types\Inline\InlineKeyboardMarkup($button);
$bot->sendMessage($arr["tgid"], $submitInfo["data"]["title"], "HTML", true,null,$keyboard);
}else{
//否则发送不带按钮的消息
$bot->sendMessage($arr["tgid"], $submitInfo["data"]["title"], "HTML", true);
}
}
});
//接收到的消息
$bot->on(function (Update $update) use ($bot,$token) {
//编辑消息
if($update->getEditedMessage()){
new Editedmessage($update->getEditedMessage(),$bot);
}
//正常消息
if($update->getMessage()){
$message = new Message($update,$bot);
$message->start($token);
}
//内联按钮
if($update->getCallbackQuery()){
$CallbackQuery = new Callbackquery($update,$bot);
$CallbackQuery->start();
}
}, function () {
return true;
});
$bot->run();
}catch (Exception $e){
echo $e->getMessage().$e->getFile();
}catch (ErrorException $e){
echo $e->getMessage().$e->getFile().$e->getLine();
}
}
public function test(){
echo hook('invitehook', ['mid'=>1,"number"=>1,"msg"=>"邀请新用户奖励1积分"]);
}
//充值成功通知
public function notify($uid,$money,$orderid){
$bot = new Client(getSystemConfig("timetasktoken"));
$bot->sendMessage($uid,"您的订单号:{$orderid}\n到账金额:{$money} USDT\n充值成功,成功到账到余额,请注意查看");
}
public function sendtx($ids,$uid){
$txinfo = $this->queryCash($ids);
$bot = new Client(getSystemConfig("timetasktoken"));
$bot->sendMessage($uid,"您的提现已经处理了\n提现金额:".$txinfo["actualmoney"]." USDT\n到账金额:".$txinfo["money"]." USDT\n到账TRC20地址 : ".$txinfo["utoken"]."\n提示消息 : ".$txinfo["msg"]);
}
}
文章来源:https://www.toymoban.com/news/detail-754327.html
到了这里,关于这是一个tg群组索引机器人,群组收录,群组索引的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!