个人钉钉使用群机器人API实现WordPress评论消息通知代码

实现WordPress新评论消息钉钉机器人消息通知,
首先你要有一个钉钉号,再创建一个普通群,群内选择一个自定义机器人,并且获得机器人的webhook和加签秘钥

个人钉钉使用群机器人API实现WordPress评论消息通知代码
function request_by_curl($remote_server, $post_string) {  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, $remote_server);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json;charset=utf-8'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $data = curl_exec($ch);
    curl_close($ch);                
    return $data;  
}
function boxmoe_msg_comment($comment_id){
    $comment = get_comment($comment_id);
    $siteurl = get_bloginfo('url');
    $text = '文章《' . get_the_title($comment->comment_post_ID) . '》有新的评论!';
    $message = $text . "\n" . "作者: $comment->comment_author \n邮箱: $comment->comment_author_email \n评论: $comment->comment_content \n 点击查看:$siteurl/?p=$comment->comment_post_ID#comments";
			$time    = intval(microtime(true) * 1000);
			$secret  = '机器人加签秘钥';
			$sign    = urlencode(base64_encode(hash_hmac('sha256', "{$time}\n{$secret}", $secret, true)));
			$apiurl	 = 'https://oapi.dingtalk.com/robot/send?access_token=你的webhook&timestamp='.$time.'&sign='.$sign.'';
			$data = array ('msgtype' => 'text','text' => array ('content' => $message));
			$data_string = json_encode($data);
			return $result = request_by_curl($apiurl, $data_string);  	
	}
add_action('comment_post', 'boxmoe_msg_comment', 19, 2);	 

FROM:https://www.boxmoe.com/

免责声明:
1.本站所有内容只做学习和交流使用。 版权归原作者所有。
2.保证站内提供的所有可下载源码资源(软件等)都是按“原样”提供,本站未做过任何改动;但本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。
3.本站部分内容均收集于网络!如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。请联系站长邮箱:admin#ibian.online(#换成@)处理!

给TA打赏
共{{data.count}}人
人已打赏
综合项

利用go-cqhttp搭建的qq机器人接入WordPress主题评论的时QQ消息通知

2025-2-14 15:48:48

综合项

离线更新1Panel及脱离面板进行更新的一个示例(1Panel-offline-update-and-terminal-mode-update)

2025-2-20 14:59:18

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索