最近在做項目的時候用到了暢言評論,因為是第三方評論,所以沒辦法直接入庫,但是暢言提供了評論回推接口,嘗試著制作了一下,廢話不多說,上代碼:
第一步:獲取暢言數據并轉為數組
$cy_data = htmlspecialchars_decode(I('data'));//獲取暢言返回數據,并轉碼
$data = json_decode($cy_data,true);//將JSON轉為數組第二步,根據自身業務需求完成后續操作
暢言返回的數組格式為:
Array
(
[comments] => Array
(
[0] => Array
(
[apptype] =>
[attachment] => Array()
[channelid] =>
[channeltype] => //1為評論框直接發表的評論,2為第三方回流的評論
[cmtid] => //評論唯一ID
[content] => //評論內容
[ctime] => //評論時間
[from] => //評論來源
[ip] => //發布ip
[opcount] => //評論被踩次數
[referid] =>
[replyid] => //回復的評論ID,沒有為0
[score] =>
[spcount] => //評論被頂次數
[status] =>
[user] => Array
(
[nickname] => //發布者昵稱
[sohuPlusId] =>
[usericon] => //發布者頭像(留空使用默認頭像)
[userid] => //發布者ID
[userurl] => //發布者主頁地址(可留空)
)
[useragent] => //瀏覽器信息
)
)
[metadata] => {"local_ip":"127.0.0.1"}
[sourceid] => //文章Id
[title] => //文章標題
[ttime] => //文章創建時間
[url] => //文章url
)完整的Json數據為:
{
"title":"123", //文章標題
"url":"http://localhost/?p=9", //文章url
"ttime":1401327899094, //文章創建時間
"sourceid":"9", //文章Id
"parentid":"0", //文章所屬專輯的ID,多個的話以,號分隔
"categoryid":"", //文章所屬頻道ID(可留空)
"ownerid":"", //文章發布者ID(可留空)
"metadata":"", //文章其他信息(可留空)
"comments":[
{
"cmtid":"358", //評論唯一ID
"ctime":1401327899094, //評論時間
"content":"2013年8月1日18:36:29 O(∩_∩)O~", //評論內容
"replyid":"0", //回復的評論ID,沒有為0
"user":{
"userid":"1", //發布者ID
"nickname":"admin", //發布者昵稱
"usericon":"", //發布者頭像(留空使用默認頭像)
"userurl":"", //發布者主頁地址(可留空)
"usermetadata":{ //其它用戶相關信息,例如性別,頭銜等數據
"area": "北京市",
"gender": "1",
"kk": "",
"level": 1
}
},
"ip":"127.0.0.1", //發布ip
"useragent":"Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0", //瀏覽器信息
"channeltype":"1", //1為評論框直接發表的評論,2為第三方回流的評論
"from":"", //評論來源
"spcount":"", //評論被頂次數
"opcount":"", //評論被踩次數
"attachment":[ //附件列表
{
"type":1, //1為圖片、2為語音、3為視頻
"desc":"", //描述,
"url":"http://img.sohu.itc/xxxx" //附件地址
}
]
}
]
}你可以參照以上字段進行下一步業務的處理!






