php:
function pushme($params = array())
{
$options = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
);
return $result = file_get_contents('https://push.i-i.me/', 0, stream_context_create($options));
}
//example
$res = pushme(['push_key' => 'your push_key', 'title' => 'hello', 'content' => 'this is message content']);
echo $res;
php(curl):
function pushme($params = [])
{
$url = 'https://push.i-i.me/';
$data = json_encode($params, JSON_UNESCAPED_UNICODE);
$len = strlen($data);
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . $len)
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
return curl_errno($curl).': '.curl_error($curl);
}
curl_close($curl); // 关键CURL会话
return $tmpInfo; // 返回数据
}
//example
$res = pushme(['push_key' => 'your push_key', 'title' => 'hello', 'content' => 'this is message content']);
echo $res;
nodejs:
async function pushme(params) {
const https = require('https');
const data = Buffer.from(JSON.stringify({...params}));
const options = {
hostname: 'push.i-i.me',
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
return new Promise((resolve) => {
const req = https.request(options, res => {
let _data = '';
res.on('data', chunk => {
_data += chunk;
});
res.on('end', _ => {
resolve(_data.toString());
});
});
req.on('error', error => {
resolve(error.toString())
});
req.write(data);
req.end();
});
}
//example
pushme({push_key: 'your push_key', title: 'test'}).then(res => console.log(res));