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. Web 字体的选择和运用

    首先来看一则设计师和前端小白的日常,这是使用 Mac OS 的设计师给的效果图 这是使用 Windows 开发的实际产品页面 我跟你们说,设定字体要按照基本法! (PS: 以上截图不代表网站真实面貌, ...

  2. SVN版本控制图标未显示或显示异常解决方法

    SVN版本控制图标未显示问题解决方法,刚开始遇到这个问题的时候,好苦恼.经过“千辛万苦”的努力,终于得以解决,分享给大家,希望能帮到各位哦! 工具/原料   SVN安装包 方法/步骤     首先安装 ...

  3. PHP 数字补零 固定位数补0

    在处理订单编号的时候,需要固定位数的数字,比如需要固定四位数格式: 1->0001 56->0056 288->0288 1992->1992 可以使用php内置函数str_p ...

  4. solidity学习笔记

    一 pragam solidity ^0.4.23; contract helloword{ string public  name ="hello"; function getN ...

  5. cogs1612. 大话西游

    1612. 大话西游 http://www.cogs.pro/cogs/problem/problem.php?pid=1612 ★★   输入文件:westward.in   输出文件:westwa ...

  6. 封装MySQL的单例,连接数据库并对数据进行增删改查操作

    单例: 一个类只能有一个对象 应用场景:多次请求数据库只需要一个连接对象. 实现:三私一公 1.私有的静态属性用来保存对象的单例2.私有的构造方法用来阻止在类的外部实例化3.私有的__clone阻止在 ...

  7. LuoguP2323 [HNOI2006]公路修建问题 【最小生成树+二分】By cellur925

    题目大意:给你\(n\)个点,\(m\)条边,每条边上有两个权值:一级和二级的.选\(n-1\)条边使这个图连通,并至少有\(k\)个一级边,求花费最多的一条边最小值及方案. 最大值最小,肯定会先想到 ...

  8. EOS 主节点同步

    一.从github克隆主网代码仓库 git clone https://github.com/EOSIO/eos --recursive 二.编译与安装EOS环境 cd ~/eos ./eosio_b ...

  9. 用户角色权限查询添加bug集锦 用户密码加密 MD5 加盐 随机盐 spring的加密bcrypt

    package cn.itcast.encode; import org.apache.commons.lang3.RandomStringUtils; import org.springframew ...

  10. SQL Server权限设置

    常用的几个系统表:(其实是View) sysdatabases,主数据库,服务器上的数据库 sysobjects,每个数据库,所有数据库对象 syscolumns,每个数据库,列 sysprocess ...