تنظمیات اولیه

 با اجرای این مثال ها، پوش به تمامی کاربرانی که این اپ را نصب کرده باشند، ارسال خواهد شد!

برای ارسال پوش از طریق API می بایست که ابتدا برای اپلیکشن خود API KEY را فعال نمایید.

 

ارسال پوش ساده

​
<?php
$ch              = curl_init();
$myPrivateApiKey = "4ce8cd05ab6f2f7e20e7ccc31c58130c64c784";// API Key Update me
$myAppID         = "5bf3fc788435e80007b60d15"; //  Update me
$myPushTitle     = 'Normal push'; // Update me
$myPushMessage   = 'MY PUSH MESSAGE FROM PHP'; // Update me
$targetPushUrl   = 'http://mywebsite.com/'; // Update me

////////////// Don't change the following code ///////////
$data            = array (
	'afterOpenType' => 'url',
	'pushData' =>
		[
			'title' => $myPushTitle,
			'shortMessage' => $myPushMessage,
			'url' => $targetPushUrl,
		],
);
$data_string     = json_encode($data);
curl_setopt($ch, CURLOPT_URL, "https://api.cheshmak.me/v1/push/app/{$myAppID}/send" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string );
curl_setopt($ch, CURLOPT_POST, 1);

$headers         = array();
$headers[]       = "Content-Type: application/json";
$headers[]       = "Key: {$myPrivateApiKey}";
$headers[]       = "Cache-Control: no-cache";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}else{
	var_dump($result);
}
curl_close ($ch);

پوش با ارسال داده JSON

​

<?php
$ch              = curl_init();
$myPrivateApiKey = "4ce8cd05ab6fd550e7ccc31c58130c64c784";//API Key Update me
$myAppID         = "5bf3fc788435e80007b60d15"; // Update me
$myPushTitle     = 'Normal push with JSON'; // Update me
$myPushMessage   = 'MY PUSH MESSAGE FROM PHP'; // Update me
$targetPushUrl   = 'http://mywebsite.com/'; // Update me
$myJSON = [ // Update me
	"name" => "reza",
	"city" => "chehmak"
];

///////////////// Don't change the following code ///////////////
$data            = array (
	'afterOpenType' => 'url',
	'pushData' =>
		[
			'title' => $myPushTitle,
			'shortMessage' => $myPushMessage,
			'url' => $targetPushUrl,
			'customData'=> json_encode($myJSON)
		],
);
$data_string     = json_encode($data);
curl_setopt($ch, CURLOPT_URL, "https://api.cheshmak.me/v1/push/app/{$myAppID}/send" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string );
curl_setopt($ch, CURLOPT_POST, 1);

$headers         = array();
$headers[]       = "Content-Type: application/json";
$headers[]       = "Key: {$myPrivateApiKey}";
$headers[]       = "Cache-Control: no-cache";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}else{
	var_dump($result);
}
curl_close ($ch);

پوش مخفی به همراه داده JSON

<?php 
$ch = curl_init();
$myPrivateApiKey = "4ce8cd05aaf7e21c58130c64c784";// API Key Update me 
$myAppID = "5bf3fc788435e80007b60d15"; // Update me 
$myJSON = [ // Update me 
        "name" => "reza",
	"city" => "chehmak"
];

///////////// Don't change the following code /////////////////
$data   = array (
	'afterOpenType' => 'service',
	'pushData' =>
		[
			'title' => 'ارسال داده',
			'customData'=> json_encode($myJSON)
		],
);
$data_string     = json_encode($data);


curl_setopt($ch, CURLOPT_URL, "https://api.cheshmak.me/v1/push/app/{$myAppID}/send" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string );
curl_setopt($ch, CURLOPT_POST, 1);

$headers         = array();
$headers[]       = "Content-Type: application/json";
$headers[]       = "Key: {$myPrivateApiKey}";
$headers[]       = "Cache-Control: no-cache";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

if (curl_errno($ch)) {
	echo 'Error:' . curl_error($ch);
}else{
	var_dump($result);
}
curl_close ($ch);

ارسال پوش به گروهی خاص

در صورتی که کاربران خود را توسط توابع تگ چشمک، گروه بندی کرده باشید می توانید به یک یا چند گروه خاص، پوش ارسال نمایید.

 



<?php
$ch              = curl_init();
$myPrivateApiKey = "544b885ba9f07e3c3653e1656060340aceb3b34be0168c18f4942cfcca";// API Key Update me
$myAppID         = "5c31b4772e465e0006ba0164"; //  Update me
$myPushTitle     = 'Normal push'; // Update me
$myPushMessage   = 'MY PUSH MESSAGE FROM PHP'; // Update me
$targetPushUrl   = 'http://mywebsite.com/'; // Update me
$myTags = [ // Update me
	'groupB',
	'cheshmakMulti3',
];

////////// Don't change the following code //////////////
$data        = array(
	'afterOpenType' => 'url',
	'pushData'      =>
		[
			'title'        => $myPushTitle,
			'shortMessage' => $myPushMessage,
			'url'          => $targetPushUrl,
		],
	'target'        => [
		'tags' => [
			'pattern' => $myTags
		]
	]


);

$data_string = json_encode( $data );
curl_setopt( $ch, CURLOPT_URL, "https://api.cheshmak.me/v1/push/app/{$myAppID}/send" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string );
curl_setopt( $ch, CURLOPT_POST, 1 );

$headers   = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Key: {$myPrivateApiKey}";
$headers[] = "Cache-Control: no-cache";
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );

$result = curl_exec( $ch );

if ( curl_errno( $ch ) ) {
	echo 'Error:' . curl_error( $ch );
} else {
	var_dump( $result );
}
curl_close( $ch );

ارسال پوش به یک فرد خاص

برای ارسال پوش به صورت تکی، شما می بایست Cheshmak ID  آن دستگاه را داشته باشید. سپس با کمک مثال زیر می توانید به آن دستگاه خاص پوش ارسال نمایید.

<?php
$ch              = curl_init();
$myPrivateApiKey = "35a17a9429c86dbd26811781bc12f475bb8130ac1";// Update me
$myAppKey        = "5c3db54c48689000073f881b"; // Update me
$myPushTitle     = 'FROM PHP'; // Update me
$myPushMessage   = 'MY PUSH MESSAGE WITH API'; // Update me
$targetPushUrl   = 'http://mywebsite.com/'; // Update me
$pushIcon        = 'https://www.android.com/img/lg.png'; // Update me
$myCheshmakId    = '7a4a1430-1d5d-11e9-8cd9-716383a85cf6'; // Update me
$myCheshmakId2   = '61cf1e00-d771-11e8-a557-33a24402f764'; // Update me

///////////////////////////// Don't change the following code ///////////////////////////////
$data            = array (
	'afterOpenType' => 'url',
	'pushData' =>
		[
			'title' => $myPushTitle,
			'shortMessage' => $myPushMessage,
			'icon' => $pushIcon,
			'url' => $targetPushUrl,
		],
	'filter' =>
		[
			'cheshmakIds' => [ $myCheshmakId ,$myCheshmakId2],
		]
);
$data_string     = json_encode($data);
curl_setopt($ch, CURLOPT_URL, "https://api.cheshmak.me/v1/push/app/{$myAppKey}/send" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string );
curl_setopt($ch, CURLOPT_POST, 1);

$headers         = array();
$headers[]       = "Content-Type: application/json";
$headers[]       = "Key: {$myPrivateApiKey}";
$headers[]       = "Cache-Control: no-cache";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}else{
	var_dump($result);
}
curl_close ($ch);