<?php
/*
 本代码由 口号帮 创建
 创建时间 2019-05-08 16:22:09
 技术支持 口号帮 
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace App\Traits;use App\Models\SmsRecord;use App\Models\SmsSetting;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Redis;use Illuminate\Support\Facades\Session;trait SendMsg{protected $messageCount=10;protected $encode='UTF-8';protected $accesskey='';protected $secret='';protected $msg_url="http://sms.kouhaobang.com/api/send/do";public function setCodeRedis($phone,$code,$verifyType){Session::forget($verifyType.':'.$phone);Session([$verifyType.':'.$phone=>$code]);Session::save();}public function destroyCodeRedis($phone,$verifyType){Session::forget($verifyType.':'.$phone);}public function checkCodeHistory($phone){$number=SmsRecord::where('phone',$phone)->where('created_at','>=',date('Y-m-d'))->count();$P2g0=$number<$this->messageCount;if($P2g0)goto P2gBodyx2;goto P2gNextx2;P2gBodyx2:return 1;goto P2gx1;P2gNextx2:return 0;P2gx1:}public function checkPhoneCode($phone,$verifyType){if(Session::get($verifyType.':'.$phone))goto P2gBodyx4;goto P2gNextx4;P2gBodyx4:return Session::get($verifyType.':'.$phone);goto P2gx3;P2gNextx4:return 0;P2gx3:}public function checkWhite($phone='',$channel=''){$P2g0=!empty($phone);if($P2g0)goto P2gBodyx6;goto P2gNextx6;P2gBodyx6:$redis_key='phone_white_list';$redis_value=$phone;goto P2gx5;P2gNextx6:$redis_key='channel_white_list';$redis_value=$channel;P2gx5:if(Redis::exists($redis_key))goto P2gBodyx8;goto P2gNextx8;P2gBodyx8:$exists=json_decode(Redis::get($redis_key),true);$A____A_AA="in_array";$P2gAC0=$A____A_AA($redis_value,$exists);if($P2gAC0)goto P2gBodyxa;goto P2gNextxa;P2gBodyxa:return 1;goto P2gx9;P2gNextxa:return 0;P2gx9:goto P2gx7;P2gNextx8:return 0;P2gx7:}public function newSendSMS($phone,$code,$type){$setting=SmsSetting::first();$this->accesskey=$setting->appkey;$this->secret=$setting->appsecret;$P2gAC0=array();$P2gAC0['sms_key']=$this->accesskey;$P2gAC0['sms_secret']=$this->secret;$P2gAC0['phone']=$phone;$P2gAC0['code']=$code;$P2gAC0['category']=$type;$param=$P2gAC0;$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$this->msg_url);curl_setopt($ch,CURLOPT_HEADER,1);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$param);$data=curl_exec($ch);curl_close($ch);$res=@explode("

",$data);return $res[1];}public function newSendContent($phone,$content){$setting=SmsSetting::first();$this->accesskey=$setting->appkey;$this->secret=$setting->appsecret;$P2gAC0=array();$P2gAC0['sms_key']=$this->accesskey;$P2gAC0['sms_secret']=$this->secret;$P2gAC0['phone']=$phone;$P2gAC0['con']=$content;$P2gAC0['category']='notice';$param=$P2gAC0;$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$this->msg_url);curl_setopt($ch,CURLOPT_HEADER,1);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POST,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$param);$data=curl_exec($ch);curl_close($ch);$res=@explode("

",$data);return $res[1];}}
?>