game2006api/webapp/services/NoticeService.php
aozhiwei 96a3836202 1
2024-08-20 11:06:56 +08:00

81 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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"=>NOTICE_CHANNEL_ID,//频道 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);
}
}
}