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的更多相关文章

  1. 机器学习在SAP Cloud for Customer中的应用

    关于机器学习这个话题,我相信我这个公众号1500多位关注者里,一定有很多朋友的水平比Jerry高得多.如果您看过我以前两篇文章,您就会发现,我对机器学习仅仅停留在会使用API的层面上. 使用Java程 ...

  2. SAP Cloud for Customer销售订单External Note的建模细节

    SAP Cloud for Customer的销售订单创建页面里,我们可以给一个订单维护External Note,当这个订单同步到S/4HANA生成对应的生产订单后,这个note可以作为备注提示生产 ...

  3. SAP Cloud for Customer里Sales Order和Sales Quote的建模方式

    SAP Cloud for Customer的Sales工作中心里有Sales Quote和Sales Order两个视图,一个用于销售报价单,另一个用于销售订单. 流程上是先有报价单 ,报价单是一份 ...

  4. SAP Cloud for Customer Extensibility的设计与实现

    今天的文章来自Jerry的同事,SAP成都研究院C4C开发团队的开发人员徐欢(Xu Boris).徐欢就坐我左手边的位置,因此我工作中但凡遇到C4C的技术问题,一扭头就可以请教他了,非常方便.下图是他 ...

  5. SAP Cloud for Customer Price-计价简介

    SAP Cloud for Customer(本文以下简称C4C)作为SAP新一代的CRM云产品,其Price功能实现虽不如以前的SAP ERP那么复杂,但是也能满足企业运作中各种Price需求. C ...

  6. SAP Cloud for Customer(C4C)的一些学习资料

    经常有顾问朋友们问我想自学C4C,有什么好的资料. SAP内部确实有一些C4C培训材料,但是不能散布到公司外部. 想学习C4C,还是得到SAP官网网站上查找资料. 1. 登录https://help. ...

  7. SAP Cloud for Customer Account和individual customer的区别

    在SAP Cloud for Customer的Customers工作中心里,有三个视图:Accounts,Contacts和Individual Customers. 这三种主数据的区别是什么?我们 ...

  8. 如何找到SAP Cloud for Customer标准培训和认证方面的信息

    有一些朋友询问我如何在SAP官网上找到和SAP Cloud for Customer相关的标准培训信息,我这里把步骤写出来: 登录SAP官网https://training.sap.com 输入和Cl ...

  9. 如何把SAP Kyma和SAP Cloud for Customer连接起来

    首先进入SAP Cloud for Customer的Administration的工作中心,打开General Settings视图,进入Event Notification配置UI: 新建一个C4 ...

随机推荐

  1. 连接带密码的access数据库

    在网上找了很多都不靠谱,稀里哗啦的弄一堆连接字符串,很不优雅. 这个方法很简单: 1.在“连接”这页中,下方有“输入登录数据库的信息”用户名:admin,并在下面选择“空白密码” 2.在“所有”这页的 ...

  2. UVa 11552 Fewest Flops (DP)

    题意:给一个字符串,把它分为k块,每一块里面的字母可以任意的排序.最终字符串, 连续的一样的字母算作一个chunk,问总chunks最少是多少? 析:dp[i][j] 表示第 i 个块,第 j 位在末 ...

  3. UVa 10801 Lift Hopping (Dijkstra)

    题意:有一栋100层的大楼(标号为0~99),里面有n个电梯(不超过5个),以及要到达的层数(aid),然后是每个电梯走一层所需的时间, 再n行就是对应每个电梯可以到达的层数,数量不定.然后每装换一次 ...

  4. cshtml 获取session值

    在 cshtml 中,我们如何获取 session 的呢? 首先我们先设置 session 值,我们一般都会在 Controller 设置 session. Session["isAdmin ...

  5. 跟我学: 使用 fireasy 搭建 asp.net core 项目系列之一 —— 开篇

    ==== 目录 ==== 跟我学: 使用 fireasy 搭建 asp.net core 项目系列之一 —— 开篇 跟我学: 使用 fireasy 搭建 asp.net core 项目系列之二 —— ...

  6. Python之路(四十一):通过项目来深入理解tornado

    Tornado之路   引子 与其感慨路难行,不如马上出发 目录 通过项目来深入理解tornado(一):tornado基础回顾 通过项目来深入理解tornado(二):AsyncHttpClient ...

  7. ffmpeg h264转h265

    ffmpeg -i d:\soft\720p.mp4 -c:v libx265 -b:v 5000k d:\soft\myvideo.mp4 这里码率是5000k,编码是h265 h265的解码貌似用 ...

  8. CentOS设置代理, yum, wget

    /etc # vi yum.conf [main] cachedir=/var/cache/yum/basearch/releasever keepcache=0 debuglevel=2 logfi ...

  9. HDU5340 Three Palindromes

    Three Palindromes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  10. 解决Idea项目启动报错:程序包javax.servlet.http不存在

    报错信息 在没有使用maven的时候,web项目从远程仓库获取下以后,起一次启动往往会报错javax.servlet.http程序包找不到,随之而来的java基础包都将不能使用,报错信息如下: 解决方 ...