ActiveController.php 27.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/5
 * Time: 11:24
 */

namespace api\index\controller;


use cmf\controller\RestBaseController;
use think\Db;
use api\index\model\JobModel;
use think\Validate;


/**
 * @title 我的活动
 * @description
 */
class ActiveController extends RestBaseController
{

    /**
     * @title 我参与的活动
     * @description 我参与的活动
     * @author GuoSheng
     * @url /index/Active/index
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     *
     * @return id:ID
     * @return job_title:标题
     * @return linkman:联系人
     * @return linkman_tel:手机号
     * @return adress:详细地址
     * @return create_time:开始时间
     * @return end_time:结束时间
     * @return is_begin:是否开始  0报名中 1已结束
     */
    public function index()
    {
        $user_id = $this->getUserId();
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $apply_id = Db::name('apply')
            ->where('user_id',$user_id)
            ->where('status',2)
            ->order('create_time desc')
            ->column('job_id');
        $data = Db::name('job')
            ->whereIn('id',$apply_id)
            ->page($page,$pageNum)
            ->select()
            ->toArray();
        foreach ($data as $k=>$v){
            if($data[$k]['end_time'] < time()){
                $data[$k]['is_begin'] = 1;
            }else{
                $data[$k]['is_begin'] = 0;
            }
            $data[$k]['create_time'] = date('Y-m-d H:i',$v['create_time']);
            $data[$k]['end_time'] = date('Y-m-d H:i',$v['end_time']);
        }
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 我发布的活动
     * @description 我发布的活动
     * @author GuoSheng
     * @url /index/Active/activeList
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     *
     * @return id:ID
     * @return job_title:标题
     * @return linkman:联系人
     * @return linkman_tel:手机号
     * @return adress:详细地址
     * @return create_time:开始时间
     * @return end_time:结束时间
     * @return is_begin:是否开始 0显示报名人数  1已结束 2还未发布
     */
    public function activeList()
    {
        $user_id = $this->getUserId();
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $data = Db::name('job')
            ->where('user_id',$user_id)
            ->where('job_type',3)
            ->page($page,$pageNum)
            ->order('create_time desc')
            ->select()
            ->toArray();
        foreach ($data as $k=>$v){
            if($v['status'] == 0){
                $data[$k]['is_begin'] = 2;
            }else{
                if($v['end_time'] > time()){
                    $data[$k]['is_begin'] = 0;
                    $data[$k]['count'] = Db::name('apply')
                        ->where('job_id',$v['id'])
                        ->where('status',2)
                        ->count();
                    $list = Db::name('apply')
                        ->where('job_id',$v['id'])
                        ->where('status',1)
                        ->select()
                        ->toArray();
                    if(empty($list)){
                        $data[$k]['is_show'] = 0;
                    }else{
                        $data[$k]['is_show'] = 1;
                    }
                }
                if($v['end_time'] < time()){
                    $data[$k]['is_begin'] = 1;
                }
            }
            $data[$k]['create_time'] = date('Y-m-d H:i',$v['create_time']);
            $data[$k]['end_time'] = date('Y-m-d H:i',$v['end_time']);
        }
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 修改我的活动
     * @description 修改我的活动
     * @author GuoSheng
     * @url /index/Active/updActive
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 desc:信息ID
     * @param name:job_title type:string require:1 desc:信息标题
     * @param name:end_time type:string require:0 desc:有效日期
     * @param name:linkman type:string require:1 desc:联系人
     * @param name:linkman_tel type:string require:1 desc:手机号码
     * @param name:needpeople type:int require:1 desc:需求人数
     * @param name:payroll type:int require:1 desc:费用
     * @param name:city type:string require:1 desc: 城市(此处只能添加一个)
     * @param name:adress type:string require:1 desc:详细地址
     * @param name:company_name type:string require:1 desc:公司名称不能为空
     * @param name:content type:text require:1 desc:项目详情
     * @param name:status type:int require:1 desc:保存为0  发布为1
     * @param name:image type:string require:0 desc:项目详情图片
     *
     */
    public function updActive()
    {
        $user_id = $this->getUserId();
        $param = $this->request->param();
        $param['user_id'] = $user_id;
        $param['update_time'] = time();

        $res = Db::name('job')
            ->where('id',$param['id'])
            ->find();
        if(empty($param['end_time'])){
            $param['end_time'] = $res['create_time']+7*24*60*60;
        }else{
            $param['end_time'] = strtotime($param['end_time']);
        }
        $validate = new Validate([
            'job_title' => 'require',
            'linkman' => 'require',
            'linkman_tel'=>'require|number|max:11',
            'needpeople' =>'require|number',
            'payroll'=>'require|number',
            'city'=>'require',
            'adress'=>'require',
            'company_name'=>'require',
            'content'=>'require',
        ]);
        if (!$validate->check($param)) {
            $this->error(['code'=>40005,'msg'=>$validate->getError()]);
        }
        $this->secCheck($param['job_title'],1);
        $this->secCheck($param['company_name'],1);
        $this->secCheck($param['content'],1);
        if(!empty($param['image'])){
            $this->secCheck($param['image'],2);
        }
        $data = Db::name('job')
            ->where('id',$param['id'])
            ->update($param);
        if(empty($data)){
            $this->error(['code'=>40006,'msg'=>'sql执行失败']);
        }
        $this->success('SUCCESS');
    }

    /**
     * @title 我的活动详情
     * @description 我的活动详情
     * @author GuoSheng
     * @url /index/Active/myActive
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     * @param name:id type:int require:1 other: desc:信息ID
     *
     * @return id:信息ID
     * @return job_title:信息标题
     * @return end_time:有效日期
     * @return linkman:联系人
     * @return linkman_tel:联系人电话
     * @return needpeople:人数
     * @return payroll:费用
     * @return city:城市
     * @return company_name:公司名称
     * @return adress:详细地址
     * @return content:项目详情
     * @return status:0 未提交 1已提交
     */
    public function myActive()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }

        $where['id'] = ['eq',$id];
        $jobModel = new JobModel();
        $info = $jobModel->getOne($where);
        $data['status'] = $info['status'];
        $data['id'] = $info['id'];
        $data['job_title'] = $info['job_title'];
        $data['end_time'] = date('Y-m-d',$info['end_time']);
        $data['linkman'] = $info['linkman'];
        $data['linkman_tel'] = $info['linkman_tel'];
        $data['needpeople'] = $info['needpeople'];
        $data['city_id'] = ','.$info['city'].',';
        $data['payroll'] = $info['payroll'];
        $city = explode(',',trim($info['city'],','));
        $data['city'] = Db::name('area')->whereIn('id',$city)->column('name');
        $data['company_name'] = $info['company_name'];
        $data['adress'] = $info['adress'];
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
        $data['image'] = $info['image'];
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 报名审核
     * @description 报名审核
     * @author GuoSheng
     * @url /index/Active/audit
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 other: desc:活动信息ID
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     *
     * @return id:ID
     * @return apply_name:姓名
     * @return apply_phone:联系方式
     * @return apply_company:公司名称
     */
    public function audit()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $list = Db::name('apply')
            ->where('status',1)
            ->where('job_id',$id)
            ->page($page,$pageNum)
            ->select();
        $this->success('SUCCESS',$list);
    }

    /**
     * @title 报名表
     * @description 报名表
     * @author GuoSheng
     * @url /index/Active/apply
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 other:desc:活动信息ID
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     *
     * @return id:ID
     * @return apply_name:姓名
     * @return apply_phone:联系方式
     * @return apply_company:公司名称
     */
    public function apply()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $list = Db::name('apply')
            ->where('status',2)
            ->where('job_id',$id)
            ->order('create_time desc')
            ->page($page,$pageNum)
            ->select();
        $this->success('SUCCESS',$list);
    }

    /**
     * @title 接受
     * @description 接受
     * @author GuoSheng
     * @url /index/Active/receive
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 other:desc:报名信息ID
     *
     */
    public function receive()
    {
        //报名信息ID
        $param['id'] = $this->request->param('id');
        //报名信息
        $info = Db::name('apply')
            ->where('id',$param['id'])
            ->find();
        //获取该报名用户的账户信息  找出报名人的id 以及报名的活动信息ID
        $arr = Db::name('account')
            ->where('user_id',$info['user_id'])
            ->find();
        if(!empty($arr)){
            //用户开启服务通知
            if($arr['infostatus']==2){
                //获取该活动的信息
                $job = Db::name('job')
                    ->where('id',$info['job_id'])
                    ->find();
                $city = explode(',',trim($job['city'],','));
                if(in_array($arr['city'],$city)){
                    //用户所选的通知城市在活动发布城市中
                    $form = Db::name('form')->where(['user_id'=>$info['user_id'],'past_time'=>['gt',time()]])->order('past_time desc')->find();
                    if(empty($form)){
                        $param['status'] = 2;
                        $data = Db::name('apply')
                            ->where('id',$param['id'])
                            ->update(['status'=>$param['status']]);
                        if($data){
                            $this->success('SUCCESS');
                        }else{
                            $this->error('sql执行失败1');
                        }
                    }else{
                        $openid = $this->getOpenid($info['user_id']);
                        //发送模板消息
                        $post_data = array(
                            "touser" => $openid,
                            // 小程序后台申请到的模板编号
                            "template_id" => 'NiS9cOcO66zM5EyZKHxclT_JgI6IYFDFF10WF61JTGE',
                            // 进入页面
                            "page" => "pages/index/index",
                            // 第一步里获取到的 formID
                            "form_id" => $form['form_id'],
                            // 数据
                            "data" =>[
                                'keyword1'=>["value"=>"通过"],
                                'keyword2'=>["value"=>"您报名参与活动标题:$job[job_title] 的申请已通过"]
                            ],
                            // 变大关键字
                            //"emphasis_keyword" => "keyword1.DATA",
                        );
                        $result = json_decode($this->send($post_data),true);
                        if(!empty($result['errcode'])){
                            $this->error($result['errmsg']);
                        }
                        $result1 = Db::name('form')->where('id',$form['id'])->delete();
                        if(empty($result1)){
                            $this->error('sql1执行失败');
                        }
                        $result2 = Db::name('send')->insert(['user_id'=>$info['user_id'],'job_id'=>$info['job_id'],'create_time'=>time()]);
                        if(empty($result2)){
                            $this->error('sql2执行失败');
                        }
                        $param['status'] = 2;
                        $data = Db::name('apply')
                            ->where('id',$param['id'])
                            ->update(['status'=>$param['status']]);
                        if($data){
                            $this->success('SUCCESS');
                        }else{
                            $this->error('sql执行失败2');
                        }
                    }

                }else{
                    $param['status'] = 2;
                    $data = Db::name('apply')
                        ->where('id',$param['id'])
                        ->update(['status'=>$param['status']]);
                    if($data){
                        $this->success('SUCCESS');
                    }else{
                        $this->error('sql执行失败3');
                    }
                }
            }else{
                //用户关闭服务通知
                $param['status'] = 2;
                $data = Db::name('apply')
                    ->where('id',$param['id'])
                    ->update(['status'=>$param['status']]);
                if($data){
                    $this->success('SUCCESS');
                }else{
                    $this->error('sql执行失败4');
                }
            }
        }else{
            $param['status'] = 2;
            $data = Db::name('apply')
                ->where('id',$param['id'])
                ->update(['status'=>$param['status']]);
            if($data){
                $this->success('SUCCESS');
            }else{
                $this->error('sql执行失败5');
            }
        }
    }

    /**
     * @title 忽略
     * @description 忽略
     * @author GuoSheng
     * @url /index/Active/deny
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 other:desc:报名信息ID
     *
     */
    public function deny()
    {
        //报名信息ID
        $param['id'] = $this->request->param('id');
        //报名信息
        $info = Db::name('apply')
            ->where('id',$param['id'])
            ->find();
        //获取该报名用户的账户信息
        $arr = Db::name('account')
            ->where('user_id',$info['user_id'])
            ->find();
        if(!empty($arr)){
            //用户开启服务通知
            if($arr['infostatus']==2){
                //获取该活动的信息
                $job = Db::name('job')
                    ->where('id',$info['job_id'])
                    ->find();
                $city = explode(',',trim($job['city'],','));
                if(in_array($arr['city'],$city)){
                    //用户所选的通知城市在活动发布城市中
                        $form = Db::name('form')->where(['user_id'=>$info['user_id'],'past_time'=>['gt',time()]])->order('past_time desc')->find();
                        if(empty($form)){
                            $param['status'] = 3;
                            $data = Db::name('apply')
                                ->where('id',$param['id'])
                                ->update(['status'=>$param['status']]);
                            if($data){
                                $this->success('SUCCESS');
                            }else{
                                $this->error('sql执行失败1');
                            }
                        }else{
                            $openid = $this->getOpenid($info['user_id']);
                            //发送模板消息
                            $post_data = array(
                                "touser" => $openid,
                                // 小程序后台申请到的模板编号
                                "template_id" => 'NiS9cOcO66zM5EyZKHxclT_JgI6IYFDFF10WF61JTGE',
                                // 进入页面
                                "page" => "pages/index/index",
                                // 第一步里获取到的 formID
                                "form_id" => $form['form_id'],
                                // 数据
                                "data" =>[
                                    'keyword1'=>["value"=>"未通过"],
                                    'keyword2'=>["value"=>"您报名参与的活动标题:$job[job_title] 的申请未通过"]
                                ],
                                // 变大关键字
                                //"emphasis_keyword" => "keyword1.DATA",
                            );

                            $result = json_decode($this->send($post_data),true);
                            if(!empty($result['errcode'])){
                                $this->error($result['errmsg']);
                            }
                            $result1 = Db::name('form')->where('id',$form['id'])->delete();
                            if(empty($result1)){
                                $this->error('sql1执行失败');
                            }
                            $result2 = Db::name('send')->insert(['user_id'=>$info['user_id'],'job_id'=>$info['job_id'],'create_time'=>time()]);
                            if(empty($result2)){
                                $this->error('sql2执行失败');
                            }
                            $param['status'] = 3;
                            $data = Db::name('apply')
                                ->where('id',$param['id'])
                                ->update(['status'=>$param['status']]);
                            if($data){
                                $this->success('SUCCESS');
                            }else{
                                $this->error('sql执行失败2');
                            }
                        }
                }else{
                    $param['status'] = 3;
                    $data = Db::name('apply')
                        ->where('id',$param['id'])
                        ->update(['status'=>$param['status']]);
                    if($data){
                        $this->success('SUCCESS');
                    }else{
                        $this->error('sql执行失败');
                    }
                }
            }else{
                //用户关闭服务通知
                $param['status'] = 3;
                $data = Db::name('apply')
                    ->where('id',$param['id'])
                    ->update(['status'=>$param['status']]);
                if($data){
                    $this->success('SUCCESS');
                }else{
                    $this->error('sql执行失败');
                }
            }
        }else{
            $param['status'] = 3;
            $data = Db::name('apply')
                ->where('id',$param['id'])
                ->update(['status'=>$param['status']]);
            if($data){
                $this->success('SUCCESS');
            }else{
                $this->error('sql执行失败');
            }
        }
    }

    public function get_access_token()
    {
        $app_id = config('app_id');
        $app_secret = config('app_secret');
        $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$app_id.'&secret='.$app_secret;
        $res = $this->http_get($url);
        $json_arr = json_decode($res,true);
        $token = $json_arr['access_token'];
        return $token;
    }
    function send_post($url, $post_data)
    {
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/json',
                'content' => $post_data,
                'timeout' => 60
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }
    public function send($post_data)
    {
        $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $this->get_access_token();
        $data = json_encode($post_data, true);
        return $this->send_post($url, $data);
    }
    public function getOpenid($user_id){
        $openid = Db::name('third_party_user')->where(['user_id'=>$user_id])->value('openid');
        return $openid;
    }

    //curl  get请求
    public function http_get($url){
        $curl = curl_init();//启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL,$url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, false);//不开启header
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
        $result = curl_exec($curl); //执行操作
        curl_close($curl);
        return $result;
    }

    //curl post请求
    public function http_post($url,$data){
        $curl = curl_init();//启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); // Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, false); // 开启header
        //curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);//请求头部
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
        $result = curl_exec($curl); //执行操作
        curl_close($curl);
        return $result;
    }

    /**
     * 小程序内容安全审核
     * @param $content 审核内容
     * @param $type 类型(1,文本;2,图片;3,音频)
     */
    public function secCheck($content,$type = 1) {
//        if(!$type) {
//            return true;
//        }
        $access_token = $this->get_access_token();
        $basic_url = 'https://api.weixin.qq.com/wxa';
        if($type == 1) {
            $url = $basic_url.'/msg_sec_check?access_token='.$access_token;
            if(is_array($content)) {
                foreach ($content as $v) {
                    $this->setUrl($url,['content'=>$v]);
                }
            } else {
                $this->setUrl($url,['content'=>$content]);
            }
        }
        if($type == 2) {
            $url = $basic_url.'/media_check_async?access_token='.$access_token;
            if(is_array($content)) {
                foreach ($content as $v) {
                    $this->setUrl($url,['media_url'=>$v,'media_type'=>2],'图片');
                }
            } else {
                $this->setUrl($url,['media_url'=>$content,'media_type'=>2],'图片');
            }
        }
        if($type == 3) {
            $url = $basic_url.'/media_check_async?access_token='.$access_token;
            if(is_array($content)) {
                foreach ($content as $v) {
                    $this->setUrl($url,['media_url'=>$v,'media_type'=>1],'语音');
                }
            } else {
                $this->setUrl($url,['media_url'=>$content,'media_type'=>1],'语音');
            }
        }
    }
    /**
     * 调用接口审核
     * @param $url 跳转地址
     * @param $post 审核内容
     * @param $type_name
     * @param $image
     */
    private function setUrl($url,$post,$type_name = '文本') {
        $result = $this->curls($url,json_encode($post,JSON_UNESCAPED_UNICODE));
        $return_data = json_decode($result,true);
        if($return_data['errcode'] != 0) {
            $this->error($type_name.'内容含有违法违规内容');
        }
    }
    // curl方法
    function curls($url, $post = null, $header = null) {
        // 初始化
        $curl = curl_init();
        // 设置抓取的url
        curl_setopt($curl, CURLOPT_URL, $url);
        if($header) {
            // 请求头
            curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
        }
        // 设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLINFO_HEADER_OUT, true);
        // 设置获取的信息以文件流的形式返回,而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        if($post) {
            curl_setopt($curl, CURLOPT_POST, 1);
            //把POST的变量加上
            curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
        }
        // 执行命令
        $data = curl_exec($curl);
        if (curl_errno($curl)) {
            $data = curl_error($curl);
        }
        return $data;
    }
}