I have figured out how to send a push notification with WonderPush through two ways:
#1
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://management-api.wonderpush.com/v1/deliveries');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$fields = array(
'accessToken' => "xxx",
'targetIds' => "123",
'campaignId' => "123abc",
'notification' => array(
'alert' => array(
'title' => "Some title",
'text' => "Some text"
)
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
#2:
require_once('inc/WonderPush/init.php');
$wonderpush = new \WonderPush\WonderPush('xxx', 'yyy');
$response = $wonderpush->deliveries()->create(
\WonderPush\Params\DeliveriesCreateParams::_new()
->setTargetSegmentIds('@ALL')
->setTargetUserIds('123')
->setCampaignId('123abc')
->setNotification(\WonderPush\Obj\Notification::_new()
->setAlert(\WonderPush\Obj\NotificationAlert::_new()
->setTitle('Some title')
->setText('Some text')
))
);
The first method uses the pre-created "campaign" which includes a custom URL when the user clicks the notification and also buttons with possible other URLs. However, I can't change anything on-the-fly, i.e. no custom title, text or URL.
The second method is created by code and there I can have custom titles and texts, but the URL is taken from the settings in WonderPush and I can't make any buttons at all.
Can someone help me to do what I want to do with either of my examples (or a totally new way)?