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

42次阅读
没有评论

共计 2356 个字符,预计需要花费 6 分钟才能阅读完成。

这篇文章给大家介绍如何使用 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 就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计2356字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)