定义('PW_AUTH','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');定义('PW_APPLICATION','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$query = mysql_query("Select * from xxxxx where id ='".xxxx."'");
while($res=mysql_fetch_array($query))
{
function doPostRequest($url, $data, $optional_headers = null) {
$params = array(
'http' => array(
'method' => 'GET',
'content' => $data
));
if ($optional_headers !== null)
$params['http']['header'] = $optional_headers;
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp)
throw new Exception("Problem with $url, $php_errmsg");
$response = @stream_get_contents($fp);
if ($response === false)
return false;
return $response;
}
function pwCall( $action, $data = array() ) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $action;
$json = json_encode( array( 'request' => $data ) );
$res = doPostRequest( $url, $json, 'Content-Type: application/json' );
// print_r( @json_decode( $res, true ) );
}
$div = $res['device_token'];
$username = $res['username'];
pwCall( 'createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'devices' => array($div),
'content' => $username.' has sent you an challenge!',
'data' => array( 'custom' => 'json data' )
)
)
)
);
}
$div = "Device Token,you can assign it dynamically from database or statically.