custom-content-notification
- CURL
- NODE.JS
- PYTHON
- PHP
- GO
- در این نمونه کد از cURL استفاده شده است که میتوانیدتوسط
sudo apt install curl
آن را نصب کنید.
curl -X POST https://api.pushe.co/v2/messaging/notifications/ \
-H 'authorization: Token YOUR_TOKEN' \
-H 'content-type: application/json' \
-d '{"app_ids": "YOUR_APP_ID", "custom_content": {"key1": "Value1","Key2": "Value2"}}'
- برای اجرای این کد باید ابتدا پکیج axios را نصب کنید
npm install axios
const axios = require('axios');
const YOUR_TOKEN = 'put your token here ...';
const YOUR_APP_ID = 'put your app id here ...';
const url = `https://api.pushe.co/v2/messaging/notifications/`;
const options = {
headers: {
'Authorization': `Token ${YOUR_TOKEN}`,
'Content-Type': 'application/json'
}
};
const data = {
app_ids: YOUR_APP_ID,
custom_content: {
key1: "value1",
key2: "value2"
}
};
axios.post(url, data, options)
.then(resp => console.log(resp))
.catch(err => console.error(err));
- برای اجرا نیاز به پایتون ورژن ۳.۶ و به بالا میباشد
- برای اجرای این کد باید ابتدا پکیج requests را نصب کنید.
pip install requests
import requests
import json
YOUR_TOKEN = 'put your token here ...'
YOUR_APP_ID = 'put your app id here ...'
url = f'https://api.pushe.co/v2/messaging/notifications/'
headers = {
'Authorization': f'Token {YOUR_TOKEN}',
'Content-Type': 'application/json'
}
payload = json.dumps({
'app_ids': YOUR_APP_ID,
'custom_content': {
'key1': 'value1',
'key2': 'value2'
}
})
r = requests.post(url, data=payload, headers=headers)
print(r.status_code)
$YOUR_TOKEN = 'put your token here ...';
$YOUR_APP_ID = 'put your app id here ...';
$ch = curl_init('https://api.pushe.co/v2/messaging/notifications/');
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Token " . $YOUR_TOKEN,
),
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'app_ids' => $YOUR_APP_ID,
'custom_content' => array(
'key1' => 'value1',
'key2' => 'value2'
)
)));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
package main
import (
"fmt"
"bytes"
"io/ioutil"
"encoding/json"
"net/http"
)
const YOUR_TOKEN = "put your token here ..."
const YOUR_APP_ID = "put your app id here ..."
func main() {
url := "https://api.pushe.co/v2/messaging/notifications/"
payload := map[string]interface{}{
"app_ids" : YOUR_APP_ID,
"custom_content": map[string]string{
"key1": "value1",
"key2": "value2",
}
}
jsonValue, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Token " + YOUR_TOKEN)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
}