0

我正在開發使用IBM MobileFirst平臺8.0的SDK,有推送通知功能IBM移動第一平臺 - 從適配器

我設法通過郵遞員發送通知的iOS應用程序發送推送通知,這個過程是 獲得從令牌在MobileFirst平臺服務器 並通過REST API與令牌

教程鏈接,我有如下是一起發送的通知,

服務器端 - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/sending-notifications/

客戶端 - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/notifications/handling-push-notifications/cordova/

獲得令牌 - https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/authentication-and-security/confidential-clients/#obtaining-an-access-token

現在,我努力當應用程序觸發一個適配器調用我目前停留在使用發送通知

發送推送通知WL.Server.invokeHttp,下面是更適配器代碼

function sendPushNotification(message) {  
    var result = getToken();  
    var access_token = "Bearer " + result["access_token"];  

    var requestStructure = { 
     method : 'post', 
     returnedContentType : 'json', 
     path : '/imfpush/v1/apps/my.app/messages', 
     headers: { 
      "Content-Type" : "application/json", 
      "Authorization" : access_token 
     }, 
     parameters : { 
      'message':{'alert' : 'Test message'} 
     } 
    }; 

    result = MFP.Server.invokeHttp(requestStructure); 

    return result; 
} 


function getToken() { 
    var requestStructure = { 
     method : 'post', 
     returnedContentType : 'json', 
     path : '/mfp/api/az/v1/token',  
     headers: { 
      "Content-Type" : "application/x-www-form-urlencoded", 
      "Authorization" : "Basic UHVzaE5vd213123asdsadGlvbjpQdXNoTm90aasdasdWZpY2F0aW9u" 
     }, 
     parameters:{ 
      "grant_type" : "client_credentials", 
      "scope" : "push.application.my.app messages.write" 
     } 
    }; 

    var results = MFP.Server.invokeHttp(requestStructure); 
    return results; 
} 

我似乎對

有問題 ​​

我可能在這部分做錯了,希望有建議。

在此先感謝

+0

你似乎缺少目標在JSON: https://www.ibm.com/support/knowledgecenter/SSHS8R_8.0.0/com .ibm.worklight.apiref.doc/rest_runtime/r_restapi_push_message_post.html –

回答

0

sendPushNotification方法使用了錯誤的語法在移動首先調用WS。 悠雲改變這樣的:

function sendPushNotification(message) {  
var result = getToken();  
var access_token = "Bearer " + result["access_token"];  

var requestStructure = { 
    method : 'post', 
    returnedContentType : 'json', 
    path : '/imfpush/v1/apps/my.app/messages', 
    headers: { 
     "Authorization" : access_token 
    }, 
    body: { 
     content: 'message':{'alert' : 'Test message'}, 
     contentType: 'application/json' 
    } 
}; 

result = MFP.Server.invokeHttp(requestStructure); 

return result; 

}

相關問題