返回列表 发帖
查看: 1386|回复: 5

通过掌上论坛的回帖不触发钩子函数

11

主题

29

回帖

45

积分

初学乍练

贡献
0 点
金币
2 个
发表于 2022-2-5 10:32:31 | 显示全部楼层 |阅读模式
我写了一个很简单的钩子函数

  1. <?php

  2. if (!defined('IN_DISCUZ')) {

  3.     exit('Access Denied');
  4. }

  5. function sendPostRequest($url,$jsonData){

  6.     $curl = curl_init($url);
  7.     curl_setopt($curl, CURLOPT_HEADER, false);
  8.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  9.     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
  10.     curl_setopt($curl, CURLOPT_POST, true);
  11.     curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($jsonData));
  12.     // set a very low timeout to avoid blocking
  13.     curl_exec($curl);
  14.     curl_close($curl);
  15. }

  16. class plugin_dhpush {}




  17. class plugin_dhpush_forum extends plugin_dhpush
  18. {

  19.     function __construct()
  20.     { //全局函数定义
  21.         global $_G;
  22.         $config = $_G['cache']['plugin']['dhpush'];
  23.         $this->groupid = $_G['groupid'];
  24.         $this->allowPushGroupIds = unserialize($config["allowPushGroups"]);
  25.         $this->pushToken = $config["pushToken"];
  26.     }

  27.     function post_reply_output($params)
  28.     {
  29.         global $_G;
  30.         $DEBUG = true;
  31.         $SEND_URL_PREFIX = "https://dhpushservice.kidozh.com/";
  32.         $SEND_URL_PATH = "v1/push/reply/";
  33.         if ($DEBUG) {
  34.             $SEND_URL_PREFIX = "http://localhost:8888/";

  35.         }

  36.         $SEND_URL = $SEND_URL_PREFIX.$SEND_URL_PATH;

  37.         error_log(print_r($params, TRUE));
  38.         // check with post reply succeed
  39.         if ($params["message"] != "post_reply_succeed") {
  40.             return;
  41.         }
  42.         $fid = $params['values']['fid'];
  43.         $tid = $params['values']['tid'];
  44.         $pid = $params['values']['pid'];


  45.         $mForumPost = C::t("forum_post");
  46.         $post = $mForumPost->fetch($tid, $pid);
  47.         $senderUid = $post["authorid"];
  48.         $senderName = $post["author"];
  49.         $replyMessage = $post["message"];

  50.         $mForumThread = C::t('forum_thread');

  51.         $thread = $mForumThread->fetch($tid);
  52.         //主题作者ID
  53.         $authorId = $thread['authorid'];
  54.         $userResult = DB::fetch_first("SELECT groupid FROM " . DB::table("common_member") . " WHERE uid=" . $authorId);
  55.         $receiverGroupId = $userResult["groupid"];
  56.         //判断作者是否开启回贴通知
  57.         //$mForumPostNotice = C::t('#post_notice#forum_post_notice');
  58.         //$isNotice = $mForumPostNotice->getNoticeState($authorId);
  59.         // allow notify
  60.         if (true) {
  61.             $mCommonMember = C::t('common_member');
  62.             $author = $mCommonMember->fetch($authorId);
  63. //            $email = $author['email'];
  64.             $title = $senderName . '回复了帖子' . $thread["subject"];
  65.             $siteURL = $_G["siteurl"];
  66.             // check whether group id is not null and in the allowed group
  67.             if ($receiverGroupId && in_array($receiverGroupId, $this->allowPushGroupIds)) {
  68.                 // look in the table whether the user in the push database
  69.                 $pushInfo = DB::fetch_first("SELECT uid, token, allowPush FROM " . DB::table("dhpush_token") . " WHERE uid=" . $authorId);
  70.                 // start to push the information to device via firebase
  71.                 $token = $pushInfo["token"];
  72.                 $deviceToken = $token;
  73.                 $data = [
  74.                     // belong to a reply
  75.                     "site_url" => $siteURL,
  76.                     "type" => "thread_reply",
  77.                     "sender_name" => $senderName,
  78.                     "sender_id" => $senderUid,
  79.                     "message" => $replyMessage,
  80.                     "title" => $title,
  81.                     "tid" => $tid,
  82.                     "pid" => $pid,
  83.                     "fid" => $fid,
  84.                     "tokenList"=> $deviceToken

  85.                 ];

  86.                 $SEND_URL_WITH_PARAMTER = $SEND_URL."?token=".$this->pushToken;

  87.                 sendPostRequest($SEND_URL_WITH_PARAMTER,$data);
  88.                 error_log(print_r($data, TRUE));
  89.                 error_log(print_r($SEND_URL, TRUE));

  90.             } else {
  91.                 // the user are not able to get a push
  92.             }
  93.         } else {
  94.             // not to send a information

  95.         }
  96.     }
  97. }

  98. //    function post_message($params)
  99. //    {
  100. //        return;
  101. //        //file_put_contents('php://stderr', print_r($params, TRUE));
  102. //        error_log(print_r($params, TRUE));
  103. //        global $_G;
  104. //        $fid = $params['param'][2]['fid'];
  105. //        $tid = $params['param'][2]['tid'];
  106. //        $pid = $params['param'][2]['pid'];
  107. //
  108. //        $action=$params['param'][0];
  109. //        if($action=='post_newthread_succeed'){//newthread
  110. //            //TODO For newthread
  111. //        }
  112. //        elseif($action=='post_reply_succeed'){//new reply
  113. //            return;
  114. //            $senderName = $_G["username"];
  115. //            $senderUid = $_G["uid"];
  116. //
  117. //            $mForumThread = C::t('forum_thread');
  118. //            //$tid = $params['values']['tid'];
  119. //            $thread = $mForumThread->fetch($tid);
  120. //            //主题作者ID
  121. //            $authorId = $thread['authorid'];
  122. //            $userResult = DB::fetch_first("SELECT groupid FROM " . DB::table("common_member") . " WHERE uid=" . $authorId);
  123. //            $receiverGroupId = $userResult["groupid"];
  124. //            //判断作者是否开启回贴通知
  125. //            //$mForumPostNotice = C::t('#post_notice#forum_post_notice');
  126. //            //$isNotice = $mForumPostNotice->getNoticeState($authorId);
  127. //            // allow notify
  128. //            if (true) {
  129. //                $mCommonMember = C::t('common_member');
  130. //                $author = $mCommonMember->fetch($authorId);
  131. //                $email = $author['email'];
  132. //                $subject = '您的贴子有回复了!';
  133. //                $body = $author['username'] . "\n";
  134. //                $body .= "您的主题:" . $thread['subject'] . "有回复了!\n";
  135. //                $body .= "复制链接查看:" . $_G['siteurl'] . "forum.php?mod=viewthread&tid=" . $tid . "\n";
  136. //
  137. //                $replyMessage = $body;
  138. //                // check whether group id is not null and in the allowed group
  139. //                if ($receiverGroupId && in_array($receiverGroupId, $this->allowPushGroupIds)) {
  140. //                    // look in the table whether the user in the push database
  141. //                    $pushInfo = DB::fetch_first("SELECT uid, token, allowPush FROM ".DB::table("dhpush_token")." WHERE uid=" . $authorId);
  142. //                    // start to push the information to device via firebase
  143. //                    $token = $pushInfo["token"];
  144. //                    $deviceToken = $token;
  145. //                    $data = [
  146. //                        // belong to a reply
  147. //                        "type" => "thread_reply",
  148. //                        "sender_name" => $author['username'],
  149. //                        "sender_id" => $senderUid,
  150. //                        "message" => $replyMessage,
  151. //
  152. //                    ];
  153. //                    sendPostRequest($SEND_URL,$data);
  154. //                    error_log(print_r($data, TRUE));
  155. //
  156. //                } else {
  157. //                    // the user are not able to get a push
  158. //                }
  159. //            }
  160. //
  161. //        }
  162. //
  163. //        if ($params['message'] != 'post_reply_succeed') {
  164. //        }
  165. //
  166. //    }

复制代码
这个可以在每次回帖的时候正常的回调,但是我通过掌上论坛API调用的时候却并不触发这个钩子函数,我想问问是什么原因,需要做哪些事情才能让通过掌上论坛API发帖的时间被正确的通过钩子函数回调?
回复

使用道具 举报

2

主题

1412

回帖

2043

积分

应用开发者

啦啦啦~

贡献
55 点
金币
320 个
发表于 2022-2-5 11:39:22 | 显示全部楼层
试试改成 post_message 嵌入点呢?这个嵌入点应该是不依赖前端的,不过 $params["message"] != "post_reply_succeed" 估计得改。
老周博客
本人不在任何渠道提供任何付费技术支持服务, 谨防上当受骗.
回复 支持 反对

使用道具 举报

11

主题

29

回帖

45

积分

初学乍练

贡献
0 点
金币
2 个
 楼主| 发表于 2022-2-5 22:59:22 | 显示全部楼层
老周部落 发表于 2022-2-5 11:39
试试改成 post_message 嵌入点呢?这个嵌入点应该是不依赖前端的,不过 $params["message"] != "post_reply ...

似乎这个也触发不了。。。刚刚试了一下。。。
回复 支持 反对

使用道具 举报

2

主题

1412

回帖

2043

积分

应用开发者

啦啦啦~

贡献
55 点
金币
320 个
发表于 2022-2-8 15:37:04 | 显示全部楼层
kidozh 发表于 2022-2-5 22:59
似乎这个也触发不了。。。刚刚试了一下。。。

$params["message"] != "post_reply_succeed" 去掉也不行么?
老周博客
本人不在任何渠道提供任何付费技术支持服务, 谨防上当受骗.
回复 支持 反对

使用道具 举报

11

主题

29

回帖

45

积分

初学乍练

贡献
0 点
金币
2 个
 楼主| 发表于 2022-2-10 04:06:41 | 显示全部楼层
老周部落 发表于 2022-2-8 15:37
$params["message"] != "post_reply_succeed" 去掉也不行么?

我试了 没有办法通过掌上论坛API触发,网页端都是可以的
回复 支持 反对

使用道具 举报

11

主题

29

回帖

45

积分

初学乍练

贡献
0 点
金币
2 个
 楼主| 发表于 2022-2-11 23:55:46 | 显示全部楼层
老周部落 发表于 2022-2-8 15:37
$params["message"] != "post_reply_succeed" 去掉也不行么?

我回复被吞了,我试了一下 是不行的 我嵌入了移动端也不行。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 关注公众号
  • 有偿服务微信
  • 有偿服务QQ

手机版|小黑屋|Discuz! 官方交流社区 ( 皖ICP备16010102号 |皖公网安备34010302002376号 )|网站地图|star

GMT+8, 2024-4-19 06:21 , Processed in 0.040626 second(s), 5 queries , Redis On.

Powered by Discuz! W1.0 Licensed

Cpoyright © 2001-2024 Discuz! Team.

关灯 在本版发帖
有偿服务QQ
有偿服务微信
返回顶部
快速回复 返回顶部 返回列表