/**
*
* @param array $data
* @param string
m
s
g
t
y
p
e
t
e
x
t
l
i
n
k
m
a
r
k
d
o
w
n
a
c
t
i
o
n
C
a
r
d
∗
@
r
e
t
u
r
n
b
o
o
l
e
a
n
∗
/
p
u
b
l
i
c
f
u
n
c
t
i
o
n
r
o
b
o
t
S
e
n
d
(
msgtype text link markdown actionCard * @return boolean */ public function robotSend(
msgtypetextlinkmarkdownactionCard∗@returnboolean∗/publicfunctionrobotSend(data ) {
// $data = ‘[’ . $this->code . '] ErrorException in ’ . Request::url() . ’ errorCode ’ . $this->errorCode . PHP_EOL . $this->msg;
$data = array ('msgtype' => 'text','text' => array ('content' => $data));
$data_string = json_encode($data);
$result = $this->request_by_curl($data_string);
return $result;
}
function request_by_curl( $post_string) {
$url = $this->API_URL;
$time = time() *1000;
$secret=‘钉钉机器人中的安全标签’
$sign = hash_hmac('sha256', $time . "\n" . $secret,$secret,true);
$sign = base64_encode($sign);
$sign = urlencode($sign);
$url = "{$url}×tamp={$time}&sign={$sign}";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
此处secret为钉钉机器人中的安全标签,一定要加上 否则会报错 说什么签名不匹配
{
“errcode”:310000,
“errmsg”:“sign not match”
}