通过掌上论坛的回帖不触发钩子函数
我写了一个很简单的钩子函数<br /><br /><ol><li><?php<br /><li><br /><li>if (!defined('IN_DISCUZ')) {<br /><li><br /><li> exit('Access Denied');<br /><li>}<br /><li><br /><li>function sendPostRequest($url,$jsonData){<br /><li><br /><li> $curl = curl_init($url);<br /><li> curl_setopt($curl, CURLOPT_HEADER, false);<br /><li> curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);<br /><li> curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));<br /><li> curl_setopt($curl, CURLOPT_POST, true);<br /><li> curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($jsonData));<br /><li> // set a very low timeout to avoid blocking<br /><li> curl_exec($curl);<br /><li> curl_close($curl);<br /><li>}<br /><li><br /><li>class plugin_dhpush {}<br /><li><br /><li><br /><li><br /><li><br /><li>class plugin_dhpush_forum extends plugin_dhpush<br /><li>{<br /><li><br /><li> function __construct()<br /><li> { //全局函数定义<br /><li> global $_G;<br /><li> $config = $_G['cache']['plugin']['dhpush'];<br /><li> $this->groupid = $_G['groupid'];<br /><li> $this->allowPushGroupIds = unserialize($config["allowPushGroups"]);<br /><li> $this->pushToken = $config["pushToken"];<br /><li> }<br /><li><br /><li> function post_reply_output($params)<br /><li> {<br /><li> global $_G;<br /><li> $DEBUG = true;<br /><li> $SEND_URL_PREFIX = "https://dhpushservice.kidozh.com/";<br /><li> $SEND_URL_PATH = "v1/push/reply/";<br /><li> if ($DEBUG) {<br /><li> $SEND_URL_PREFIX = "http://localhost:8888/";<br /><li><br /><li> }<br /><li><br /><li> $SEND_URL = $SEND_URL_PREFIX.$SEND_URL_PATH;<br /><li><br /><li> error_log(print_r($params, TRUE));<br /><li> // check with post reply succeed<br /><li> if ($params["message"] != "post_reply_succeed") {<br /><li> return;<br /><li> }<br /><li> $fid = $params['values']['fid'];<br /><li> $tid = $params['values']['tid'];<br /><li> $pid = $params['values']['pid'];<br /><li><br /><li><br /><li> $mForumPost = C::t("forum_post");<br /><li> $post = $mForumPost->fetch($tid, $pid);<br /><li> $senderUid = $post["authorid"];<br /><li> $senderName = $post["author"];<br /><li> $replyMessage = $post["message"];<br /><li><br /><li> $mForumThread = C::t('forum_thread');<br /><li><br /><li> $thread = $mForumThread->fetch($tid);<br /><li> //主题作者ID<br /><li> $authorId = $thread['authorid'];<br /><li> $userResult = DB::fetch_first("SELECT groupid FROM " . DB::table("common_member") . " WHERE uid=" . $authorId);<br /><li> $receiverGroupId = $userResult["groupid"];<br /><li> //判断作者是否开启回贴通知<br /><li> //$mForumPostNotice = C::t('#post_notice#forum_post_notice');<br /><li> //$isNotice = $mForumPostNotice->getNoticeState($authorId);<br /><li> // allow notify<br /><li> if (true) {<br /><li> $mCommonMember = C::t('common_member');<br /><li> $author = $mCommonMember->fetch($authorId);<br /><li>// $email = $author['email'];<br /><li> $title = $senderName . '回复了帖子' . $thread["subject"];<br /><li> $siteURL = $_G["siteurl"];<br /><li> // check whether group id is not null and in the allowed group<br /><li> if ($receiverGroupId && in_array($receiverGroupId, $this->allowPushGroupIds)) {<br /><li> // look in the table whether the user in the push database<br /><li> $pushInfo = DB::fetch_first("SELECT uid, token, allowPush FROM " . DB::table("dhpush_token") . " WHERE uid=" . $authorId);<br /><li> // start to push the information to device via firebase<br /><li> $token = $pushInfo["token"];<br /><li> $deviceToken = $token;<br /><li> $data = [<br /><li> // belong to a reply<br /><li> "site_url" => $siteURL,<br /><li> "type" => "thread_reply",<br /><li> "sender_name" => $senderName,<br /><li> "sender_id" => $senderUid,<br /><li> "message" => $replyMessage,<br /><li> "title" => $title,<br /><li> "tid" => $tid,<br /><li> "pid" => $pid,<br /><li> "fid" => $fid,<br /><li> "tokenList"=> $deviceToken<br /><li><br /><li> ];<br /><li><br /><li> $SEND_URL_WITH_PARAMTER = $SEND_URL."?token=".$this->pushToken;<br /><li><br /><li> sendPostRequest($SEND_URL_WITH_PARAMTER,$data);<br /><li> error_log(print_r($data, TRUE));<br /><li> error_log(print_r($SEND_URL, TRUE));<br /><li><br /><li> } else {<br /><li> // the user are not able to get a push<br /><li> }<br /><li> } else {<br /><li> // not to send a information<br /><li><br /><li> }<br /><li> }<br /><li>}<br /><li><br /><li>// function post_message($params)<br /><li>// {<br /><li>// return;<br /><li>// //file_put_contents('php://stderr', print_r($params, TRUE));<br /><li>// error_log(print_r($params, TRUE));<br /><li>// global $_G;<br /><li>// $fid = $params['param']['fid'];<br /><li>// $tid = $params['param']['tid'];<br /><li>// $pid = $params['param']['pid'];<br /><li>//<br /><li>// $action=$params['param'];<br /><li>// if($action=='post_newthread_succeed'){//newthread<br /><li>// //TODO For newthread<br /><li>// }<br /><li>// elseif($action=='post_reply_succeed'){//new reply<br /><li>// return;<br /><li>// $senderName = $_G["username"];<br /><li>// $senderUid = $_G["uid"];<br /><li>//<br /><li>// $mForumThread = C::t('forum_thread');<br /><li>// //$tid = $params['values']['tid'];<br /><li>// $thread = $mForumThread->fetch($tid);<br /><li>// //主题作者ID<br /><li>// $authorId = $thread['authorid'];<br /><li>// $userResult = DB::fetch_first("SELECT groupid FROM " . DB::table("common_member") . " WHERE uid=" . $authorId);<br /><li>// $receiverGroupId = $userResult["groupid"];<br /><li>// //判断作者是否开启回贴通知<br /><li>// //$mForumPostNotice = C::t('#post_notice#forum_post_notice');<br /><li>// //$isNotice = $mForumPostNotice->getNoticeState($authorId);<br /><li>// // allow notify<br /><li>// if (true) {<br /><li>// $mCommonMember = C::t('common_member');<br /><li>// $author = $mCommonMember->fetch($authorId);<br /><li>// $email = $author['email'];<br /><li>// $subject = '您的贴子有回复了!';<br /><li>// $body = $author['username'] . "\n";<br /><li>// $body .= "您的主题:" . $thread['subject'] . "有回复了!\n";<br /><li>// $body .= "复制链接查看:" . $_G['siteurl'] . "forum.php?mod=viewthread&tid=" . $tid . "\n";<br /><li>//<br /><li>// $replyMessage = $body;<br /><li>// // check whether group id is not null and in the allowed group<br /><li>// if ($receiverGroupId && in_array($receiverGroupId, $this->allowPushGroupIds)) {<br /><li>// // look in the table whether the user in the push database<br /><li>// $pushInfo = DB::fetch_first("SELECT uid, token, allowPush FROM ".DB::table("dhpush_token")." WHERE uid=" . $authorId);<br /><li>// // start to push the information to device via firebase<br /><li>// $token = $pushInfo["token"];<br /><li>// $deviceToken = $token;<br /><li>// $data = [<br /><li>// // belong to a reply<br /><li>// "type" => "thread_reply",<br /><li>// "sender_name" => $author['username'],<br /><li>// "sender_id" => $senderUid,<br /><li>// "message" => $replyMessage,<br /><li>//<br /><li>// ];<br /><li>// sendPostRequest($SEND_URL,$data);<br /><li>// error_log(print_r($data, TRUE));<br /><li>//<br /><li>// } else {<br /><li>// // the user are not able to get a push<br /><li>// }<br /><li>// }<br /><li>//<br /><li>// }<br /><li>//<br /><li>// if ($params['message'] != 'post_reply_succeed') {<br /><li>// }<br /><li>//<br /><li>// }<br /><li><br /><li></ol>这个可以在每次回帖的时候正常的回调,但是我通过掌上论坛API调用的时候却并不触发这个钩子函数,我想问问是什么原因,需要做哪些事情才能让通过掌上论坛API发帖的时间被正确的通过钩子函数回调?<br />子函数<em>, </em>通过<em>, </em>掌上<em>, </em>论坛<em>, </em>这个 试试改成 post_message 嵌入点呢?这个嵌入点应该是不依赖前端的,不过 $params["message"] != "post_reply_succeed" 估计得改。 <br />似乎这个也触发不了。。。刚刚试了一下。。。 <br />$params["message"] != "post_reply_succeed" 去掉也不行么?<br /> <br />我试了 没有办法通过掌上论坛API触发,网页端都是可以的 <br />我回复被吞了,我试了一下 是不行的 我嵌入了移动端也不行。。。
頁:
[1]