SOAP请求步骤

使用postman构造soap请求的方法:

  1. 将请求方法设置为POST。

  2. 打开Raw编辑器,并将body类型设置为“text / xml”。

  3. 在请求体中,根据需要定义SOAP Envelope,header和body标签。首先给出必要的SOAP Envelope标签,并定义所有的命名空间。给SOAP header和body。应在SOAP体中指定SOAP方法(操作)的名称。
    代码中的实现:

  4. 先在cur-system.js和cur-system-url.js(三个环境都需要配置)里进行配置。

  5. 设置params,一般是这种形式:

    1. 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <soapenv:Header>
      <ns1:CSBHeader soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="http://www.shtel.com.cn/csb/v2/">
      <ServiceName>QueryPointsInfoByCrmId</ServiceName>
      <ServiceVer>1.0</ServiceVer>
      <Consumer>CRMORDWEB</Consumer>
      <RequestTime>2013-12-19T07:53:01.198Z</RequestTime>
      </ns1:CSBHeader>
      </soapenv:Header>
      <soapenv:Body>
      <m:webSearchExchangePoints xmlns:m="http://src.ws.com">
      <ScoreInfo>
      <CrmId>${this.custInfo.custNumber}</CrmId>
      </ScoreInfo>
      </m:webSearchExchangePoints>
      </soapenv:Body>
      </soapenv:Envelope>
  1. 调取接口方法

  2. 获取数据需要先进行格式化

    1
    2
    3
    4
    5
    6
    7
    8
     import xml2js from "xml2js" // 注意:xml2js需要先引入

    curApi.queryPointsInfoByCrmId(param).then(res=>{
    let parser = new xml2js.Parser();
    parser.parseString(res.data,(err,result)=>{
    this.integral = result.ScoreInfo.body[0].PointsUseable[0] // 当前可用积分
    })
    })