我是OneSignal通知的新手 我必须通过我的phonegap应用程序发送通知消息。我知道如何发送新消息流程以通过信号仪表板发送通知的过程。
任何人都可以帮助我使用ajax调用从应用程序中执行此操作 三江源。
答案 0 :(得分:1)
您可以使用对 https://onesignal.com/api/v1/notifications 的ajax调用来触发来自应用的通知。
var request = $.ajax({
url: "https://onesignal.com/api/v1/notifications",
headers: {
'Authorization':'Basic ONESIGNAL_REST_API_KEY',
'Content-Type':'application/json'
},
type: "POST",
data: {"app_id" : "Your APP ID","contents":{"en":"message"},"included_segments":["All"],"data":{"abc": "123", "foo": "bar"}},
dataType: "application/json"
});
request.done(function(msg) {
console.log("success");
});
request.fail(function(jqXHR, textStatus) {
console.log( "Request failed: " + textStatus );
});
希望它会对你有所帮助。
答案 1 :(得分:0)
var jsonBody = {
"app_id": "Onesignal App Id",
"include_player_ids": ["App Playerid"],
"headings": {
"en": "Sump"
},
"contents": {
"en": " Sump Level is 'Sumpper' "
}
};
var request = $.ajax({
url: "https://onesignal.com/api/v1/notifications",
headers: {
'Authorization':'Basic REST API Key',
'Content-Type':'application/json',
'Access-Control-Allow-Headers': 'SDK-Version',
'Access-Control-Allow-Origin': '*'
},
type: "POST",
data: JSON.stringify(jsonBody),
dataType: "json"
});
console.log(request);
request.success(function(msg) {
console.log("success");
});
request.error(function(jqXHR, textStatus ) {
console.log( "Request failed: " + textStatus );
});