CommonController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Http\Controllers\AdminController;
  4. use App\Servers\System\BaiduServer;
  5. use App\Servers\System\CommonServer;
  6. use App\Servers\System\SmsServer;
  7. use Illuminate\Support\Facades\Storage;
  8. class CommonController extends AdminController
  9. {
  10. /**
  11. * 发送短信
  12. * @return \Illuminate\Http\JsonResponse
  13. * @throws \End01here\EasySms\Exceptions\CodeErrorException
  14. * @throws \End01here\EasySms\Exceptions\GatewayErrorException
  15. * @throws \End01here\EasySms\Exceptions\MessageException
  16. */
  17. function sendSms()
  18. {
  19. $phone = request()->input('phone', '');
  20. $send_type = request()->input('send_type', 'default');
  21. if (empty($phone)) {
  22. return $this->apiResponseError('请输入手机号码');
  23. }
  24. $send_server = SmsServer::creatServer();
  25. $ret = $send_server->sendCode($phone, $send_type);
  26. if (!$ret) {
  27. return $this->apiResponseError($send_server->getErrorMsg() ?: '短信发送失败');
  28. } else {
  29. return $this->apiResponseSuccess('短信发送成功');
  30. }
  31. }
  32. /**
  33. * 获取身份证orc识别
  34. * @return \Illuminate\Http\JsonResponse
  35. */
  36. function getCardFrontOrc()
  37. {
  38. $commonServer = CommonServer::creatServer();
  39. $id_card = $commonServer->filtrationStr('id_card');//身份证正面
  40. if (empty($id_card)) return $this->apiResponseError( '请上传身份证正面');
  41. $result = BaiduServer::creatServer()->idCard($id_card);
  42. if ($result['code'] == 1){
  43. $id_number = empty($result['data']['公民身份号码']['words']) ? '' : $result['data']['公民身份号码']['words'];
  44. $name = empty($result['data']['姓名']['words']) ? '' : $result['data']['姓名']['words'];
  45. $sex = empty($result['data']['性别']['words']) ? '' : $result['data']['性别']['words'];
  46. $birthday = empty($result['data']['出生']['words']) ? '' : $result['data']['出生']['words'];
  47. if ($birthday) {
  48. $birthday = substr($birthday, 0, 4) . '-' . substr($birthday, 4, 2) . '-' . substr($birthday, 6, 2);
  49. }
  50. $newData = [
  51. 'name' => $name,
  52. 'birthday' => $birthday,
  53. 'sex' => $sex,
  54. 'id_number' => $id_number,
  55. ];
  56. }else{
  57. $newData = [
  58. 'name' => '',
  59. 'birthday' => '',
  60. 'sex' => '',
  61. 'id_number' => '',
  62. ];
  63. }
  64. return $this->apiResponseSuccess('获取成功', $newData);
  65. }
  66. /**
  67. * 获取营业执照orc识别
  68. * @return \Illuminate\Http\JsonResponse
  69. */
  70. function getLicenseOrc()
  71. {
  72. $commonServer = CommonServer::creatServer();
  73. $license_img = $commonServer->filtrationStr('license_img');//营业执照
  74. if (empty($license_img)) return $this->apiResponseError( '请上传营业执照');
  75. $result = BaiduServer::creatServer()->businessLicense($license_img);
  76. if ($result['code'] == 1){
  77. return $this->apiResponseSuccess($result['msg'],$result['data']);
  78. }else{
  79. return $this->apiResponseError($result['msg']);
  80. }
  81. }
  82. /**
  83. * 获取阿里云临时权限
  84. * @return \Illuminate\Http\JsonResponse
  85. */
  86. function getAliSts()
  87. {
  88. $ret = CommonServer::creatServer()->getAliSts();
  89. if (empty($ret['code'])) {
  90. return $this->apiResponseError($ret['msg']);
  91. } else {
  92. return $this->apiResponseSuccess($ret['msg'], $ret['data']);
  93. }
  94. }
  95. /**
  96. * 获取腾讯云临时权限
  97. * @return \Illuminate\Http\JsonResponse
  98. */
  99. function getTxySts()
  100. {
  101. $ret = CommonServer::creatServer()->getTxySts();
  102. if (empty($ret['code'])) {
  103. return $this->apiResponseError($ret['msg']);
  104. } else {
  105. return $this->apiResponseSuccess($ret['msg'], $ret['data']);
  106. }
  107. }
  108. }