CtuDemo.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dingxiang-inc
  5. * Date: 2017/8/21
  6. * Time: 上午10:35
  7. */
  8. include "./CtuClient.php";
  9. $url = "http://sec.dingxiang-inc.com/ctu/event.do";
  10. $appId = "appId";
  11. $appSecret = "appSecret";
  12. // 时区
  13. ini_set('date.timezone','Asia/Shanghai');
  14. // 构造请求参数
  15. $request = new CtuClient($url, $appId, $appSecret);
  16. $reqJsonString = json_encode($request, JSON_UNESCAPED_UNICODE);
  17. $ctuRequest = new CtuRequest();
  18. // $data 具体的业务参数,根据业务实际情况传入
  19. $data = array (
  20. "const_id" => "egUbLWXKgiPKBMmcwbZsF1PqoflWOyhKLIhAzw9X1",
  21. "user_id" => "438699324",
  22. "phone_number" => "15958004277",
  23. "source" => 2,
  24. "activity_id" => 1,
  25. "ext_prov_name" => "北京市",
  26. "register_date" => date('Y-m-d H:i:s'),
  27. "ext_answer_end_date" => date('Y-m-d H:i:s'),
  28. "ext_answer_start_date" => date('Y-m-d H:i:s'),
  29. "ext_user_level" => 5,
  30. "ext_open_id" => "58483ea3174dde1f",
  31. "ip" => "127.0.0.1");
  32. // $eventCode 事件code
  33. $ctuRequest -> eventCode = "event_code";
  34. $ctuRequest -> flag = "activity_" . time();
  35. $ctuRequest -> data = $data;
  36. // 请求超时时间,单位秒
  37. $timeout = 2;
  38. //调用风控引擎
  39. $responseData = $request -> checkRisk($ctuRequest, $timeout);
  40. echo "风险引擎返回结果:" . $responseData. "\n";
  41. $jsonResult = json_decode($responseData, true);
  42. $result = $jsonResult['result']["riskLevel"];
  43. // ... 根据不同风险做出相关处理
  44. if ($result == "ACCEPT") {
  45. // 无风险,建议放过
  46. echo "风险结果:无风险,建议放过" . "\n";
  47. } else if ($result == "REVIEW") {
  48. // 不确定,需要进一步审核
  49. echo "风险结果:不确定,需要进一步审核" . "\n";
  50. } else if ($result == "REJECT") {
  51. // 有风险,建议拒绝
  52. echo "风险结果:有风险,建议拒绝" . "\n";
  53. }
  54. ?>