微信开发,添加多图文界面和消息群发显示界面

1.首先在html文件中home文件下创建Qunfa文件夹,写入HTML文件名为newlist和addnews,为前台页面。

2.创建控制器QunfaController.class.php 写入命名空间和_initialize方法检测有无公众号使用。代码如下:

<?php
namespace Home\Controller;
use Think\Controller;

class QunfaController extends Controller{

	private $mp;

    //初始化
    public function _initialize(){
        $mp = getCurrentMp();
        if (empty($mp)) {
            $this->error('无使用的公众号',U('mp/index'));
            exit();
        }else{
            $this->mp = $mp;
        }
    }

3.写入addnews方法实现多图文上传界面。代码如下:

public function addnews(){
        if(IS_GET){
            $this->display();
        }else{
        	$data = I('post.data');
            $mp = $this->mp;
            $mp_id = $mp['id'];
            
            foreach ($data as $key => &$v) {
                $v['mp_id'] = $mp_id;
                $v['create_time'] = time();
                $data['media_id'] = $v['thumb_media_id'];
                
                if($key==0){
                	 $news_id = M('media_news')->add($v);
                }
                $v['news_id'] = $news_id;

                M('media_news_list')->add($v);
            }
            $this->ajaxReturn(array('error'=>0,'msg'=>'添加成功'));    

        }
    }

上传图片需使用upload方法 代码如下:

public function upload(){
        $upload = new \Think\Upload();//实例化上传类
        $upload->maxSize = 3145728;//设置附件上传的大小
        $upload->exts = array('jpg','gif','png','jpeg');//设置附件上传的类型
        $upload->rootPath = './Uploads/';//设置附件上传根目录
        $upload->savePath = '';//设置附件上传(子)目录
        //上传文件
        $info = $upload->uploadOne($_FILES['file']);
        if (!$info) {//上传错误显示错误信息
          $this->ajaxReturn(array('code'=>1,'msg'=>$upload->getError()));
        }else{
          $file = '/Uploads/'.$info['savepath'].$info['savename'];
          $this->ajaxReturn(array('code'=>0,'msg'=>'上传成功!','url'=>$file));
        }
    }

4.写入newslist方法显示图文群发界面,代码如下:

public function newslist(){
        $mp = getCurrentMp();
        $where['mp_id']=$mp['id'];
        $data = M('media_news')->where($where)->select();
        // print_r($data);
        foreach ($data as $key => $value) {
            $where['news_id']=$value['news_id'];
            $arr=M('media_news_list')->where($where)->select();
            // print_r($arr);
            // exit;
            $data[$key]['list']=$arr;
        }
        // print_r($data);
        // exit();


        $this->assign('data',$data);
		$this->display();
	}

      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值