zhphpweixinApi 说明文档

告知义务:
  1. api提供订阅号基本服务以及公众号常用服务;

  2. api如不能满足您的需求,请阅读微信公众平台说明文档

使用说明:
     header('Content-type: text/html; charset=utf-8');#设置头信息
     require_once('zhphpWeixinApi.class.php');#加载微信接口类文件
     $dodiwx=new zhphpWeixinApi();//实例化
    
    配置:
       第一种方式:
       $dodiwx->weixinConfig=array(
                            'token'=>'weixintest',
                            'appid'=>'wx7b4b6ad5c7bfaae1',
                            'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
                            'myweixinId'=>'gh_746ed5c6a58b'
                            );
                            
        第二种方式:
        $configArr=array(
                'token'=>'weixintest',
                'appid'=>'wx7b4b6ad5c7bfaae1',
                'appSecret'=>'faaa6a1e840fa40527934a293fabfbd1',
                'myweixinId'=>'gh_746ed5c6a58b'
                );
        $dodiwx->setConfig($configArr);
        
        第三种方式:
             $dodiwx->weixinBaseApiMessage($configArr);
             $dodiwx->weixinHighApiMessage($configArr);
            
    官方建议使用 第二种方式        
        
        
    订阅号基本功能调用
       $dodiwx->weixinBaseApiMessage(); #订阅号接口入口  返回 true  false
       
       
     下面是调用案例
    if($dodiwx->weixinBaseApiMessage()){ //基本微信接口会话 必须
        $keyword=$dodiwx->getUserTextRequest();//得到用户发的微信内容, 这里可以写你的业务逻辑
        $msgtype=$dodiwx->getUserMsgType();//得到用户发的微信数据类型, 这里可以写你的业务逻辑
        $SendTime=$dodiwx->getUserSendTime();//得到用户发送的时间
        $fromUserName=$dodiwx->getUserWxId();//用户微信id
        $pingtaiId=$dodiwx->getPlatformId();//平台微信id
        $requestId=$dodiwx->getUserRequestId(); //获取微信公众平台消息ID
        $userPostData=$dodiwx->getUserPostData();//获取用户提交的post 数据对象集
    if( $msgtype == 'text' ){ //如果是文本类型
             if($keyword == 'news'){ //新闻类别请求
                $callData=array(
                      array('Title'=>'第一条新闻的标题','Description'=>'第一条新闻的简

介','PicUrl'=>'http://t12.baidu.com/it/u=1040955509,77044968&fm=76','Url'=>'http://wxphptest1.applinzi.com/'),
                      array('Title'=>'第二条新闻的标题','Description'=>'第一条新闻的简

介','PicUrl'=>'http://images.cnitblog.com/blog2015/340216/201505/051316468603876.png','Url'=>'http://wxphptest

1.applinzi.com/'),
                      array('Title'=>'第三条新闻的标题','Description'=>'第一条新闻的简

介','PicUrl'=>'http://dimgcn2.s-msn.com/imageadapter/w60h60q85/stimgcn3.s-

msn.com/msnportal/hp/2016/01/21/3e3ef7f07361b5211e2b155bb66fa6a9.jpg','Url'=>'http://wxphptest1.applinzi.com/'

),
                 );
                $dodiwx->responseMessage('news',$callData);
            }elseif($keyword == 'music'){ //音乐请求
               $music=array(
                 "Title"=>"最炫民族风",
                 "Description"=>"歌手:凤凰传奇",
                 "MusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3",
                 "HQMusicUrl"=>"http://121.199.4.61/music/zxmzf.mp3"
                );
                $dodiwx->responseMessage('music',$music);
            }else{
                $callData='这是zhphp 官方对你的回复:
                         你输入的内容是'.$keyword.'
                         你发数据类型是:'.$msgtype.'
                         你发的数据时间是:'.$SendTime.'
                         你的微信ID是:'.$fromUserName.'
                         平台的微信Id是:'.$pingtaiId.'
                         zhphp官方接收的ID是:'.$requestId;
                $dodiwx->responseMessage('text',$callData);
            }
    }else if($msgtype == 'image'){ //如果是图片类型
             $image=$dodiwx->getUserImageRequest();//如果用户发的是图片信息,就去得到用户的图形 信


             $callData=$image['MediaId'];//mediaID 是微信公众平台返回的图片的id,微信公众平台是依据

该ID来调用用户所发的图片
             $dodiwx->responseMessage('image',$callData);
            
        }else if($msgtype == 'voice'){ //如果是语音消息,用于语音交流
            $callData=$dodiwx->getUserVoiceRequest(); //返回数组
            $dodiwx->responseMessage('voice',$callData);
        }elseif($msgtype == 'event'){//事件,由系统自动检验类型
            $content='感谢你关注zhphp官方平台';//给数据为数据库查询出来的
            $callData=$dodiwx->responseEventMessage($content);//把数据放进去,由系统自动检验类型,

并返回字符串或者数组的结果
            $dodiwx->responseMessage('text',$callData); //使用数据
        }else{
            $callData='这是zhphp 官方对你的回复:
                       你发数据类型是:'.$msgtype.'
                       你发的数据时间是:'.$SendTime.'
                     zhphp官方接收的ID是:'.$requestId;
            $dodiwx->responseMessage('text',$callData);
        }
    }
    ##########################################
    订阅号提供基本接口
     getAccessToken()   获取accessToken
     getExpiresTime()   获取accessToken 过期时间
     CheckAccessToken()  检查高级接口权限
     bytes_to_emoji($cp) 字节转表情
     getUserMessageInfo() 获取用户的所有会话状态信息
     getUsertEventClickRequest() 获取用户点击菜单信息
     getUserEventLocationRequest() 上报地理位置事件
     getUserEventScanRequest()  二维码扫描类容
     getUserLinkRequest()       获取用户链接信息
     getUserLocationRequest()   获取用户本地位置信息
     getUserMusicRequest()      获取音乐内容
     getUserVideoRequest()      获取视频内容
     getUserVoiceRequest()      获取语音消息
     getUserImageRequest()      获取图片消息
     getUserRequestId()         返回微信平台的当条微信id
     getUserTextRequest()       获取用户输入的信息
     getPlatformId()             获取当前平台的id
     getUserWxId()                获取当前用户的id
     getUserSendTime()             获取用户发送微信的时间
     getUserMsgType()              获取当前的会话内容
     isWeixinMsgType()             检查用户发的微信类型
     getUserPostData()             获取用户发送信息的数据对象集
     getConfig()                    获取配置信息
     responseMessage($wxmsgType,$callData='')  微信平台回复用户信息统一入口
    
    #####################################################
    服务号基本功能调用
      $dodiwx->weixinHighApiMessage();  #服务号接口入口  返回 true  false
      $dodiwx->CheckAccessToken();       #检查access权限
      
      下面是调用案例
       if($zhwx->weixinHighApiMessage()){// 检查配置统一入口
          if($zhwx->CheckAccessToken()){  //检查accessToken 为必须
          $arrayData=$zhwx->getUserList(); ##测试用户列表
           echo '<pre>';
            rint_r($arrayData);
          echo '</pre>';*/
       }
     }
    
     ######################################################
     服务号提供的接口:
         getUserList($next_openid=null)  获取用户列表
         getUserInfo($openid)            获取用户详细信息
         createUsersGroup($groupName)    创建分组
         moveUserGroup($toGroupid,$openid) 移动用户到组
         getUsersGroups()                  获取所有分组
         getUserGroup($openid)              获取用户所在的组
         updateUserGroup($groupId,$groupName) 修改组名
         createQrcode($scene_id,$qrcodeType=1,$expire_seconds=1800) 生成二维码
         uploadMedia($type, $file)  上传文件
         createMenu($menuListdata)   创建菜单
         queryMenu()                 查询菜单
         deleteMenu()                删除菜单
         sendMessage($touser, $data, $msgType = 'text') 主动某个用户发送数据
         newsUpload($data) 上传图文素材 按接口规定 $data 必须是二维数组
         mediaUpload($type,$filePath)  上传媒体文件 filePath 必须是文件绝对路径
         sendTemplateMessage($touser,$template_id,$url,$topColor,$data) 发送模板消息 通常为通知接口
         sendMassMessage($sendType,$touser=array(),$data)  群发消息
    
    
    

发布了186 篇原创文章 · 获赞 24 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/echocdzh/article/details/50608680
今日推荐