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. 转:AppScan代理扫描app/H5安全测试

    1.首先设置AppScan代理,设置如下:

  2. 4.xpath注入详解

    0x01 简介 XPath注入攻击是指利用XPath 解析器的松散输入和容错特性,能够在 URL.表单或其它信息上附带恶意的XPath 查询代码,以获得权限信息的访问权并更改这些信息.XPath注入发 ...

  3. JavaScript 语言的历史

    说明:此类博客来自以下链接,对原内容做了标注重点知识,此处仅供自己学习参考! 来源:https://wangdoc.com/javascript/basic/introduction.html 1.诞 ...

  4. 网络性能优化GSO/GIO研究

    性能检测工具安装 # curl -O http://downloads.es.net/pub/iperf/iperf-3.0.6.tar.gz # tar axf iperf-3.0.6.tar.gz ...

  5. react-router-dom

    创建: 2019/05/18  安装 npm install react-router-dom --save    

  6. 初步了解XMLHttpRequest对象、http请求的封装

    构造器 var xhr = new XMLHttpRequest() 设置超时时间 xhr.ontimeout= 设置超时时间为 1s 设置超时时间(单位:ms) 0为永不超时 HTTP 请求的状态 ...

  7. Unity命令行打包

    http://www.66acg.com/?post=137 补充 unity编辑器端获取打包命令行自定义参数,这个可以获取到所有打包时的参数 string[] runArgs = System.En ...

  8. Spark系列视频

    大数据生态圈很大,很多开发者都仅仅接触到某个单一产品. Spark 是近年来比较流行的大数据计算框架,系统.平台要想用好Spark 这个产品,需要用到很多的产品. 本视频系列主要是为准备入坑大数据的童 ...

  9. Codeforces 548E(莫反、容斥)

    转化为质数域上的操作,如果用莫反的话,记录因数的cnt. 其实莫反的推式子最后和容斥做法殊途同归了,容斥的系数就是莫比乌斯函数. const int maxn = 2e5 + 5, maxa = 5e ...

  10. win7设置管理员权限

    1.在运行中输入:secpol.msc 2.修改设置权限设置 3.在账户中, 将administrator启用并设置密码 将其他用户取消管理原权限,设置为user权限