使用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 ...
随机推荐
- Struts2+JQuery+Json登陆实例
Struts2+JQuery+Json登陆实例 博客分类: Struts2 在搭建之前.. 首先,需要准备struts2.0框架的5个核心包, 以及jsonplugin-0.32.jar 以及js ...
- Java正则表达式之Matcher介绍
Matcher方法如下: Matcher方法如下: Matcher appendReplacement(StringBuffer sb, String replacement) 将当前匹配子串替换为指 ...
- iOS公司账号($99)/企业账号($299)申请
公司账号($99)与企业账号($299)申请基本大同小异,最主要的差别就在于入口不一样 一.注册Apple ID 在iOSAppStore个人开发者账号申请中已经介绍过注册App ID的流程,这里不再 ...
- Linux 97个常用命令
ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件 -A 通-a,但不列出"."和".." -l 列出文件 ...
- Jinkins定时任务设置
设置的地方在构建触发器中 Build after other projects are built:在其他项目构建完成后再进行构建. Build periodically:周期进行构建 Build w ...
- MS SQL的CASE...WHEN...THEN...END语法
根据多个可能的答案检查一个值或变量. 举例说明: SELECT [type],CASE [type] WHEN 'TT' THEN 'TYPE_TABLE' WHEN 'FN' THEN 'SQL_S ...
- python3 Flask安装
虚拟环境 建议在开发环境和生产环境下都使用虚拟环境来管理项目的依赖. 为什么要使用虚拟环境?随着你的 Python 项目越来越多,你会发现不同的项目会需要 不同的版本的 Python 库.同一个 Py ...
- 上传、裁剪图片-----Jcrop图片裁剪插件
Jcrop文档:http://code.ciaoca.com/jquery/jcrop/C#裁剪:http://www.cnblogs.com/xyang/archive/2013/02/25/293 ...
- Luogu P2522 [HAOI2011]Problem b 莫比乌斯反演
设$f(d)=\sum_{i=1}^N\sum_{j=1}^M[gcd(i,j)==d],\\F(n)=\sum_{n|d}f(d)=\lfloor \frac{N}{n} \rfloor \lflo ...
- 2019湘潭校赛 G(并查集)
要点 题目传送 题目本质是每个点必属于两个集合中的一个,伴随的性质是:如果一个人说别人true,则他们一定属于同一阵营:如果说别人fake,一定不属于同一阵营. 每个点拆为\(i\)和\(i + n\ ...