createCode(); //发送验证码到手机 TODO list($status,$msg) = $this->sendCode($code); if(! $status) return [false,$msg]; //成功后 缓存code 60s Cache::add($cacheKey,$code,60); return [true,'']; } //确认验证码 public function sendConfirmCode($data){ if(empty($data['id'])) return [false,'ID不能为空!']; //键名 $cacheKey = self::CACHE_CONFIRM . $data['id']; //限制发送验证码 if(Cache::has($cacheKey)) return [false,'已发送验证码,请勿重复发送!']; //获取验证码 $code = $this->createCode(); //获取金额数据 $finance = (new FinanceService())->getData($data['id']); if(empty($finance)) return [false,'未找到出账数据!']; $send = [ "code"=> $code, "type"=> 2, "account" => $finance['account'], "bankAccount" => $finance['finance_account_name'], "ifsc" => $finance['ifsc'], "amount" => $finance['amount'], ]; $send['sign'] = $this->sign($send); //发送验证码到 list($status,$msg) = $this->sendCode($send); if(! $status) return [false, $msg]; //成功后 缓存code 60s Cache::add($cacheKey,$code,60); return [true,'']; } //加密 public function sign($data){ $str = []; sort($data); foreach ($data as $k=>$v){ $str[] = $k.'='.$v; } $vaild = implode(',',$str).'doTAKtnpiG'; return md5($vaild); } //发送验证码 public function sendCode($send){ $url = "https://api2.indiacashpayment.in/sendTelegramCode"; $result = $this->curlURL($url,$send); if($result['status'] == 201){ return [false, $result['msg']]; } return [true,'']; } //验证登录验证码 public function loginCodeRule($data){ if(empty($data['account'])) return [false,'账号不能为空!']; if(empty($data['code'])) return [false,'验证码不能为空!']; $cacheKey = self::CACHE_LOGIN . $data['account']; if(Cache::has($cacheKey)){ $code = Cache::get($cacheKey); if($code != $data['code']) return [false,'验证码填写错误!']; return [true, '']; } return [false, '验证码不正确!']; } //验证确认验证码 public function ConfirmCodeRule($data){ if(empty($data['code'])) return [false,'验证码不能为空!']; $cacheKey = self::CACHE_CONFIRM . $data['id']; if(Cache::has($cacheKey)){ $code = Cache::get($cacheKey); if($code != $data['code']) return [false,'验证码填写错误!']; return [true, '']; } return [false,'验证码不存在!']; } public function curlURL($url,$data){ $data = json_encode($data); $header[] = "Content-Type:application/json"; $ch=curl_init($url); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_HTTPHEADER,$header); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $response=curl_exec($ch); file_put_contents('charge.txt',$response.PHP_EOL,8); $response=json_decode($response,true); if(curl_errno($ch) ){ sc(curl_error($ch)); } return $response; } //------------------暂时用不到下面------------------------// 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 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; } }