Replying to myself. I got it done. For those who may be interested, to send onesignal push notification to a user, see the script below.:
$content = array(“en” => $_POST[‘message’]);
$fields = array(
‘app_id’ => “your app id here”,
‘include_player_ids’ => array($_POST[‘playerId’]),
‘contents’ => $content
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
$response = sendMessage();
$return[“allresponses”] = $response;
$return = json_encode( $return);
I used extension to get playerId for a user, save to mysql database and sent it to the user by email on first run of the app, Phone anti-theft and anti-abduction app. In the event that the phone is stolen, the owner may prompt phone call or use of the app by sending onesignal push notification to the device with the player ID form my website.
My discovery that I could not explain:
Getting data from the web
$message = $_POST[‘message’];
$playerId = $_POST[‘playerId’];
If substitute the string value on the left in the above script, onesignal will see null and present error but if I substitute the string value on the right, the message sends successfully.
Can someone tell me why?
For this reason, I could not get string value from the database and use directly.
$row[“playerId”] will give null error.
I have been able to add an important feature to phone app, “prompt a call”. Thanks to @wanttobe for Get Player ID.
See user’s face feature: Thanks to @Taifun camera extension.
Try it: https://play.google.com/store/apps/details?id=com.contritrack.phone