自定义回复图片回复图文

创建一个类文件 AutoreplyController.class.php

代码例:

//自定义回复图片
  public function index1(){
    $this->display('replyimage');
  }

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));
         }
  }
自动回复图片
public function replyimage(){
    $url =I('post.url');//图片在本地服务器上的路径 
    $media_id = I('post.media_id');
    if(empty($media_id)){
      $accessToken = getAccess_token();
      include APP_PATH .'LaneWeChat/lanewechat.php';
      $api = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$accessToken&type=image";
      //相对路径转换为绝对
      $file = realpath('.'.$url);
      // echo $file;
      // exit;
      $data['media'] = Curl::addFile($file);
      // print_r($data);
      // exit;
      $ret = Curl::callWebServer($api,$data,'post',true,false);

      if(isset($ret['media_id'])){
        $media_id = $ret['media_id'];
        $url = $ret['url'];
     }else{
        $ret['fail'] = '本地图片上传公众平台失败';
        $this->ajaxReturn(array('status'=>1,'msg'=>$ret));
        exit;
     }


回复图文

public function replynews(){
     $picurl =I('post.url');
     $accessToken = getAccess_token();
      include APP_PATH .'LaneWeChat/lanewechat.php';
      $api = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$accessToken&type=image";
      //相对路径转换为绝对
      $file = realpath('.'.$picurl);
      // echo $file;
      // exit;
      $data['media'] = Curl::addFile($file);
      // print_r($data);
      // exit;
      $ret = Curl::callWebServer($api,$data,'post',true,false);

      if(isset($ret['media_id'])){
        $media_id = $ret['media_id'];
        $picurl = $ret['url'];
     }else{
        $ret['fail'] = '本地图片上传公众平台失败';
        $this->ajaxReturn(array('status'=>1,'msg'=>$ret));
        exit;
     }

 if($ret){
           $this->ajaxReturn(array('status'=>1,'msg'=>'添加成功'));

        }else{
           $this->ajaxReturn(array('status'=>1,'msg'=>'添加失败'));

        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值