第一种:基于URL Restful API 接口的访问
查询数据
var now = Date.now();
var appKey = SHA1(" " + "UZ" + "268EC1C9-41DD-97BD-6F43- " + "UZ" + now) + "." + now;
var filter = {
fields: {
"id": true,
"title": true,
"videoPath": true
}
}
$.ajax({
"url": "https://d.apicloud.com/mcm/api/video?filter=" + encodeURIComponent(JSON.stringify(filter)),
"type": "GET",
"cache": false,
"headers": {
"X-APICloud-AppId": " ",
"X-APICloud-AppKey": appKey
}
}).done(function(data, status, header) {
//success body
alert(JSON.stringify(data));
}).fail(function(header, status, errorThrown) {
//fail body
alert(JSON.stringify(errorThrown));
})
提交数据
var now = Date.now();
var appKey = SHA1(" **" + "UZ" + "6DFD0059-2808-5828-E05A- ***F" + "UZ" + now) + "." + now;
$.ajax({
"url": "https://d.apicloud.com/mcm/api/Company",
"type": "POST",
"cache": false,
"headers": {
"X-APICloud-AppId": " **",
"X-APICloud-AppKey": appKey
},
"data": {
"name": "API Cloud",
"level": "Branch",
"area": "Haidian District"
}
}).done(function(data, status, header) {
alert(data);
//success body
}).fail(function(header, status, errorThrown) {
//fail body
alert(errorThrown);
})
第二种:基于mcm模块 model对象 query操作
var model = api.require('model');
model.config({
appKey: '6DFD0059-2808-5828-E05A- ****F',
host: 'https://d.apicloud.com'
});
var query = api.require('query');
query.createQuery(function(ret, err) {
if (ret) {
var queryId = ret.qid;
query.whereEqual({
qid: queryId,
column: 'name',
value: 'jiaocheng'
});
model.findAll({
class: "Company",
qid: queryId
}, function(ret, err) {
if (ret) {
for (var i = ret.length - 1; i >= 0; i--) {
alert(JSON.stringify(ret[i]));
}
} else {
alert(JSON.stringify(err));
}
});
} else {
alert(JSON.stringify(err));
}
});