CodeService.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Service;
  3. use Illuminate\Support\Facades\Cache;
  4. class CodeService extends Service
  5. {
  6. public function sendCodeToWx($data,$token){
  7. $cacheKey = "code_" . $token;
  8. if(! $this->isSubmitlimitation($cacheKey)) return [false,'已发送验证码,请勿重复操作!'];
  9. //生成验证码
  10. $code = $this->createCode();
  11. //发送验证码
  12. list($status,$msg) = $this->sendCode($code);
  13. if($status){
  14. Cache::add($cacheKey,$code,1);
  15. return [true,''];
  16. }else{
  17. return [false,$msg];
  18. }
  19. }
  20. public function createCode(){
  21. return "123123";
  22. }
  23. public function sendCode($code){
  24. return [true,''];
  25. }
  26. //微信公众号发送 目前发现不行
  27. // public function sendCode($code){
  28. // $serivce = new WxService();
  29. // list($status,$msg) = $serivce->getToken();
  30. // if(! $status) return [false,$msg];
  31. //
  32. // list($status,$msg) = $serivce->sendToWx($msg,$code);
  33. // return [$status,$msg];
  34. // }
  35. public function isSubmitlimitation($cacheKey){
  36. if(Cache::has($cacheKey)){
  37. return false;
  38. }
  39. return true;
  40. }
  41. }