分享海报以及微信模板消息推送

//使用phpqrcode生成海报

public function haibao(){

        $userid = $this->uid;            //dump($this->uid);die;
        $this->head_title="海报反馈";       
        $job = D('Job');                //根据uid查出公司正在招check_status的职位
        $infodata = $job->field('id,name,contact_number,remuneration,charge_mode')->where(array('uid'=>$this->uid))->order('id desc')->find();//查出最近发的一条信息
        //dump($infodata);
        if(!$infodata){
            $this->error('没有发布职位,请发布职位',U('Account/base_info'));
        }                    
        $level = 'L';               // 纠错级别:L、M、Q、H       
        $size = 4;                  // 点的大小:1到10,用于手机端4就可以了
        $path = $_SERVER['DOCUMENT_ROOT'].'/Uploads/qrcodes/';      //二维码存储路径 Uploads/qrcodes
        $fileName = $path.'2_'.$level.$userid.'_'.$size.'.png';  
        if(!file_exists($fileName)){
            vendor("phpqrcode.phpqrcode");
            $qrcode = new \QRcode();
            $url = 'http://'.$_SERVER['HTTP_HOST'].'/Job/detail/id/'.$infodata['id'];//需要跳转的一个路径';
            // dump($url);die;
            $info = $qrcode->png($url,$fileName, $level, $size);//生成带参数的二维码            
        }
        $final = $path.'final/'.$userid.$level.'_'.$size.'.png';
        if(!file_exists($final)){
            $haibao = './Uploads/qrcodes/haibao/haibao1.jpg';
            $msyh = './Uploads/qrcodes/msyh/msyh.ttf';
            $erweima = './Uploads/qrcodes/tmp/'.$userid.'_'.$size.'.jpg';
            $image = new \Think\Image();
            $image->open($fileName)
            ->thumb(500,500,\Think\Image::IMAGE_THUMB_FIXED)->save($erweima);//二维码小图
            $image->open($haibao)
            ->water($erweima,array(925,2800),100)
            ->text('招聘职位:'.$infodata['name'],$msyh,70,'#000000',array(500,2070))
            ->text('薪资:'.$infodata['remuneration'].'元/月',$msyh,70,'#000000',array(500,2200))
            ->text('联系电话:'.$infodata['contact_number'],$msyh,70,'#000000',array(500,2330))
            ->save($final);
        } 
        $pic_url = 'http://'.$_SERVER['HTTP_HOST'].'/Uploads/qrcodes/final/'.$userid.$level.'_'.$size.'.png';//图片最终的一个地址
        if($pic_url){
            $this->assign('image',$pic_url);
        }          
            $this->display();

    }

/*
**name      当前申请绑定的公司名称
**openid    总公司的openid
**data    
 */
//发送模板消息
public function sendToMessage($openid='owWdvt3NRVhW-jaJB8nqAAyz5FI0',$name='GGGG',$datas='LLLL'){
    $template_id = '0jyRMLDqM5R5YA24XWdkcDok63gAOVcGvzDOgkB6MJE';   //      面试确认提醒模板
    $configs        = array('appid'=> C('APPID'),'secret'=> C('APPSECRET'));
    //dump($configs);die;
    $wechat   = new Wechat($configs);
    $access_token = S('ACCESS_TOKEN');
    //S('ACCESS_TOKEN',null);    //dump($access_token);
    if (!$access_token) {
        $access_token = $wechat->getToken();
        S('ACCESS_TOKEN', $access_token,7100);
    }    
    $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.$access_token;
    $json_template = $this->TemplateMessage($openid,$name,$datas,$datas,$template_id);
    $this->http($url,$json_template);
}

//拼接post方法需要的json数据
public function  TemplateMessage($openid,$name,$keyword1,$keyword2,$template_id='0jyRMLDqM5R5YA24XWdkcDok63gAOVcGvzDOgkB6MJE'){
    $data = array(
            "first" => array("value"=>"您好,".$name."申请加入贵公司", "color"=>"#173177"),
            "keyword1"=>array("value"=>$keyword1,"color"=>"#173177"),
            "keyword2"=>array("value"=>$keyword2, "color"=>"#173177"),
            "remark"=> array("value"=>"请尽快通过审核", "color"=>"#173177"),
        ); 
    $template = array(
            'touser' => $openid,
            'template_id' =>$template_id,
            'data' => $data
    );     
    return  json_encode($template);
}

public function http($url,$data){
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        $data = curl_exec($ch);
}

猜你喜欢

转载自blog.csdn.net/weixin_36521716/article/details/80020704