1. 程式人生 > >微信公眾號傳送模板訊息範例

微信公眾號傳送模板訊息範例

public function sendTemplateMessage($data){


        $info = model('Base')->model->table('wechat_template')
            ->field('switch,template_id')
            ->where('open_id="'.$data['open_id'].'"')
            ->find();
        if($info['switch'] == 1 && $info['template_id']){
            //傳送
            $format = array(
                'touser' => $data['openid'],
                'template_id' => $info['template_id'],
                'url' => $data['url'],
                'topcolor' => '#FF0000',
                "topcolor"=>"#FF0000",
                'data' =>array(
                    'first' => array(
                        'value' =>$data['first'],
                        'color'=>'#173177'
                    ),
                    'keyword1'=>array(
                        'value'=>$data['keyword1'],
                        'color'=>'#FF0000'
                    ),
                    'keyword2'=>array(
                        'value'=>$data['keyword2'],
                        'color'=>'#FF0000'
                    ),
                    'keyword3'=>array(
                        'value'=>$data['keyword3'],
                        'color'=>'#FF0000'
                    ),
                    'keyword4'=>array(
                        'value'=>$data['keyword4'],
                        'color'=>'#FF0000'
                    ),
                    'keyword5'=>array(
                        'value'=>$data['keyword5'],
                        'color'=>'#FF0000'
                    ),
                    'remark'=>array(
                        'value'=>$data['remark'],
                        'color'=>'#FF0000'
                    )
                )
            );