被动回复图文

获取永久素材
http请求方式: POST,https协议
https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN
参数:
access_token调用接口凭证
media_id要获取的素材的media_id
直接返回:"https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN" -d '{"media_id":"61224425"}' > file
错误返回:{"errcode":40007,"errmsg":"invalid media_id"}

创建新增图文的方法:replynews
public function replynews(){
      if(IS_GET){
       $this->display();
    }else{
      $keyword=I('keyword');
      $title = I('title');
      $description = I('content');
      // echo $description;
      // exit;
      $url = I('content_source_url');
      $fileurl = I('url');
      // dump($picurl);
      // exit;
     // if(empty($keyword)|| empty($description)){
     //  $this->ajaxReturn(array('status'=>0,'msg'=>'请输入关键字和图片'));
     //  exit;
     // }
       $accessToken=getAccess_token();
        // echo $accessToken;
        // exit;
        include APP_PATH.'LaneWeChat/lanewechat.php';
        $api="https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$accessToken&type=news";
        $file=realpath('.'.$fileurl);
        // echo $file;
        // exit;
        $data['media']=curl::addFile($file);
        $ret=Curl::callwebServer($api,$data,'post',1,0);
        // dump($ret);
        // exit;
        if(isset($ret['url'])){
          // $media_id=$ret['media_id'];
          $picurl=$ret['url'];
          // echo $picurl;
          // exit;
        }else{
          $ret['fail']='上传失败';
          $this->ajaxReturn(array('status'=>1,'msg'=>$ret));
          exit;
        }
     
     $data['title'] = $title;
     $data['description'] = $description;
     $data['url'] = $url;
     $data['picurl'] = $picurl;
     $reply_id=M('mp_reply_news')->add($data);
     $mp=getCurrentMp();
     $arr['mp_id']=$mp['id'];
     $arr['type']='news';
     $arr['keyword']=$keyword;
     $arr['reply_id']=$reply_id;
     $ret=M('mp_rule')->add($arr);
     if($ret){
      $this->ajaxReturn(array('status'=>1,'msg'=>'添加成功','url'=>'replyimage'));
     }else{
      $this->ajaxReturn(array('status'=>0,'msg'=>'添加失败'));
     }
     }
   } 

回复图文的方法

public static function text(&$request){
        // $content = '收到文本消息';
        // return ResponsePassive::text($request['fromusername'], $request['tousername'], $content);
        //获取那个公众号发过来的请求
        $mpid=$_GET['id'];
        $content=$request['content'];
        $where['mp_id']=$mpid;
        $where['keyword']=$content;
        $data=M('mp_rule')->where($where)->find();
        if($data){
            //发送请求中有这个关键字
            $reply_id=$data['reply_id'];
            $type=$data['type'];//回复类型

            //判断回复类型
            switch($type){
                case 'text'://回复文字
                    $reply=M('mp_reply_text')->find($reply_id);
                    if($reply){
                        $reply_text=$reply['content'];
                    }else{
                        $reply_text='出错啦';
                    }
                    return ResponsePassive::text($request['fromusername'],$request['tousername'],$reply_text);
            
                    break;
                case 'image'://回复图片
                    $reply = M('mp_reply_image')->find($reply_id);
                    if($reply){
                        $media_id = $reply['media_id'];
                        return ResponsePassive::image($request['fromusername'],$request['tousername'],$media_id);
                    }else{
                        $reply_text = "出错啦";
                        return ResponsePassive::text($request['fromusername'], $request['tousername'], $reply_text);
                    }
                    
                    break;
                case 'news'://回复图文
                    $reply=M('mp_reply_news')->find($reply_id);
                    if($reply){
                        $item[]=ResponsePassive::newsItem($reply['title'],$reply['description'],$reply['picurl'],$reply['url']);
                         return ResponsePassive::news($request['fromusername'],$request['tousername'],$item);
                    }else{
                        $reply_text='出错啦';
                        return ResponsePassive::text($request['fromusername'],$request['tousername'],$reply_text);
                    }
                   break;

                default:
                
                    return 'success';
                    break;

            }


        }else{
            return 'success';
        }
    }



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值