使用nodejs消费SAP Cloud for Customer上的Web service
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的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码:
使用nodejs消费SAP Cloud for Customer上的Web service的更多相关文章
- 机器学习在SAP Cloud for Customer中的应用
关于机器学习这个话题,我相信我这个公众号1500多位关注者里,一定有很多朋友的水平比Jerry高得多.如果您看过我以前两篇文章,您就会发现,我对机器学习仅仅停留在会使用API的层面上. 使用Java程 ...
- SAP Cloud for Customer销售订单External Note的建模细节
SAP Cloud for Customer的销售订单创建页面里,我们可以给一个订单维护External Note,当这个订单同步到S/4HANA生成对应的生产订单后,这个note可以作为备注提示生产 ...
- SAP Cloud for Customer里Sales Order和Sales Quote的建模方式
SAP Cloud for Customer的Sales工作中心里有Sales Quote和Sales Order两个视图,一个用于销售报价单,另一个用于销售订单. 流程上是先有报价单 ,报价单是一份 ...
- SAP Cloud for Customer Extensibility的设计与实现
今天的文章来自Jerry的同事,SAP成都研究院C4C开发团队的开发人员徐欢(Xu Boris).徐欢就坐我左手边的位置,因此我工作中但凡遇到C4C的技术问题,一扭头就可以请教他了,非常方便.下图是他 ...
- SAP Cloud for Customer Price-计价简介
SAP Cloud for Customer(本文以下简称C4C)作为SAP新一代的CRM云产品,其Price功能实现虽不如以前的SAP ERP那么复杂,但是也能满足企业运作中各种Price需求. C ...
- SAP Cloud for Customer(C4C)的一些学习资料
经常有顾问朋友们问我想自学C4C,有什么好的资料. SAP内部确实有一些C4C培训材料,但是不能散布到公司外部. 想学习C4C,还是得到SAP官网网站上查找资料. 1. 登录https://help. ...
- SAP Cloud for Customer Account和individual customer的区别
在SAP Cloud for Customer的Customers工作中心里,有三个视图:Accounts,Contacts和Individual Customers. 这三种主数据的区别是什么?我们 ...
- 如何找到SAP Cloud for Customer标准培训和认证方面的信息
有一些朋友询问我如何在SAP官网上找到和SAP Cloud for Customer相关的标准培训信息,我这里把步骤写出来: 登录SAP官网https://training.sap.com 输入和Cl ...
- 如何把SAP Kyma和SAP Cloud for Customer连接起来
首先进入SAP Cloud for Customer的Administration的工作中心,打开General Settings视图,进入Event Notification配置UI: 新建一个C4 ...
随机推荐
- python 学习笔记8 (模块)
Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python 代码段. 把相关的代码 ...
- GridView 72般绝技
GridView无代码分页排序 GridView选中,编辑,取消,删除 GridView正反双向排序 GridView和下拉菜单DropDownList结合 GridView和CheckBox结合 鼠 ...
- DropDownlist数据SelectedIndexChanged触发问题解决
1.设置DropDownlist的AutoPostBack为True 2.绑定DropDownlist数据时出现了重复项, 在载入数据时保存数据状态应该写在Load事件中的if (!IsPostBac ...
- 手动配置webpack之React
安装 1.安装react转译相关依赖包: npm安装: npm install --save-dev babel-core babel-loader babel-preset- ...
- memcached 扩展安装(windows)
在脚本之家里下载扩展压缩包 https://www.jb51.net/softs/392873.html 安装扩展前得先安装memcached并启动 下载完扩展压缩包解压并找到对应自己php版本 复制 ...
- Unity 5着色器系统代码介绍(上)
http://forum.china.unity3d.com/thread-25724-1-10.html Unity 5着色器系统代码介绍(上) Unity在着色器开发方面提供了很大的灵活性.有些工 ...
- spring事物回滚机制 (事务异常回滚,捕获异常不抛出就不会回滚)
当异常被捕获catch的时候,spring的事物则不会回滚 为什么不会滚呢?? spring aop 异常捕获原理:被拦截的方法需显式抛出异常,并不能经任何处理,这样aop代理才能捕获到方法的异常 ...
- 题解 P1004 方格取数
传送门 动态规划Yes? 设i为路径长度,(为什么i这一维可以省掉见下)f[j][k]表示第一个点到了(j,i-j),第二个点到了(k,j-k) 则 int ji=i-j,ki=i-k; f[j][k ...
- GUI的最终选择 Tkinter(九):事件
Tkinter事件处理 Tkinter应用会花费大部分的时间在处理事件循环中(通过mainloop()方法进入),事件可以是触发的鼠标,键盘的操作,管理窗口触发的重绘事件(在多数情况下都是有用户间接引 ...
- NET Core学习方式(视频)
NET Core学习方式(视频) ASP.NET Core都2.0了,它的普及还是不太好.作为一个.NET的老司机,我觉得.NET Core给我带来了很多的乐趣.Linux, Docker, Clou ...