使用nodejs消费SAP Cloud for Customer上的Web service
2023-09-14 09:03:58 时间
Jerry在公众号文章C4C和微信集成系列教程里曾经使用nodejs去消费C4C提供的标准webservice。
看一个具体例子:C4C里Individual Customers可以维护Social User Profile,在Jerry上面的公众号文章里,正是把微信用户的open ID维护到Social User Profile的SocialMediaAccountUserID字段去,如下图所示。
那么已知一个Social Profile ID,如何用nodejs通过Web Service的方式获得该Profile明细?
首先到Administrator->Input and Output Management->Service Explorer中取得标准的查询Social User profile的web service:
https:///sap/bc/srt/scs/sap/requestforsocialmediauserprofi
然后使用nodejs module request给这个url发一个HTTP post请求。
您可以参考我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和返回的响应内容:
要获取更多Jerry的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码:
相关文章
- SAP UI5 Routing 路由介绍
- SAP UI5和Angular的函数防抖(Debounce)和函数节流(Throttle)实现原理介绍
- SAP CRM和SAP Hybris的action profile
- role based page - cached_sap_menu
- SAP ABAP Netweaver里进程能够申请的最大内存
- 如何安装 SAP Commerce Cloud,以便让 SAP Spartacus 使用
- SAP Spartacus的页面类型和路由配置
- SAP Spartacus的cxComponentWrapper指令
- SAP 电商云 Spartacus UI SiteContextParamsService 的实现原理解析
- 一个 SAP 成都研究院开发工程师的2021年度总结:既没有厚积,也未能薄发
- SAP Business ByDesign 和支付宝与钉钉集成的一个原型开发案例
- 如何下载 SAP Cloud for Customer Cloud Application Studio
- 如何在 SAP Cloud for Customer 里自定义消息 Message
- 使用nodejs代码在SAP C4C里创建Individual customer
- 使用Visual Studio Code调试运行在SAP云平台上处于运行状态的nodejs应用
- 从SAP Leonardo到SAP Data Intelligence
- 使用nodejs运行SAP Fiori应用
- 如何把nodejs应用和SAP云平台上的Redis实例做绑定
- 如何自定义SAP Spartacus店铺的界面颜色风格