接入教程
1. 注册获取API密钥
2. 查阅文档了解端点
3. 构建搜索查询请求
4. 解析返回的JSON数据
5. 集成到您的应用中
使用Python进行语义搜索
python
import requests
url = "https://api.example.com/v1/search"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"query": "祈祷的重要性",
"collection": "hadith",
"limit": 5
}
response = requests.post(url, json=payload, headers=headers)
data = response.json()
print(data)
PHP集成示例
php
<?php
$url = 'https://api.example.com/v1/search';
$apiKey = 'YOUR_API_KEY';
$data = [
'query' => 'importance of prayer',
'collection' => 'quran',
'limit' => 3
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
print_r($result);
?>
JavaScript前端调用
javascript
const searchEndpoint = 'https://api.example.com/v1/search';
const apiKey = 'YOUR_API_KEY';
async function searchIslamicText(query, collection) {
const response = await fetch(searchEndpoint, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: query,
collection: collection,
limit:我们发现5
})
});
return await response.json();
}
// 使用示例
searchIslamicText('斋戒的好处', 'hadith')
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
常见问题
如何获取API密钥?
请访问Amanah Sunnah开发者网站(https://sunnah.amanahagent.cloud/developers)注册账户并申请API密钥。免费套餐提供有限的调用次数,适用于个人项目和小规模应用。
支持哪些数据源的搜索?
API支持《古兰经》全文、主要圣训集(布哈里、穆斯林等)、经注文献以及超过18,000名圣训传述者信息的语义搜索。您可以通过collection参数指定要搜索的数据源类型。
API是否有调用频率限制?
是的,根据不同的套餐等级设有调用频率限制。免费套餐通常每分钟限制60次调用,每日限制1,000次调用。具体限制请参考官方文档中的套餐说明。
Aitishiku.com