<?php

单纯设置了IP段,可以使用以下代码

$dingArray['msgtype'] = 'link';
$dingArray['link']['title'] = '标题';
$dingArray['link']['text'] = '内容';
$dingArray['link']['messageUrl'] = 'http://www.baidu.com';
$dingArray['link']['picUrl'] = 'http://www.baidu.com/avatar.jpg';
$ding_send_content = json_encode($dingArray);
$dingReturn = dingtalk_by_curl($ding_send_content, $config['dingtalk']['remote_server']);

function dingtalk_by_curl($post_string,$remote_server) {
if(empty($remote_server)){
return false;
}

$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证书验证, 未调通情况可尝试添加该代码
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;

 

至于加签的代码生成

list($s1, $s2) = explode(' ', microtime());

$timestamp = (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);

$secret = 'xxxxx';

$data = $timestamp . "\n" . $secret;

$signStr = base64_encode(hash_hmac('sha256', $data, $secret,true));

$signStr = utf8_encode(urlencode($signStr));

$webhook = "https://oapi.dingtalk.com/robot/send?access_token=xxxxx";

$webhook .= "&timestamp=$timestamp&sign=$signStr";

}

?>