如何使用nodejs消费SAP Cloud for Customer上的Web service

发布时间:2021-11-18 16:17:47 作者:柒染
来源:亿速云 阅读:111

这篇文章给大家介绍如何使用nodejs消费SAP Cloud for Customer上的Web service,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

看一个具体例子:C4C里Individual Customers可以维护Social User Profile,在Jerry上面的公众号文章里,正是把微信用户的open ID维护到Social User Profile的SocialMediaAccountUserID字段去,如下图所示。

如何使用nodejs消费SAP Cloud for Customer上的Web service

那么已知一个Social Profile ID,如何用nodejs通过Web Service的方式获得该Profile明细?

首先到Administrator->Input and Output Management->Service Explorer中取得标准的查询Social User profile的web service:

https://<host name>/sap/bc/srt/scs/sap/requestforsocialmediauserprofi

如何使用nodejs消费SAP Cloud for Customer上的Web service

然后使用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和返回的响应内容:

如何使用nodejs消费SAP Cloud for Customer上的Web service

如何使用nodejs消费SAP Cloud for Customer上的Web service

关于如何使用nodejs消费SAP Cloud for Customer上的Web service就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. Idea下SpringCloud2实验(三、Eureka+Fegin服务消费)
  2. Spring-cloud 服务发现与消费(以ribbon为例)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nodejs web service

上一篇:怎么安装percona server 5.7

下一篇:SAP云平台CloudFoundry中的用户如何自定义变量

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》