201 lines
6.4 KiB
PHP
201 lines
6.4 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Controller;
|
||
use think\Db;
|
||
use think\Log;
|
||
|
||
class Ceshi extends Controllers
|
||
{
|
||
//设置白名单ip访问本类接口
|
||
protected $allowIp = [
|
||
'113.201.181.82'
|
||
];
|
||
|
||
//发送群组系统消息
|
||
public function send_group_system_notification()
|
||
{
|
||
$rid = input('rid', '');//群组id 拼接好的id,avchartroom +room,public+g
|
||
$content = input('content', '');
|
||
$type = input('type', 1005);
|
||
if(!$content){
|
||
$FromUserInfo = db::name('user')->where('id',10)->field('id as user_id,nickname,avatar,sex')->find();
|
||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon(10);//财富图标
|
||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon(10);//魅力图标
|
||
$ToUserInfo = Db::name('user')->where(['id' => 51])->field('id as user_id,nickname,avatar,sex')->find();
|
||
$ToUserInfo['icon'][0] = model('UserData')->user_wealth_icon(51);//财富图标
|
||
$ToUserInfo['icon'][1] = model('UserData')->user_charm_icon(51);//魅力图标
|
||
$gift_info = Db::name('vs_gift')->where(['gid'=>4])->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type')->find();
|
||
$text = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 礼物 ' .$gift_info['gift_name'].' x 2';
|
||
$content = [
|
||
'FromUserInfo' => $FromUserInfo,
|
||
'ToUserInfo' => $ToUserInfo,
|
||
'GiftInfo' => $gift_info,
|
||
'GiftNum' => 2,
|
||
'text' => $text
|
||
];
|
||
}
|
||
|
||
//获取群组id里面的纯数字
|
||
$roomId = preg_replace('/[^0-9]/', '', $rid);
|
||
$text = [
|
||
'MsgType' => $type,
|
||
'RoomId' => $roomId,
|
||
'Text' => $content
|
||
];
|
||
//发送群组系统消息
|
||
$reslut = model('Tencent')->send_group_system_notification($rid, json_encode($text));
|
||
//邀请成员
|
||
// $reslut = model('Tencent')->add_group_member('g32', '10');
|
||
//向所有直播群发送消息
|
||
// $reslut = model('Tencent')->send_broadcast_msg('【请注意!!! 该直播间已经起飞!!!请系好安全带。】');
|
||
|
||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||
|
||
|
||
//发送群组消息
|
||
// $reslut = model('Tencent')->send_group_msg('room28', '大家好 我是系统消息。由 可爱的空气 下发的!','u10');
|
||
|
||
//发送单聊消息(可以模拟系统发送 发送者昵称设置为:系统)
|
||
// $reslut = model('Tencent')->user_sendmsg('10', '51', '你已违反本平台的协议,账号已被封禁!');
|
||
// return V(1, '发送成功!', $reslut);
|
||
}
|
||
|
||
//向所有直播群发送消息 要加钱(企业或者旗舰)
|
||
public function send_broadcast_msg()
|
||
{
|
||
$content = input('content', '');
|
||
if (!$content) {
|
||
$content = '【请注意!!! 该直播间已经起飞!!!请系好安全带。】';
|
||
}
|
||
//向所有直播群发送消息
|
||
$reslut = model('Tencent')->send_broadcast_msg($content);
|
||
|
||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||
}
|
||
|
||
//邀请成员
|
||
public function add_group_member()
|
||
{
|
||
$rid = input('rid', '');//群组id 拼接好的id,avchartroom +room,public+g
|
||
if(!$rid){
|
||
$rid = 'g32';
|
||
}
|
||
$uid = input('uid', '');
|
||
if(!$uid){
|
||
$uid = '10';
|
||
}
|
||
$reslut = model('Tencent')->add_group_member($rid, $uid);
|
||
|
||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||
}
|
||
|
||
//发送群组消息
|
||
public function send_group_msg()
|
||
{
|
||
$rid = input('rid', '');//群组id 拼接好的id,avchartroom +room,public+g
|
||
if(!$rid){
|
||
$rid = 'room28';
|
||
}
|
||
$uid = input('user_id', '');
|
||
if($uid){
|
||
$uid = 'u'.$uid;
|
||
}
|
||
$content = input('content', '');
|
||
if (!$content) {
|
||
$content = '大家好 我是系统消息。由 可爱的空气 下发的!';
|
||
}
|
||
//发送群组消息
|
||
$reslut = model('Tencent')->send_group_msg($rid, $content,$uid);
|
||
|
||
return V(1, '发送成功!', $reslut);
|
||
}
|
||
|
||
//发送单聊消息
|
||
public function user_sendmsg()
|
||
{
|
||
$uid = input('uid', '');
|
||
if(!$uid){
|
||
$uid = '10';
|
||
}
|
||
$receive_uid = input('receive_uid', '');
|
||
if(!$receive_uid){
|
||
$receive_uid = '51';
|
||
}
|
||
$content = input('content', '');
|
||
if (!$content) {
|
||
$content = '你已违反本平台的协议,账号已被封禁!';
|
||
}
|
||
//发送单聊消息(可以模拟系统发送 发送者昵称设置为:系统)
|
||
$reslut = model('Tencent')->user_sendmsg($uid, $receive_uid, $content);
|
||
return V(1, '发送成功!', $reslut);
|
||
}
|
||
|
||
//获取token
|
||
public function get_token()
|
||
{
|
||
$reslut = model('user_token')->where('token','<>', 1)
|
||
->field('token,user_id,expiretime')->order('id' , 'desc')->select();
|
||
if ($reslut) {
|
||
foreach ($reslut as &$res){
|
||
$res['expiretime'] = date('Y-m-d H:i:s', $res['expiretime']);
|
||
$res['nickname'] = model('user')->where('id', $res['user_id'])->value('nickname');
|
||
}
|
||
|
||
}
|
||
return V(1, '成功', $reslut);
|
||
}
|
||
|
||
|
||
//测试富文本消息
|
||
public function test_rich_text(){
|
||
$contene = $_POST['contene'];
|
||
var_dump($contene);
|
||
}
|
||
|
||
|
||
//测试声网token 过期
|
||
public function test_agora_token(){
|
||
$token = input('token','');
|
||
if(empty($token)){
|
||
$token = request()->header('token');
|
||
}
|
||
Log::record("声网过期了请求更新".json_encode($token),"infos");
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
//测试异步信息
|
||
public function test_async_info(){
|
||
// 创建子进程
|
||
$pid = pcntl_fork();
|
||
|
||
if ($pid == -1) {
|
||
die('无法创建子进程');
|
||
} elseif ($pid) {
|
||
// 父进程
|
||
echo "父进程继续执行\n";
|
||
// 父进程不等待子进程
|
||
} else {
|
||
// 子进程
|
||
sleep(5);
|
||
Log::record("子进程:5秒后执行".json_encode($pid),"infoss");
|
||
echo "子进程:5秒后执行\n";
|
||
exit(0); // 子进程结束
|
||
}
|
||
|
||
echo "父进程继续执行其他代码\n";
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |