| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Service;
- use Illuminate\Support\Facades\Cache;
- class CodeService extends Service
- {
- public function sendCodeToWx($data,$token){
- $cacheKey = "code_" . $token;
- if(! $this->isSubmitlimitation($cacheKey)) return [false,'已发送验证码,请勿重复操作!'];
- //生成验证码
- $code = $this->createCode();
- //发送验证码
- list($status,$msg) = $this->sendCode($code);
- if($status){
- Cache::add($cacheKey,$code,1);
- return [true,''];
- }else{
- return [false,$msg];
- }
- }
- public function createCode(){
- return "123123";
- }
- public function sendCode($code){
- $serivce = new WxService();
- list($status,$msg) = $serivce->getToken();
- if(! $status) return [false,$msg];
- list($status,$msg) = $serivce->sendToWx($msg,$code);
- return [$status,$msg];
- }
- public function isSubmitlimitation($cacheKey){
- if(Cache::has($cacheKey)){
- return false;
- }
- return true;
- }
- }
|