Auth.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\api\ChuanglanSmsApi;
  5. use app\common\model\MessageRecord;
  6. use think\Facade\Cache;
  7. use app\common\validate\Enterprise;
  8. use think\exception\ValidateException;
  9. use think\facade\Request;
  10. class Auth extends BaseController
  11. {
  12. public function register(){
  13. $msg = "";
  14. if($this->request->isPost()){
  15. $source = intval($this->request['source']);
  16. try {
  17. $result = validate(Enterprise::class)->batch(true)->scene('add')->check(Request::post());
  18. } catch (ValidateException $e){
  19. dd($e->getError());
  20. }
  21. dd($result);
  22. $username = \StrUtil::getRequestDecodeParam($this->request,'username');
  23. $password = \StrUtil::getRequestDecodeParam($this->request,'password');
  24. $name = \StrUtil::getRequestDecodeParam($this->request,'name');
  25. $idCard = \StrUtil::getRequestDecodeParam($this->request,'idCard');
  26. $agentName = \StrUtil::getRequestDecodeParam($this->request,'agentName');
  27. $agentPhone = \StrUtil::getRequestDecodeParam($this->request,'agentPhone');
  28. $verificationCode = \StrUtil::getRequestDecodeParam($this->request,'verificationCode');
  29. $legal = \StrUtil::getRequestDecodeParam($this->request,'legal');
  30. $street = \StrUtil::getRequestDecodeParam($this->request,'street');
  31. $address = \StrUtil::getRequestDecodeParam($this->request,'address');
  32. $type = intval($this->request['type']);
  33. $talentType = \StrUtil::getRequestDecodeParam($this->request,'talentType');
  34. $agentEmail = \StrUtil::getRequestDecodeParam($this->request,'agentEmail');
  35. $ephone = \StrUtil::getRequestDecodeParam($this->request,'ephone');
  36. $industryFieldNew = \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew');
  37. $industryFieldOld = \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld');
  38. $bankCard = \StrUtil::getRequestDecodeParam($this->request,'bankCard');
  39. $bank = \StrUtil::getRequestDecodeParam($this->request,'bank');
  40. $bankNetwork = \StrUtil::getRequestDecodeParam($this->request,'bankNetwork');
  41. }
  42. return view("", ["msg" => $msg]);
  43. }
  44. public function enterpriseRegister()
  45. {
  46. }
  47. public function verificationCode()
  48. {
  49. $phone = $this->request["phone"];
  50. $type = $this->request["type"];
  51. //校验手机号码是否为空
  52. if(\StrUtil::isEmpOrNull($phone)) {
  53. return json(["msg" => "请填写手机号码!"],500);
  54. }
  55. if (\StrUtil::isEmpOrNull($type)) {
  56. return json(["msg" => "请填写手机号码!"],500);
  57. }
  58. //校验手机号码格式是否正确
  59. if(\StrUtil::isMoblePhone($phone)) {
  60. return json(["msg" => "请填写正确的手机号码!"],500);
  61. }
  62. $record = Cache::get("verify_{$type}_{$phone}");
  63. if($record){
  64. $time = time();
  65. if($time - $record <= 60){
  66. return json(["msg" => "一分钟内请勿频繁发送短信!"],500);
  67. }
  68. }
  69. $code = '';
  70. for ($i = 1;$i <= 6;$i++){
  71. $code .= rand(0,9);
  72. }
  73. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  74. $smsapi = new ChuanglanSmsApi();
  75. $result = $smsapi->sendSMS($phone,$template);
  76. $result = json_decode($result,true);
  77. $id = getStringId();
  78. $record_data = [
  79. 'id' => $id,
  80. 'bizId' => $id,
  81. 'type' => 2,
  82. 'smsType' => 1,
  83. 'phone' => $phone,
  84. 'params' => $code,
  85. 'templateCode' => $template,
  86. 'state' => $result['code'] == 0 ? 2 : 3,
  87. 'sendingDate' => date("Y-m-d H:i:s",time()),
  88. 'createTime' => date("Y-m-d H:i:s",time()),
  89. 'msg' => $result['errorMsg']
  90. ];
  91. MessageRecord::create($record_data);
  92. if($result['code'] == 0){
  93. Cache::set("verify_{$type}_{$phone}",time());
  94. return json(["msg" => '验证码发送成功'],200);
  95. }else{
  96. return json(["msg" => '验证码发送失败'],500);
  97. }
  98. }
  99. }