Sample Code

The following takes GetDataSourceList interface as an example,to introduce how to initiate a signed request through the SDK in two ways.

  • First method (recommended)

    1. Instantiate RequestHelper object in PwC.Api.Sdk.

      RequestHelper requestHelper = new RequestHelper(appKey, securityKey, domain);
      
    2. Use PostAsync to initiate the request and obtain the results.

       //
       var response = 
        await requestHelper.PostAsync("/tenant/appCode/customapi/GetDataSourceList",
       JsonConvert.DeserializeObject<Dictionary<string, object>>("{\"State\":-1}"));
      
  • Second method

    1. Instantiate RequestHelper object in PwC.Api.Sdk.

      //
      RequestHelper requestHelper = new RequestHelper(appKey, securityKey, domain);
      
    2. Instantiate ISigner

      //
      ISigner signer = new HmacSHA256();
      
    3. Get timestamp

      //
      string timestamp = Common.GetDateTotalMilliseconds().ToString();
      
    4. Get random number

      //
      string nonce = Common.GetNonce();
      
    5. Get the original signature string

      //
      string sourceText = signer.GetStringToSign(requestData, appKey, securityKey, nonce, timestamp);
      
    6. Get signature

      //
      string sign = signer.GetSign(sourceText);
      
    7. Use PostAsync to initiate a request and get the result

      //
      var response = 
      await requestHelper.PostAsync("/tenant/appCode/customapi/GetDataSourceList", 
      JsonConvert.DeserializeObject<Dictionary<string, object>>("{\"State\":-1}"), sign, nonce, timestamp);
      
© Digital Maker Product Team all right reserved,powered by Gitbook该文件修订时间: 2023-02-02 10:40:12

results matching ""

    No results matching ""