marqueeNotice

This commit is contained in:
yangduo 2024-07-30 14:46:52 +08:00
parent 2cdf302d34
commit bd670ab483
3 changed files with 125 additions and 0 deletions

View File

@ -7,6 +7,7 @@ require_once('models/InGameMall.php');
require_once('services/MailApiService.php');
use phpcommon\SqlHelper;
use models\InGameMall;

View File

@ -0,0 +1,44 @@
<?php
require_once('services/NoticeService.php');
class UnitTestController extends BaseAuthedController {
public function _handlePre()
{
parent::_handlePre();
if (SERVER_ENV == _ONLINE) {
die("can't create UnitTestController");
return;
}
}
public function testNotice()
{
try {
$marqueeType= getReqVal('type', 1);
$loop = getReqVal('loop', 1);
$interval = getReqVal('interval', 10);
$contents= file_get_contents('php://input');
$postdata = json_decode($contents, true);
$content = '';
if ($marqueeType == 1) {
$elements = $postdata["elements"];
$content = services\NoticeService::buildCustom($elements);
} else if ($marqueeType == 2) {// deprecated
$langKey = $postdata["lang_key"];
$langParams = $postdata["lang_params"];
$content = services\NoticeService::buildMulLangTemplate($langKey, $langParams);
} else {
return;
}
services\NoticeService::send($content, $loop, $interval);
} catch (Exception $e){
error_log($e);
}
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace services;
use phpcommon;
class NoticeService extends BaseService {
const ELE_TYPE_RAW_TEXT = 1;
const ELE_TYPE_MUL_LANG = 2;
/*
{
"type": 1, //自定义
"elements":[
{
"ele_type": 1, //原始文本
"color": "#xxxxxxx" //[可选], 无则使用多语言里的颜色
"text": "" //如果是多语言则表示多语言配置表里的key
}
{
"ele_type": 2, //多语言(读取多语言表)
"color": "#xxxxxxx" //[可选], 无则使用多语言里的颜色
"lang_key": "",
"lang_params":[
}
]
}
*/
public static function buildCustom($elements)
{
$data = [
"type"=>1,
"elements"=> $elements,
];
return json_encode($data);
}
public static function send($content, $loop, $interval) {
$appkey = "YOUME1838B3633FF1410BDC9124BBD806F245B9D2E5AC";
$identifier="admin";
$appsecret="q6B570yTyj/00Nk4mYZtgDwyew5v05t13V1vo4mxpEuAaWUiinAyVxG41sNu3vsFe8sipOLfKfIVYGhzpQrqzvj5sId3mrBfj/s65a2gp36yDrI/nX5BnUAJB317SEosR6xLoPuhBvHU+/1DWI7nKSKaRNxnQiC46PJKFc2kX50BAAE=";
$data = [
"Notice"=>[
"ChannelID"=>"world_room_1",//频道 IDapp 内唯一,字符串
"NoticeType"=>1,//1 为跑马灯公告2 为聊天框公告3 为置顶公告,整数
"LoopType"=>1,// 公告循环类型1 为一次性公告2 为周期性公告,整数
"Title"=>"",// 公告标题,字符串
"Content"=>$content,//"testtttttt222",// 公告内容,字符串
"LinkKeyWords"=>"",// 链接关键字,字符串
"LinkAddr"=>"",// 链接地址,字符串
"Creator"=>"",// 公告添加人,字符串
"EnableStatus"=>2,// 公告启用状态1 为停用2 为启用,整数
"SendStartTime"=>"",// 公告发送时间,格式为 HH:MM:SS字符串
"SendInstantly"=>1,// 是否即时发送,也属于公告 json 里的字段。1 是0 否,不指定则不起作用
"SendTimes"=>$loop,// 公告发送次数,整数(需要传入)
"SendInterval"=>$interval,// 公告发送多次时,每次的间隔,单位秒,整数(需要传入)
]
];
$url = "https://sgapi.youme.im/v1/im/add_notice";
$curtime = time();
$params = array(
"appkey" => $appkey,
"identifier"=> $appkey,
"curtime"=> $curtime,
"checksum"=> strtolower(sha1($appsecret.$curtime)),
);
$response = '';
phpcommon\HttpClient::postContentEx($url, $params, json_encode($data), $response, ['Content-Type: application/json']);
if (SERVER_ENV != _ONLINE) {
error_log($response);
}
}
}