Oauth.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Http\Controllers\Core;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\Vendor\BaiduAi\FaceService;
  6. class Oauth extends Controller
  7. {
  8. public function faceToken(Request $request)
  9. {
  10. $url = "https://api-cn.faceplusplus.com/facepp/v3/detect";
  11. $data = array(
  12. 'api_key' => 'z_TyHj53JaD8JXVLXVTPFpGqKwZVoWjv',
  13. 'api_secret' => 'KbEfAb7eMm828ViP4_Y1oTrm4KG5_qS-',
  14. );
  15. $data = array_merge($data, $request->toArray());
  16. $response = \Curl::to($url)->withData($data)->post();
  17. return $response;
  18. }
  19. public function match(Request $request)
  20. {
  21. $this->validate($request, [
  22. 'liveness_image' => 'required',
  23. 'check_image' => 'required'
  24. ]);
  25. $fs = new FaceService();
  26. $images = array(
  27. [
  28. 'image' => $request->post('liveness_image'),
  29. 'image_type' => 'URL',
  30. 'face_type' => 'LIVE',
  31. 'quality_control' => 'NONE',
  32. 'liveness_control' => 'LOW'
  33. ],
  34. [
  35. 'image' => $request->post('check_image'),
  36. 'image_type' => 'URL',
  37. 'face_type' => 'LIVE',
  38. 'quality_control' => 'NONE',
  39. 'liveness_control' => 'NONE'
  40. ]
  41. );
  42. $data = $fs->match($images);
  43. dump($data);
  44. }
  45. public function faceverify(Request $request)
  46. {
  47. $this->validate($request, [
  48. 'image' => 'required'
  49. ]);
  50. $fs = new FaceService();
  51. $images = array(
  52. [
  53. 'image' => $request->post('image'),
  54. 'image_type' => 'URL',
  55. 'face_field' => 'occlusion,blur,completeness',
  56. ]
  57. );
  58. $data = $fs->faceverify($images);
  59. dump($data);
  60. }
  61. public function sendVerifyCode(Request $request)
  62. {
  63. $phone = $request->input('phone');
  64. $code = rand(1000, 9999);
  65. $result = \ChuanglanSms::sendSMS($phone, "【无邪科技】您的短信验证码为:{$code},若非本人操作请忽略。");
  66. if (isset($result['code']) && $result['code'] == '0') {
  67. \Cache::put("smsverifycode:{$phone}", $code, 1);
  68. return [
  69. 'code' => 200,
  70. 'message' => 'Success',
  71. ];
  72. } else {
  73. return [
  74. 'code' => 401,
  75. 'message' => '发送频繁',
  76. ];
  77. }
  78. }
  79. /**
  80. * @param Request $request
  81. * @return mixed
  82. */
  83. public function checkVerifyCode(Request $request)
  84. {
  85. $phone = $request->input('phone');
  86. $code = $request->input('code');
  87. if (\Cache::get("smsverifycode:{$phone}") == $code) {
  88. return [
  89. 'code' => 200,
  90. 'message' => '验证成功',
  91. ];
  92. }
  93. return [
  94. 'code' => 401,
  95. 'message' => '验证码错误',
  96. ];
  97. }
  98. }