Using time functions

更新时间:
复制 MD 格式

For risk control, you often need to convert request parameters into variables that are more suitable for calculations. For example, an operation time is typically provided as a timestamp. To use this value in risk control calculations, you must first extract the hour. This topic describes how to use a function to convert an operation time into hours.

Create a policy

  1. Go to the Policy Management page and click Create Policy.

  2. Configure the basic parameters for the new policy, including the policy name and description.

  3. Select an Associated Event, and then enter a Policy Name and a Policy Description.

Select a time function

  1. Click the left variable input box. In the 'Event Fields' section, select the timestamp field to convert, such as 'Operation Time'.

  2. Click the 'Operation Time' drop-down list. A list of available functions appears.

  3. Select the 'Extract the hour from a timestamp' function.

Configure the operator and right operand

  1. Select an operator. For example, select 'Equal to' to match a specific time, or 'Number between [a, b]' to match a time range.

  2. Click the 'right operand' field and enter the threshold.

Configure policy outputs

  1. Policy outputs specify the parameters that are returned when a policy is hit. This example shows how to output the hour that corresponds to the operation time.

  2. In the 'Output Variable' section, enter the variable key (operateTime) in the left input box. In the right input box, set the value type to 'Variable', and then select the event field (operateTime) and the 'Extract the hour from a timestamp' function.

Verification

  1. Verify the policy in the Fraud Detection OpenAPI. The following is an example.

  2. Request parameters: {"eventCode":"de_example","operateTime":"1674221439"}.

  3. Response parameters: The hour that corresponds to the timestamp (2023-01-20 21:30:39) is '21'. The value is parsed and returned as expected.