# 资讯推荐SDK文档
# PHP SDK简介
此 SDK 包含了如下几个功能:
提供”推荐“等各个频道列表数据。
获取资讯详情。详情内容里面的图片,音、视频。
获取资讯详情页下面出相关推荐列表。
第三方客户上报用户在端上的行为。
# 注意事项
1、请求接口如果超时,可重新调用两次,当调用两次后,还未成功拿到数据,则从已存文件中拿取数据。
2、该接口需要可写权限
# PHP SDK下载
# 接口介绍
# 推荐列表接口
# 接口说明
方法: GET
参数说明
参数名 | 参数说明 | 是否必须 | 备注 |
---|---|---|---|
app_id | 每个客户会赋予一个唯一的app_id | 是 | |
user_id | 用户唯一标识 | 是 | |
name | 客户在犀光配置平台(神灯)上配置的频道名称 | 是 | 一定要先配置频道才能获取列表数据 |
size | 拉取的数据条数 | 是 | 最大30, 建议10以下 |
log_id | 每次请求的标识 | 是 | 主要用来定位问题,可以用随机字符串 |
res_type | 资讯类型 | 否 | 如果只要图文就news, 只要视频就video, 只要音频就audio; 如果想都要,不加此参数 |
loc_province | 用户所在省份 | 否 | 如果希望推荐结果中有本地资讯,需要带此参数。直辖市的话,本字段空 |
loc_city | 用户所在城市 | 否 | 如果希望推荐结果中有本地资讯,需要带此参数。直辖市也用此地段 |
- 成功返回值: Json结构
{
"errno": 0, // 0标识成功
"log_id": "33434", // 用户请求时带的log_id
"message": "ok", // 成功
"data": {
"count": 10, // 如果没有数据, count = 0
"data": [
{
"id": "20181113122959127941", // 资讯在犀光系统内的id
"third_id": "34345", // 第三方客户的id,和第三方客户上报时用的third_id一致。
"news_title": "文章标题", // 文章标题
"news_source": "文章的来源", // 文章来源
"site_name": "站点", // 如果文章是抓取的,抓取站点
"org_url": "http://mini.eastday.com/xxxx.html", // 原始链接,如果是音视频,这里就是播放链接
"pub_time": 1542083399, // 资讯发布时间,unix时间戳,秒单位。
"smfw": {"10001": 1}, // 犀光小流量标识。注意,这里请把smfw原封不动放到用户行为上报数据里面。用户犀光做小流量试验
"author": "作者名", // 如果客户数据没有上次作者就空,
"category": "娱乐", // 资讯分类
"type": "news", // 资讯类型, news是图文, news_video是视频, news_audio是音频
"click_count": 10, // 点击数量,即阅读数
"comment_cout": 10, // 评论数, 如果评论不走犀光这边,这个值就是0
"down_count": 0, // 点踩数量
"up_count": 0, // 点赞数量
"duration": 0, // 音视频时长,对应图文类值是0
},
...
]
}
}
- 失败返回值: Json结构
{
"errno" : 8,
"log_id": "34343",
"message": "request parameter error",
"data": {
"count": 0,
"data": []
}
}
# 调用示例
public function recommend()
{
$curl = 'https://xiaojiding.com/HttpService/rec3';
$params = $this->get_val();
$string = http_build_query($params);
$once = 1;
$raw = $this->agin($curl, $string, $once, $params['res_type'], $params['size'], $params['log_id']);
$res = json_encode($raw, 320);
return $res;
}
# 获取详情的接口
# 接口说明
- 方法: GET
- 参数说明:
参数名 | 参数说明 | 是否必须 | 备注 |
---|---|---|---|
id | 资讯id | 是 | |
log_id | 每次请求的标识 | 否 | 主要用来定位问题,可以用随机字符串 |
- 成功返回:Json结构
{
"audio_url": "", // 如果是音频的话,该地址不空,音频播放地址
"author": "", // 作者
"cagetory": "娱乐", // 资讯分类
"content": [ // 详情内容
{
"data": " 日本:今起开征“出境税” 每人1000日元 ",
"type": "text" // 一段文本
},
{
"data": "http://qiniu2.xiguangtech.com/201901/1c78a43c12a1411584805cc6117ae9f0.jpg?imageView2/1/format/jpg",
"height": 0,
"type": "img", // 一段图片
"width": 0
}
],
"create_time": 1547176528510,
"duration": 0, // 音视频播放时长
"errmsg": "success",
"errno": 0,
"id": "20190111031528577404", // 资讯id
"news_source": "数字之道", // 抓取源
"news_title": "日本为办奥运开征出境税?每人需交63元2019有望创收31亿元", // 资讯标题
"org_url": "https://www.sohu.com/a/288177546_157078", // 原始链接
"pub_time": 1547204700, // 发布时间,秒单位
"site_name": "数字之道", // 站点名称
"sub_cagetory": "", // 子分类
"third_id": "",
"topic": "",
"type": 1 // 资讯类型, 1:图文; 3:视频; 5:音频; 9:图集
}
- 失败返回: Json结构
{
errno: 4113,
errmsg: "do not have data"
}
# 调用示例
public function get_detail()
{
$asp = new Asp();
$curl = 'https://xiaojiding.com/HttpService/get_news_detail2';
$get= $_GET;
$id = $get['id'];
if (count($get)>1){
$log_id = $get['log_id'];
$params = [
'id' => $id,
'log_id' => $log_id
];
}else{
$params = [
'id' => $id
];
}
$string = http_build_query($params);
$res = $asp->curl($curl,$string);
$raw = json_decode($res,true);
$res = json_encode($raw,320);
return $res;
}
# 相关推荐接口
# 接口说明
方法: GET
参数说明:
参数名 | 参数说明 | 是否必须 | 备注 |
---|---|---|---|
app_id | 每个客户会赋予一个唯一的app_id | 是 | |
third_id | 第三方资讯标识 | 是 | third_id和id必有其一 |
id | 犀光资讯内容标识 | 是 | third_id和id必有其一 |
size | 拉取的数据条数 | 是 | 建议10以下 |
log_id | 每次请求的标识 | 是 | 主要用来定位问题,可以用随机字符串 |
- 成功返回值: Json结构, 和推荐接口出去的数据格式一致。
{
"errno": 0, // 0标识成功
"errmsg": "success", // 错误信息
"count": 4, // 返回的条数
"data":[
{
"id": "2018111312333", // 如果是犀光的资讯内容
"third_id": "34343", // 如果是客户自己的资讯内容, id和third_id必有一个有值
"category": "生活", // 新闻分类
"org_url": "https://m.weibo.cn/xxx.html", // 原始网页地址,音视频的话,就是播放地址
"site_name": "微博", // 站点名
"pub_time": 1543434345000, // 发布时间,单位毫秒
"news_title": "新闻标题", // 标题
"news_source": "来源", // 新闻来源
"type": "news", // 新闻类型,图文news, 视频news_video, 音频news_audio
"author": "xxx", // 作者
"click_count": 3, // 阅读数
"up_count": 2 // 点赞数
}
]
}
- 失败返回值: Json结构
{
"errno" : -1,
"message": "request parameter error" // 错误信息
}
# 调用示例
public function related_recommend()
{
$url = 'https://xiaojiding.com/HttpService/rel';
$app_id = $_GET['app_id'];
$third_id = $_GET['third_id'];
$id = $_GET['id'];
$size = $_GET['size'];
$log_id = $_GET['log_id'];
$params = [
'app_id' => $app_id,
'third_id' => $third_id,
'id' => $id,
'size' => $size,
'log_id' => $log_id
];
$once = 1;
$raw = $this->agin($url, $params, $once);
$res = json_encode($raw, 320);
return $res;
}
# 用户行为上报接口
# 接口说明
方法:POST
请求包体 : Json结构
{
"log_id": "12234", // **必选**,每次请求时唯一标识,可以随机生成
"action_type": 1, // **必选**,1:展现; 2:点击; 3:播放完成; 4:播放中间跳过; 6:不喜欢; 7:点赞; 8:关注; 9:分享
"app_id": "default", // **必选**,分配给客户的唯一标识。和其它接口中app_id含义一致
"timestamp": 1543453452, // **必选**,用户行为发生的时间戳,秒单位
"cuid": "6F21FF3C3BC3799343077953E66", // **必选**,用户唯一标识
"smfw": {"1001":"1"}, // 可选,推荐接口出去的smfw字段,带到这里
"os": "ios", // 可选,android, ios
"cip": "1.24.81.170", // 可选,客户端ip
"data":[
{
"id":"20181113454545", // **必选**,id和third_id必选其一,如果是犀光内容,此字段必须有值。
"third_id":"343454", // **必选**,id和third_id必选其一,如果是客户提供的内容,此字段必须有值。
"rtype": "news", // **必选**,资讯类型,news:图文, video:视频, audio:音频
"delivery_time": 1543434343, // 可选, 下发时间
"log_id": "565656", // 可选,该资讯在请求推荐接口或频道接口时的请求log_id,用于定位问题
"show_time": 1545566666, // 可选, 在屏幕上展现时的时间戳,单位s
"duration": 30, // 可选,如果是音视频,播放时间,单位s
}
]
}
- 成功返回值: Json结构
{
"errno": 0,
"errmsg": ""
}
- 出错返回值: Json结构
{
"errno": -1,
"errmsg": "parameter error"
}
# 调用示例
public function user()
{
$url = 'https://xiaojiding.com/HttpService/ReceiveLog2';
$raw = file_get_contents('php://input');
parse_str($raw,$arr);
$data = $arr['data'];
$data = json_decode($data,true);
$arr['data'] = $data;
$action_type = (int)$arr['action_type'];
$timestamp = (int)$arr['timestamp'];
$arr['action_type'] = $action_type;
$arr['timestamp'] = $timestamp;
$json = json_encode($arr,320);
$asp = new Asp();
$res = $asp->json_post($url,$json);
return $res;
}