共計 2356 個字符,預計需要花費 6 分鐘才能閱讀完成。
這篇文章給大家介紹如何使用 nodejs 消費 SAP Cloud for Customer 上的 Web service,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
看一個具體例子:C4C 里 Individual Customers 可以維護 Social User Profile,在 Jerry 上面的公眾號文章里,正是把微信用戶的 open ID 維護到 Social User Profile 的 SocialMediaAccountUserID 字段去,如下圖所示。
首先到 Administrator- Input and Output Management- Service Explorer 中取得標準的查詢 Social User profile 的 web service:
https:// host name /sap/bc/srt/scs/sap/requestforsocialmediauserprofi
您可以參考我 github 上的源代碼。
var request = require(request var config = require( ../../config.js function getSocialMediaProfile(profileID) { console.log( Jerry trace begin *********************************** console.log( url: + config.socialMediaProfileGetEndPoint); console.log(config.credential_qxl: + config.credential_qxl); var ogetSocialMediaProfileOptions = { url: config.socialMediaProfileGetEndPoint, method: POST , headers: { content-type : text/xml , Authorization : Basic + new Buffer(config.credential_qxl).toString(base64)
}, body: soapenv:Envelope xmlns:soapenv= http://schemas.xmlsoap.org/soap/envelope/ xmlns:glob= http://sap.com/xi/SAPGlobal20/Global soapenv:Header/ soapenv:Body glob:SocialMediaUserProfileRequest_sync + SocialMediaUserProfileSelectionByElements + SelectionBySocialMediaUserProfileID + InclusionExclusionCode I /InclusionExclusionCode + IntervalBoundaryTypeCode 1 /IntervalBoundaryTypeCode + LowerBoundarySocialMediaUserProfileID + profileID + /LowerBoundarySocialMediaUserProfileID + /SelectionBySocialMediaUserProfileID + /SocialMediaUserProfileSelectionByElements + /glob:SocialMediaUserProfileRequest_sync /soapenv:Body /soapenv:Envelope }; console.log(body: + ogetSocialMediaProfileOptions.body); console.log(Jerry trace end *********************************** return new Promise(function(resolve,reject){ request(ogetSocialMediaProfileOptions,function(error,response,body){ console.log( Jerry web service response: + body); var soapreg = /.* SocialMediaUserAccountID (.*) \/SocialMediaUserAccountID var soapresult = soapreg.exec(body); if( soapresult.length === 2){ resolve(soapresult[1]);
}
});
});
} module.exports = getSocialMediaProfile;
將上述代碼另存為文件 getSocialMediaProfileTest.js, 直接使用 node getSocialMediaProfileTest.js 執行。
從 console 能觀察到發送的 HTTP post 請求的 body 和返回的響應內容:
關于如何使用 nodejs 消費 SAP Cloud for Customer 上的 Web service 就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。