Thinkphp3.2 畅言评论回推接口制作

 331

最近在做项目的时候用到了畅言评论,因为是第三方评论,所以没办法直接入库,但是畅言提供了评论回推接口,尝试着制作了一下,废话不多说,上代码:

第一步:获取畅言数据并转为数组

$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"               //附件地址
                }
            ]
        }
    ]
}


你可以参照以上字段进行下一步业务的处理!



本文网址:https://www.98ks.vip/server-28.html
转载请声明来自:98k源码网 - Thinkphp3.2 畅言评论回推接口制作

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐