Hello, everyone! Today I will share with you a tool that pushes alarms and logs from the server to the mobile phone.

If you need to receive the running report of the server in time, if you are too bothered to install the client software. Then you can try this, call WEB API push message to your wechat; I thought it might be a good pose.

What is Server sauce?

“Server sauce”, English name “ServerChan”, is a communication software between “programmer” and “Server”.

People speaking?

It’s a tool that pushes alarms and logs from the server to the phone.

It only takes a minute to open and use:

  1. Login: Log in with your GitHub account and get an SCKEY (on the “Send messages” page);
  2. Binding: Click “wechat Push”, scan the code to follow and complete the binding;
  3. Send a message: send a GET request to sc.ftqq.com/SCKEY.send to receive a message on wechat

Working principle diagram of Server sauce

The technical requirements

  1. You need to have a GitHub account. You can’t have one.
  2. You need to have a wechat account. You can register one if you don’t have one.
  3. Need to pay attention to a public number, no can pay attention to.
  4. Need to be able to use Get requests in any language.

Operation process

1. Enter thewebsite, the use ofGitHubLogin by account. Start binding wechat. Is to use wechat scan (will ask you to pay attention to a public number), and then click on the interface < check results and confirm binding >;

After the binding is successful, it looks like this, with your Git account username at the bottom.

2. Obtain SendKey

3. First, let’s test whether it can be successfully sent

Enter the data you want to send under this online sending tool. Ermsg will prompt success if the message is sent successfully.

4. Open wechat to see the effect

Pay attention to this interface do not share casually, because there is your SCKEY in this link, if you do not want to suddenly receive other people puzzling message, it is better to read by yourself.

Several ways to send messages

** 1, just send a GET or POST request to the following URL:

https://sc.ftqq.com/SCU60273T00b04f5c49ff126aaf1bc345eb74b6c55e70925377668.send
Copy the code

Receives two parameters:

  1. Text: specifies the message title. The maximum value is 256. This parameter is mandatory.
  2. Desp: Message content, up to 64Kb, nullable, MarkDown supported.

2. The easiest way to send a message is through a browser. Enter the following URL in the address bar and press Enter to send the message:

https:/ / sc.ftqq.com/SCU60273T00b04f5c49ff126aaf1bc345eb74b6c55e70925377668.send?text= master server and hang up ~
Copy the code

3. In PHP, file_get_contents can be called directly:

file_get_contents('https://sc.ftqq.com/SCU60273T00b04f5c49ff126aaf1bc345eb74b6c55e70925377668.send?text='.urlencode('The master server is down again.'));
Copy the code

It can also be wrapped as a function:

function sc_send(  $text , $desp = ' ' , $key = 'SCU60273T00b04f5c49ff126aaf1bc345eb74b6c55e70925377668'  )
{
	$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
    )
);
$context  = stream_context_create($opts);
return $result = file_get_contents('https://sc.ftqq.com/'.$key.'.send'.false, $context);

}
Copy the code

Analysis of working principle of Server sauce

  1. First, you must follow his official wechat account;
  2. After you scan and bind wechat, it is actually a process of differentiating users to record your UserID. For example: 100 word cut official public number through you send a specific string to distinguish.
  3. The server does a mapping between SCKEY and UserID, and then sends it to different people based on your SCKEY. The server opens an interface to receive your SCKEY, title, and content. Then call wechat official interface to send customer messages.
  4. The user receives the message.

Ps. Actually, this message supports Markdown. If you don’t know what Markdown is… Go to Google?