Auth.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\api\ChuanglanSmsApi;
  5. use app\common\api\EnterpriseApi;
  6. use app\common\model\MessageRecord;
  7. use app\common\model\TalentChecklog;
  8. use think\facade\Cache;
  9. use app\common\validate\Enterprise;
  10. use think\exception\ValidateException;
  11. use think\facade\Request;
  12. use app\common\api\UploadApi;
  13. class Auth extends BaseController {
  14. public function register() {
  15. $msg = "";
  16. if ($this->request->isPost()) {
  17. $source = 3; //intval($this->request['source']);
  18. $response_object = new \StdClass();
  19. $special = \StrUtil::getRequestDecodeParam($this->request, 'special');
  20. $data = [
  21. 'username' => \StrUtil::getRequestDecodeParam($this->request, 'username'),
  22. 'password' => \StrUtil::getRequestDecodeParam($this->request, 'password'),
  23. 're_password' => \StrUtil::getRequestDecodeParam($this->request, 're_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. 'agencyType' => intval($this->request['agencyType']),
  34. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseTag'),
  35. 'organizationTag' => \StrUtil::getRequestDecodeParam($this->request, 'organizationTag'),
  36. 'institutionTag' => \StrUtil::getRequestDecodeParam($this->request, 'institutionTag'),
  37. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseType'),
  38. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request, 'agentEmail'),
  39. 'ephone' => \StrUtil::getRequestDecodeParam($this->request, 'ephone'),
  40. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldNew'),
  41. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldOld'),
  42. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request, 'bankCard'),
  43. 'bank' => \StrUtil::getRequestDecodeParam($this->request, 'bank'),
  44. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request, 'bankNetwork')
  45. ];
  46. try {
  47. if (stripos($data['name'], "(")) {
  48. $data['name'] = str_replace('(', '(', $data['name']);
  49. }
  50. if (stripos($data['name'], ")")) {
  51. $data['name'] = str_replace(')', ')', $data['name']);
  52. }
  53. $files = $this->request->file();
  54. switch ($special) {
  55. case 'qiye':
  56. if ($data['type'] == 1) {
  57. if ($data["agencyType"] == 1) {
  58. validate(Enterprise::class)->batch(true)->scene('add')->check($data);
  59. if (!array_key_exists('domainImg', $files) || $files['domainImg'] == '') {
  60. $response_object->code = 500;
  61. $response_object->msg = '行业领域佐证材料不能为空';
  62. return \StrUtil::back($response_object, "Register.epCallBack");
  63. }
  64. } else {
  65. validate(Enterprise::class)->batch(true)->scene('add2')->check($data);
  66. }
  67. $checkTypes = ["guishang", "gaoxinjishu", "zhuanjingtexin"];
  68. if (in_array($data["enterpriseType"], $checkTypes) && (!array_key_exists('typeImg', $files) || $files['typeImg'] == '')) {
  69. $response_object->code = 500;
  70. $response_object->msg = '规上、高新技术、专精特新企业需要上传佐证材料';
  71. return \StrUtil::back($response_object, "Register.epCallBack");
  72. }
  73. } else {
  74. validate(Enterprise::class)->batch(true)->scene('jc_add')->check($data); //集成电路
  75. }
  76. if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {
  77. $response_object->code = 500;
  78. $response_object->msg = '营业执照不能为空';
  79. return \StrUtil::back($response_object, "Register.epCallBack");
  80. }
  81. if (!array_key_exists('bankImg', $files) || $files['bankImg'] == '') {
  82. $response_object->code = 500;
  83. $response_object->msg = '开户许可证/基本存款账户信息不能为空';
  84. return \StrUtil::back($response_object, "Register.epCallBack");
  85. }
  86. if (!array_key_exists('beian', $files) || $files['beian'] == '') {
  87. $response_object->code = 500;
  88. $response_object->msg = '人才联络员备案表不能为空';
  89. return \StrUtil::back($response_object, "Register.epCallBack");
  90. }
  91. $data['special'] = 0;
  92. break;
  93. case 'minfei':
  94. $data['type'] = 1;
  95. if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {
  96. $response_object->code = 500;
  97. $response_object->msg = '营业执照不能为空';
  98. return \StrUtil::back($response_object, "Register.epCallBack");
  99. }
  100. if (!array_key_exists('bankImg', $files) || $files['bankImg'] == '') {
  101. $response_object->code = 500;
  102. $response_object->msg = '开户许可证/基本存款账户信息不能为空';
  103. return \StrUtil::back($response_object, "Register.epCallBack");
  104. }
  105. if (!array_key_exists('beian', $files) || $files['beian'] == '') {
  106. $response_object->code = 500;
  107. $response_object->msg = '人才联络员备案表不能为空';
  108. return \StrUtil::back($response_object, "Register.epCallBack");
  109. }
  110. $data['special'] = 3;
  111. break;
  112. case 'shiye':
  113. $data['type'] = 1;
  114. validate(Enterprise::class)->batch(true)->scene('sy_add')->check($data); //事业单位
  115. if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {
  116. $response_object->code = 500;
  117. $response_object->msg = '法人代表证或批文不能为空';
  118. return \StrUtil::back($response_object, "Register.epCallBack");
  119. }
  120. $data['special'] = 1;
  121. break;
  122. }
  123. //检验验证码
  124. $codeResult = MessageRecord::where('smsType', 1)->where('phone', $data['agentPhone'])->order('createTime', 'desc')->find();
  125. if (!$codeResult) {
  126. $response_object->code = 500;
  127. $response_object->msg = '请先发送验证码';
  128. return \StrUtil::back($response_object, "Register.epCallBack");
  129. }
  130. if (time() - strtotime($codeResult['createTime']) > 300) {
  131. $response_object->code = 500;
  132. $response_object->msg = '验证码过期,请重新发送';
  133. return \StrUtil::back($response_object, "Register.epCallBack");
  134. }
  135. $uploadapi = new UploadApi();
  136. //检验附件 营业执照
  137. if (array_key_exists('imgurl', $files)) {
  138. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
  139. if ($upload_result->code == 500) {
  140. return \StrUtil::back($upload_result, "Register.epCallBack");
  141. }
  142. $imgurl = $upload_result->filepath;
  143. } else {
  144. $imgurl = '';
  145. }
  146. //检验附件 开户许可证
  147. if (array_key_exists('bankImg', $files)) {
  148. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
  149. if ($upload_result1->code == 500) {
  150. return \StrUtil::back($upload_result1, "Register.epCallBack");
  151. }
  152. $bankImg = $upload_result1->filepath;
  153. } else {
  154. $bankImg = '';
  155. }
  156. //检验附件 行业领域佐证材料
  157. if (array_key_exists('domainImg', $files)) {
  158. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
  159. if ($upload_result2->code == 500) {
  160. return \StrUtil::back($upload_result2, "Register.epCallBack");
  161. }
  162. $domainImg = $upload_result2->filepath;
  163. } else {
  164. $domainImg = '';
  165. }
  166. //检验附件 行业领域佐证材料
  167. if (array_key_exists('typeImg', $files)) {
  168. $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
  169. if ($upload_result4->code == 500) {
  170. return \StrUtil::back($upload_result4, "Register.epCallBack");
  171. }
  172. $typeImg = $upload_result4->filepath;
  173. } else {
  174. $typeImg = '';
  175. }
  176. //检验附件 人才联络员备案表
  177. if (array_key_exists('beian', $files)) {
  178. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
  179. if ($upload_result3->code == 500) {
  180. return \StrUtil::back($upload_result3, "Register.epCallBack");
  181. }
  182. $beian = $upload_result3->filepath;
  183. } else {
  184. $beian = '';
  185. }
  186. $data['id'] = getStringId();
  187. $data['password'] = hash('md5', $data['password']);
  188. $data['source'] = $source;
  189. $data['imgurl'] = $imgurl;
  190. $data['bankImg'] = $bankImg;
  191. $data['domainImg'] = $domainImg;
  192. $data["typeImg"] = $typeImg;
  193. $data['beian'] = $beian;
  194. $data['createTime'] = date("Y-m-d H:i:s", time());
  195. $data['updateTime'] = date("Y-m-d H:i:s", time());
  196. $data['active'] = 1;
  197. $data['checkState'] = 1;
  198. \app\common\model\Enterprise::create($data);
  199. TalentChecklog::create([
  200. 'id' => getStringId(),
  201. 'mainId' => $data['id'],
  202. 'type' => 10,
  203. 'typeField' => null,
  204. 'active' => 1,
  205. 'state' => 1,
  206. 'step' => 100,
  207. 'stateChange' => '用户提交',
  208. 'description' => '用户注册',
  209. 'createTime' => date("Y-m-d H:i:s", time()),
  210. 'createUser' => '用户'
  211. ]);
  212. $response_object->code = 200;
  213. $response_object->msg = '注册成功';
  214. return \StrUtil::back($response_object, "Register.epCallBack");
  215. } catch (ValidateException $e) {
  216. $error = $e->getError();
  217. $response_object->code = 500;
  218. $response_object->msg = array_pop($error);
  219. return \StrUtil::back($response_object, "Register.epCallBack");
  220. }
  221. }
  222. return view("", ["msg" => $msg]);
  223. }
  224. public function enterprise_edit() {
  225. $temp = session('temp');
  226. if (empty($temp)) {
  227. return redirect("/");
  228. }
  229. $ep = EnterpriseApi::getOne(session('temp')['uid']);
  230. if ($this->request->isPost()) {
  231. $response_object = new \StdClass();
  232. $data = [
  233. 'name' => \StrUtil::getRequestDecodeParam($this->request, 'name'), //单位名称
  234. 'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'idCard'), //统一社会信用代码
  235. 'agentName' => \StrUtil::getRequestDecodeParam($this->request, 'agentName'), //人才联络员
  236. 'legal' => \StrUtil::getRequestDecodeParam($this->request, 'legal'), //法人
  237. 'street' => \StrUtil::getRequestDecodeParam($this->request, 'street'), //镇街
  238. 'address' => \StrUtil::getRequestDecodeParam($this->request, 'address'), //地址
  239. 'type' => intval($this->request['type']),
  240. 'agencyType' => intval($this->request['agencyType']),
  241. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseTag'), //单位标签
  242. 'organizationTag' => \StrUtil::getRequestDecodeParam($this->request, 'organizationTag'), //机构标签
  243. 'institutionTag' => \StrUtil::getRequestDecodeParam($this->request, 'institutionTag'), //事业单位标签
  244. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseType'), //单位类型
  245. 'agentPhone' => \StrUtil::getRequestDecodeParam($this->request, 'agentPhone'), //手机
  246. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request, 'agentEmail'), //邮箱
  247. 'ephone' => \StrUtil::getRequestDecodeParam($this->request, 'ephone'), //单位电话
  248. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldNew'), //产业领域
  249. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldOld'), //行业领域
  250. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request, 'bankCard'), //银行
  251. 'bank' => \StrUtil::getRequestDecodeParam($this->request, 'bank'), //开户行
  252. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request, 'bankNetwork')//网点
  253. ];
  254. $files = $this->request->file();
  255. if ($files) {
  256. $uploadapi = new UploadApi();
  257. if (array_key_exists('imgurl', $files)) {
  258. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
  259. if ($upload_result->code == 500) {
  260. return \StrUtil::back($upload_result, "Register.epCallBack");
  261. }
  262. $data["imgurl"] = $upload_result->filepath;
  263. }
  264. //检验附件 开户许可证
  265. if (array_key_exists('bankImg', $files)) {
  266. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
  267. if ($upload_result1->code == 500) {
  268. return \StrUtil::back($upload_result1, "Register.epCallBack");
  269. }
  270. $data["bankImg"] = $upload_result1->filepath;
  271. }
  272. //检验附件 行业领域佐证材料
  273. if (array_key_exists('domainImg', $files)) {
  274. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
  275. if ($upload_result2->code == 500) {
  276. return \StrUtil::back($upload_result2, "Register.epCallBack");
  277. }
  278. $data["domainImg"] = $upload_result2->filepath;
  279. }
  280. //检验附件 行业领域佐证材料
  281. if (array_key_exists('typeImg', $files)) {
  282. $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
  283. if ($upload_result4->code == 500) {
  284. return \StrUtil::back($upload_result4, "Register.epCallBack");
  285. }
  286. $data["typeImg"] = $upload_result4->filepath;
  287. }
  288. //检验附件 人才联络员备案表
  289. if (array_key_exists('beian', $files)) {
  290. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
  291. if ($upload_result3->code == 500) {
  292. return \StrUtil::back($upload_result3, "Register.epCallBack");
  293. }
  294. $data["beian"] = $upload_result3->filepath;
  295. }
  296. }
  297. try {
  298. if (stripos($data['name'], "(")) {
  299. $data['name'] = str_replace('(', '(', $data['name']);
  300. }
  301. if (stripos($data['name'], ")")) {
  302. $data['name'] = str_replace(')', ')', $data['name']);
  303. }
  304. $data['id'] = $ep->id;
  305. if ($ep->special == 0) {
  306. if ($ep->type == 1) {
  307. if ($ep->agencyType == 1) {
  308. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change')->check($data);
  309. if (!$data["domainImg"] && !$ep->domainImg) {
  310. $response_object->code = 500;
  311. $response_object->msg = "行业领域佐证材料不能为空";
  312. return \StrUtil::back($response_object, "Register.epCallBack");
  313. }
  314. } else {
  315. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change2')->check($data);
  316. }
  317. $checkTypes = ["guishang", "gaoxinjishu", "zhuanjingtexin"];
  318. if (in_array($data["enterpriseType"], $checkTypes) && (!$data["typeImg"] && !$ep->typeImg)) {
  319. $response_object->code = 500;
  320. $response_object->msg = '规上、高新技术、专精特新企业需要上传佐证材料';
  321. return \StrUtil::back($response_object, "Register.epCallBack");
  322. }
  323. } else {
  324. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('jc_change')->check($data);
  325. }
  326. if (!$data["imgurl"] && !$ep->imgurl) {
  327. $response_object->code = 500;
  328. $response_object->msg = '营业执照不能为空';
  329. return \StrUtil::back($response_object, "Register.epCallBack");
  330. }
  331. if (!$data["bankImg"] && !$ep->bankImg) {
  332. $response_object->code = 500;
  333. $response_object->msg = '开户许可证/基本存款账户信息不能为空';
  334. return \StrUtil::back($response_object, "Register.epCallBack");
  335. }
  336. if (!$data["beian"] && !$ep->beian) {
  337. $response_object->code = 500;
  338. $response_object->msg = '人才联络员备案表不能为空';
  339. return \StrUtil::back($response_object, "Register.epCallBack");
  340. }
  341. } else {
  342. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('sy_change')->check($data);
  343. if (!$data["imgurl"] && !$ep->imgurl) {
  344. $response_object->code = 500;
  345. $response_object->msg = '法人代表证或批文不能为空';
  346. return \StrUtil::back($response_object, "Register.epCallBack");
  347. }
  348. }
  349. unset($data["agentPhone"]);
  350. $data['checkState'] = 1;
  351. $ep->update($data);
  352. $response_object->code = 200;
  353. $response_object->msg = '修改成功';
  354. return \StrUtil::back($response_object, "Register.epCallBack");
  355. } catch (ValidateException $e) {
  356. $error = $e->getError();
  357. $response_object->code = 500;
  358. $response_object->msg = array_pop($error);
  359. return \StrUtil::back($response_object, "Register.epCallBack");
  360. }
  361. }
  362. if ($ep->imgurl) {
  363. $pathinfo = pathinfo($ep->imgurl);
  364. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  365. $ep->imgurl_is_img = 1;
  366. }
  367. }
  368. if ($ep->domainImg) {
  369. $pathinfo = pathinfo($ep->domainImg);
  370. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  371. $ep->domainImg_is_img = 1;
  372. }
  373. }
  374. if ($ep->typeImg) {
  375. $pathinfo = pathinfo($ep->typeImg);
  376. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  377. $ep->typeImg_is_img = 1;
  378. }
  379. }
  380. if ($ep->beian) {
  381. $pathinfo = pathinfo($ep->beian);
  382. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  383. $ep->beian_is_img = 1;
  384. }
  385. }
  386. if ($ep->bankImg) {
  387. $pathinfo = pathinfo($ep->bankImg);
  388. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  389. $ep->bankImg_is_img = 1;
  390. }
  391. }
  392. $msg = session('temp')['msg'];
  393. return view("", ['msg' => $msg, 'ep' => $ep]);
  394. }
  395. public function findBackPassword() {
  396. $type = intval($this->request['type']);
  397. if (\StrUtil::isEmpOrNull($type)) {
  398. return json(['msg' => '请选择账号类型', 'code' => 500]);
  399. }
  400. $username = \StrUtil::getRequestDecodeParam($this->request, 'username');
  401. if (\StrUtil::isEmpOrNull($username)) {
  402. return json(['msg' => '请填写账号', 'code' => 500]);
  403. }
  404. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  405. if (\StrUtil::isEmpOrNull($password)) {
  406. return json(['msg' => '请填写新密码', 'code' => 500]);
  407. }
  408. $rePassword = \StrUtil::getRequestDecodeParam($this->request, 'rePassword');
  409. if (\StrUtil::isEmpOrNull($rePassword)) {
  410. return json(['msg' => '请填写重复新密码', 'code' => 500]);
  411. }
  412. if ($password != $rePassword) {
  413. return json(['msg' => '两次密码填写不一致', 'code' => 500]);
  414. }
  415. if (!preg_match("/^(?=.*\d)(?=.*[A-Za-z]).{8,}$/", $password)) {
  416. return json(['msg' => '密码必须包含字母、数字、特殊字符且长度超过8位', 'code' => 500]);
  417. }
  418. $phone = \StrUtil::getRequestDecodeParam($this->request, 'phone');
  419. if (\StrUtil::isEmpOrNull($phone)) {
  420. return json(['msg' => '请填写手机号', 'code' => 500]);
  421. }
  422. $verificationCode = \StrUtil::getRequestDecodeParam($this->request, 'verificationCode');
  423. if (\StrUtil::isEmpOrNull($verificationCode)) {
  424. return json(['msg' => '请填写验证码', 'code' => 500]);
  425. }
  426. //检验验证码
  427. $codeResult = MessageRecord::where('smsType', 1)->where('phone', $phone)->order('createTime', 'desc')->find();
  428. if (!$codeResult || (time() - strtotime($codeResult['sendingDate']) > 300)) {
  429. return json(['msg' => '请先发送验证码', 'code' => 500]);
  430. }
  431. if ($codeResult['params'] != $verificationCode) {
  432. return json(['msg' => '验证码不正确', 'code' => 500]);
  433. }
  434. $password = hash('md5', $password);
  435. if ($type == 1) {
  436. $count = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->count();
  437. if ($count == 0) {
  438. return json(['msg' => '未找到相关账号,请仔细核对账号及手机号信息!', 'code' => 500]);
  439. }
  440. if ($count > 1) {
  441. return json(['msg' => '找到多个账户,请联系相关单位处理!', 'code' => 500]);
  442. }
  443. $ep = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->find();
  444. $ep->password = $password;
  445. $ep->save();
  446. } else {
  447. //个人账户找回密码TODO
  448. }
  449. return json(['msg' => '找回密码成功!', 'code' => 200]);
  450. }
  451. public function verificationCode() {
  452. $phone = $this->request["phone"];
  453. $type = $this->request["type"];
  454. //校验手机号码是否为空
  455. if (\StrUtil::isEmpOrNull($phone)) {
  456. return json(["msg" => "请填写手机号码!"], 500);
  457. }
  458. if (\StrUtil::isEmpOrNull($type)) {
  459. return json(["msg" => "请填写手机号码!"], 500);
  460. }
  461. //校验手机号码格式是否正确
  462. if (\StrUtil::isMoblePhone($phone)) {
  463. return json(["msg" => "请填写正确的手机号码!"], 500);
  464. }
  465. $record = Cache::get("verify_{$type}_{$phone}");
  466. if ($record) {
  467. $time = time();
  468. if ($time - $record <= 60) {
  469. return json(["msg" => "一分钟内请勿频繁发送短信!"], 500);
  470. }
  471. }
  472. $code = '';
  473. for ($i = 1; $i <= 6; $i++) {
  474. $code .= rand(0, 9);
  475. }
  476. //$code = 999999;
  477. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  478. $smsapi = new ChuanglanSmsApi();
  479. $result = $smsapi->sendSMS($phone, $template);
  480. $result = json_decode($result, true);
  481. $id = getStringId();
  482. $record_data = [
  483. 'id' => $id,
  484. 'bizId' => $id,
  485. 'type' => 2,
  486. 'smsType' => 1,
  487. 'phone' => $phone,
  488. 'params' => $code,
  489. 'templateCode' => $template,
  490. 'state' => $result['code'] == 0 ? 2 : 3,
  491. 'sendingDate' => date("Y-m-d H:i:s", time()),
  492. 'createTime' => date("Y-m-d H:i:s", time()),
  493. 'msg' => $result['errorMsg']
  494. ];
  495. MessageRecord::create($record_data);
  496. if ($result['code'] == 0) {
  497. Cache::set("verify_{$type}_{$phone}", time());
  498. return json(["msg" => '验证码发送成功'], 200);
  499. } else {
  500. return json(["msg" => '验证码发送失败'], 500);
  501. }
  502. }
  503. }