自定义发布接口

总共需要实现5个接口

连接接口

编辑或添加采集规则-发布设置-管理连接站点-添加,弹出连接窗口:

程序类型,选择“自定义”,网站地址,请填写接口的地址,比如这个例子中,填写的是http://127.0.0.1/dxc_api_demo/api.php,
软件会向这个指定的url发送post数据。
发送两个字段
action 动作类型,程序可以根据这个,判断请求的接口。

action 说明
api_info 连接接口
category_list 栏目数据接口
field_data 字段接口
attach_upload 文件上传接口
post_data 发布数据接口

api_key 连接密钥。用于校验身份

接口如何实现?

例子里面,初始化的完整代码如下:

global $ori_api_key;

$sdk = new dxcsdk();
$sdk->charset = 'utf-8';//编码 gbk 或 utf-8
$action = $_POST['action'];
$api_key = $_POST['api_key'];

//debug
//$action = 'category_list';
//$api_key = 'asdfksdak';

//这里做一些判断
if(empty($action) || empty($api_key)) return;

$allow_actions = array('api_info', 'category_list',  'field_data', 'post_data', 'attach_upload');
if(!in_array($action, $allow_actions)) return;


$result_data = array('status' => 0, 'msg'=> 'ok', 'data' => array());


ob_clean();
ob_end_flush();

//每次需要检测密钥是否正确
if($ori_api_key != $api_key){
    $result_data['status'] = -1;
    $result_data['msg'] = '密钥错误';
    echo $sdk->json_encode($result_data);
    exit();
}


echo $sdk->json_encode($this->$action());
exit();

1、每次需要先校验密钥
2、初始化sdk时,需要指定编码
3、使用$sdk->json_encode($result_data)来输出json数据。

下面来完善各个接口。

连接接口

function api_info(){

    $result_data = array('status' => 0, 'msg'=> 'ok', 'data' => array());

    $system['cms_type'] = '自定义网站';//cms类型 比如discuz、wordpress、phpwind等等。如果是自定义,可选
    $system['cms_vertion'] = '1.0.0';//版本号,可选
    $system['api_version'] = '1.0.0';//接口的版本,可选
    $system['charset'] = 'utf-8';//编码,必填。
    $result_data['data'] = $system;
    return $result_data;
}
Copyright © DXC采集 2016 all right reserved,powered by Gitbook该文件修订时间: 2017-02-12 12:25:47

results matching ""

    No results matching ""