This repository has been archived by the owner on Sep 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
sc.php
67 lines (62 loc) · 1.64 KB
/
sc.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
58
59
60
61
62
63
64
65
66
67
<?php
//不是post直接返回
header('Content-Type: text/html;charset=utf-8');
if ($_SERVER["REQUEST_METHOD"] != "POST"){
die('<script>alert("别闹(。");location.href="./";</script>');
}
include_once('.key.php');
function sc_send($text , $desp = '' , $key = SCKEY){
$postdata = http_build_query(
array(
'text' => $text,
'desp' => $desp
)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
),
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false
)
);
$context = stream_context_create($opts);
return $result = file_get_contents('https://sc.ftqq.com/'.$key.'.send', false, $context);
}
function getIP() {
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else $ip = "Unknow";
return $ip;
}
header('Content-Type: application/json;charset=utf-8');
$text = "";
$contact = "";
$desp = "";
//获取post参数
if(isset($_POST["text"])){
$text = $_POST["text"];
}
if(empty($text)){
$json['errno']=1;
$json['errmsg']="消息标题不能为空啦";
die(json_encode($json));
}
if(isset($_POST["contact"])){
$contact = $_POST["contact"];
}
if(isset($_POST["desp"])){
$desp = $_POST["desp"];
}
if(!empty($contact)){
$desp .= " \n**Contact: " . $contact . "**";
}
$desp .= " \n**IP: " . getIP() . "**";
echo sc_send($text,$desp);