微信公众号-自定义回复

回复图片

 public function addImage(){
        if(IS_GET){
            $this->display('replyimage');
        }else{
            $data = array();

            $url = I('post.url'); //图片路径
            $file = realpath('.' . $url); //相对路径转绝对路径

            $access_token = getAccess_token();
            include APP_PATH .'LaneWeChat/lanewechat.php';

            $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$access_token&type=image";
            $data['media'] = '@'.$file;
            $ret = Curl::callWebServer($url,$data,'post',true,false);
            // dump($ret);
            // exit;
            if (isset($ret['media_id'])) {
                $mp = $this->mp;
                $mp_id = $mp['id'];

                $data['url'] = $url;
                $data['media_id'] = $ret['media_id'];
                $imgret = M('mp_reply_image')->add($data);

                if ($imgret) {
                    $data['keyword'] = I('post.keyword');
                    $data['reply_id'] = $imgret;
                    $data['mp_id'] = $mp_id;
                    $data['type'] = 'image';
                    if ($mp['is_use'] == 1){
                        $data['status'] = 1;
                    }else{
                        $data['status'] = 0;
                    }
                    $ret = M('mp_rule')->add($data);
                    if ($ret) {
                        $this->ajaxReturn(array('status'=>1,'msg'=>'添加成功!'));
                    }else{
                        $this->ajaxReturn(array('status'=>1,'msg'=>$ret));
                    }
                }
            }else{
                $this->ajaxReturn(array('msg'=>$ret));
            }
        }
    }

回复图文

public function addNews(){
        if(IS_GET){
            $this->display();
        }else{
           $data = array();
           $url = I('post.url'); //图片路径
           $file = realpath('.' . $url); //相对路径转绝对路径

           $access_token = getAccess_token();
           include APP_PATH .'LaneWeChat/lanewechat.php';
           $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$access_token&type=image";
           $data['media'] = '@'.$file;
           $ret = Curl::callWebServer($url,$data,'post',true,false);

            if (isset($ret['media_id'])) {
                $mp = $this->mp;
                $mp_id = $mp['id'];

                $data['picurl'] = $ret['url'];
                $data['title'] = I('post.title');
                $data['description'] = I('post.content');
                $data['url'] = I('content_source_url');
                $newsret = M('mp_reply_news')->add($data);

                if ($newsret) {
                    $data['keyword'] = I('post.keyword');
                    $data['reply_id'] = $newsret; 
                    $data['mp_id'] = $mp_id;
                    $data['type'] = 'news';
                    if ($mp['is_use'] == 1){
                        $data['status'] = 1;
                    }else{
                        $data['status'] = 0;
                    }
                    $ret = M('mp_rule')->add($data);
                    if ($ret) {
                        $this->ajaxReturn(array('status'=>1,'msg'=>'添加成功!'));
                    }else{
                        $this->ajaxReturn(array('status'=>1,'msg'=>$ret));
                    }
                }
            }else{
                $this->ajaxReturn(array('msg'=>$ret));
            }

        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值