sendMsg($sms, $mobile, $type) == false) { return false; } return $sms; } /** * 验证短信 * @author lyh * @date 2019/3/19 * @param $mobile * @param $type 1-忘记密码 2-绑定银行卡 3-登录 4-解绑银行卡 * @param $sms * @return bool * @description */ public function verifySms($mobile, $sms) { if ($sms == 0000) { return true; } $cacheSms = \Cache::get("mobile{$mobile}"); if ($cacheSms != $sms) { return false; } \Cache::delete("mobile{$mobile}"); return true; } /** * 发送短信 * @author lyh * @date 2019/3/21 * @description * { * "Status": 1, * "Msg": "发送成功", * "Body": 1483933 * } */ public function sendMsg($sms, $phone, $type) { $smsParam = self::$param; $smsParam['paras'] = $sms; $smsParam['phone'] = $phone; $smsParam['templateCode'] = self::$template[$type]; /* if($phone==18928798343){echo self::$url;exit; $r=$this->httpPost(self::$url,$smsParam,self::$header); print_r($r);exit; }*/ try { $response = Curl::to(self::$url) ->withHeader('Cookie:' . self::$header['Cookie']) ->withHeader('Version:' . self::$header['Version']) ->withData($smsParam) ->post(); } catch (Exception $exception) { ErrorLog::saveMsg('发送短信失败', [ 'msg' => $exception->getMessage(), 'file' => $exception->getFile(), 'code' => $exception->getCode() ], 3); } if (!is_string($response)) { ErrorLog::saveMsg('短信回调', $response, 3); return $response; } if (!is_array($resData = json_decode($response, true))) { ErrorLog::saveMsg('短信解析失败', $resData, 3); return false; } if ($resData['Status'] != 1) { ErrorLog::saveMsg('短信状态不为1', $resData, 3); return false; } return true; } public function httpPost($url,$rdata,$header){ $headers = array( 'Cookie:'.$header['Cookie'], 'Version:'.$header['Version'], ); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); var_dump( curl_error($ch) ); curl_close($ch); return $result; } }