javascript [pushover] #pushing

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript [pushover] #pushing相关的知识,希望对你有一定的参考价值。

# https://github.com/jnwatts/pushover.sh
git clone https://github.com/jnwatts/pushover.sh.git;
cd pushover.sh;
chmod +x pushover.sh;

: '
pushover.sh <options> <message>
 -c <callback>
 -d <device>
 -D <timestamp>
 -e <expire>
 -f <config file>
 -p <priority>
 -r <retry>
 -t <title>
 -T <TOKEN> (required if not in config file)
 -s <sound>
 -u <url>
 -U <USER> (required if not in config file)
'
<?php
/**---------------------------------------------------------------------------------------------------
	CURL
*/
curl_setopt_array($ch = curl_init(), array(
  CURLOPT_URL => "https://api.pushover.net/1/messages",
  CURLOPT_POSTFIELDS => array(
    "token" => "APIKEY",
    "user" => "USERKEY",
    "message" => "hello world",
  )));
$result = curl_exec($ch);
curl_close($ch);


/*---------------------------------------------------------------------------------------------------
create app, & full app token + user token.
*/
include('lib/Pushover.php');
$push = new Pushover();
$push->setToken('acbm3pt74nvoajz3zciekrzsnccyg2');
$push->setUser('us651f81kanzktawa4g3h1sq1gjhef');
$push->setTitle('Hey Chris');
$push->setMessage('Hello world! ' .time());
$push->setUrl('http://chris.schalenborgh.be/blog/');
$push->setUrlTitle('cool php blog');
$push->setDevice('iphone');
/*
priority (default 0):
1- user's quiet hours will be ignored + messages displayed in red.
2- same but message will repeat until the user acknowledges it.
*/
$push->setPriority(2);
//Used with Priority = 2; Pushover will resend the notification every 60 seconds until the user accepts.
$push->setRetry(60); 

//Used with Priority = 2; Pushover will resend the notification every 60 seconds for 3600 seconds. After that point, it stops sending notifications.
$push->setExpire(3600); 
//must be a URL (HTTP or HTTPS) that is reachable from the Internet
$push->setCallback('http://chris.schalenborgh.be/');

$push->setTimestamp(time());
$push->setDebug(true);
$push->setSound('bike');
$go = $push->send();
$receipt = $push->getReceipt();
echo '<pre>';
print_r($go);
print "Receipt: $receipt\n";
echo '</pre>';
/*---------------------------------------------------------------------------------------------------
	google script
*/
//priority=1
UrlFetchApp.fetch('https://api.pushover.net/1/messages',{
    muteHttpExceptions: true,
    validateHttpsCertificates : false,
    method: 'POST',
    contentType: 'application/json',
    payload: JSON.stringify({
      token: 'acbm3pt74nvoajz3zciekrzsnccyg2',
      user: 'us651f81kanzktawa4g3h1sq1gjhef',
      message : msg,
      title: "title",
      sound: "bike",
      retry: 30,
      priority: 2,
      expire: 3600
    })
  });
/*---------------------------------------------------------------------------------------------------
	Nodejs
*/
var push = require( 'pushover-notifications' );

var p = new push( {
    user: process.env['PUSHOVER_USER'],
    token: process.env['PUSHOVER_TOKEN'],
    // httpOptions: {
        //        proxy: process.env['http_proxy'],
        //},
    // onerror: function(error) {},
    // update_sounds: true // update the list of sounds every day - will
    // prevent app from exiting.
});

var msg = {
    // These values correspond to the parameters detailed on https://pushover.net/api
    // 'message' is required. All other values are optional.
    message: 'omg node test',    // required
    title: "Well - this is fantastic",
    sound: 'magic',
    device: 'devicename',
    priority: 1
};

p.send( msg, function( err, result ) {
    if ( err ) {
        throw err;
    }

    console.log( result );
});

/**
 * Sending a message to multiple users.
 */
var users = [
  'token1',
  'token2',
  'token3'
];

var msg = {
  message: 'omg node test',
  title: "Well - this is fantastic",
  sound: 'magic' // optional
  priority: 1 // optional,
};

for ( var i = 0, l = users.length; i < l; i++ ) {

  msg.user = users[i];
  // token can be overwritten as well.

  p.send( msg, function( err, result ) {
    if ( err ) {
      throw err;
    }

    console.log( result );
  });
}

以上是关于javascript [pushover] #pushing的主要内容,如果未能解决你的问题,请参考以下文章

当 Pushover 应用收到通知时触发我的应用

基于pushover实现计算机/服务器向不同设备的通知推送

基于pushover实现计算机/服务器向不同设备的通知推送

无法使用Javascript根据键名合并两个不同的数组

JavaScript中的唯一数组

htmlCSSjavascript-7JavaScript作用域