81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?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,//频道 ID,app 内唯一,字符串
|
||
"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);
|
||
}
|
||
}
|
||
}
|