123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Input\InputArgument;
- use TopClient;
- use DB;
- use Redis;
- use TbkAdzoneCreateRequest;
- class AdzoneCreate extends Command {
- protected $signature = 'AdzoneCreate';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '店家收集';
- public function handle()
- {
- $this->AdzoneCreate();
- }
- public function AdzoneCreateApi($name){
- $c = new TopClient;
- $c->appkey = "23260528";
- $c->secretKey = "842fc308fb5f95b1250581f664cdcde8";
- $req = new TbkAdzoneCreateRequest;
- $req->setSiteId("11458219");
- $req->setAdzoneName($name);
- $resp = $c->execute($req);
- $resp=(array)$resp;
- if(array_key_exists("data",$resp)){
- $pmodel=(array)$resp['data'];
- if(array_key_exists("model",$pmodel)){
- $adzoneArr=explode("_",$pmodel['model']);
- $data['name']=$name;
- $data['adzone_id']=$adzoneArr[count($adzoneArr)-1];
- $data['create_at']=date("Y-m-d",time());
- $data['update_at']=date("Y-m-d",time());
- DB::table("adzone")->insert($data);
- return $adzoneArr[count($adzoneArr)-1];
- }else{
- return "";
- }
- }else{
- return "";
- }
- }
- //
- public function AdzoneCreate(){
- set_time_limit(0);
- ini_set('memory_limit','1024M');
- $AdzoneListName="tbk:adzoneList";
- $lastAdzone=DB::table("adzone")->orderBy("id","desc")->first();
- if(count($lastAdzone)>0){
- $adzoneName=$lastAdzone->name;
- preg_match("/\d+/",$adzoneName,$adzoneNameArr);
- $api_last=$adzoneNameArr[0];
- $api_last=intval($api_last)+1;
- }else{
- $api_last=1;
- }
- for($i=0;$i<500;$i++){
- $api_all="api_".$api_last;
- $adzoneId=$this->AdzoneCreateApi($api_all);
- $redis=new Redis();
- $redis->connect(config('constants.REDIS_IP'),config('constants.REDIS_PORT'));
- $redis->auth(config('constants.REDIS_PASSWORD'));
- $redis->rpush($AdzoneListName,$adzoneId);
- $api_last+=1;
- if($api_last%20==0){
- sleep(5);
- }
- }
- }
- }
|