forked from MrZhang1899/WxWork_Push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
57 lines (52 loc) · 1.67 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
//判断变量是否存在
if (isset($_GET['type'])) {
$file = $_GET['type'];
include('./' . $file . '.php');
}
//此处配置你的信息
$corpid = "ww16b1a2963d3148ea";
$secret = "GVRSqmlyRSQ4tb-BdfBDou_Mg7msXBUts3XnBZWu6WU";
$agentid = 1000002;
//获取access_token
$url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' . $corpid . '&corpsecret=' . $secret;
$token = https_request($url);
$access_token = $token['access_token'];
//配置消息通知参数
if (isset($_GET['msg'])) {
$content = $_GET['msg'];
}
// 文本格式
$data = [
'touser' => '@all',
'msgtype' => 'text',
'agentid' => $agentid,
'text' => [
'content' => $content
]
];
$messageUrl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' . $access_token;
$message = https_request($messageUrl, 'post', $data);
echo json_encode($message);
// CURL
function https_request($url, $format = 'get', $data = null)
{
$headerArray = array("Content-type:application/json;", "Accept:application/json");
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if ($format == 'post') {
curl_setopt($curl, CURLOPT_POST, 1);
if ($data) {
$data = json_encode($data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
$data = json_decode(curl_exec($curl), true);
// $data=curl_exec($curl);
curl_close($curl);
return $data;
}