zoukankan      html  css  js  c++  java
  • 微信开发中自动回复(扫码、关注推事件)

    1, 进入微信公众平台,开启自动回复功能

    2,进入基本配置
        服务器配置
    3, 找到刚设置的服务器地址,写如下内容(我的服务器地址:mp_event):
        
    4, 到weixinPush中写相关逻辑代码
        示例如下:
       //执行检测的信息

      47     public function weixin_run()

      48     {

      49         $this->responseMsg();

      50     $ids = '';

      51 

      52         switch ($this->MsgType)

      53         {

      54             case 'text':

      55                 $this->fun_xml('text', array($GLOBALS['config_info']['DEFAULT_MSG']));

      56                 break;

      57             case 'voice':

      58                 $this->fun_xml('text', array($GLOBALS['config_info']['DEFAULT_MSG']));

      59                 break;

      60             case 'image':

      61                 $str   = "类型:图片消息 ";

      62                 $str  .= '图片链接:' . $this->PicUrl . " ";

      63                 $str  .= 'MediaId:' . $this->MediaId . " ";

      64                 $arr[] = $str;

      65                 $this->fun_xml('text', $arr);

      66                 break;

      67             case 'video':

      68                 $str   = "类型:视频消息 ";

      69                 $str  .= '图片链接:' . $this->PicUrl . " ";

      70                 $str  .= 'MediaId:' . $this->MediaId . " ";

      71                 $str  .= 'ThumbMediaId:' . $this->ThumbMediaId ." ";

      72                 $arr[] = $str;

      73                 $this->fun_xml('text', $arr);

      74                 break;

      75             case 'location':

      76                 $str   = "类型:地理位置消息 ";

      77                 $str  .= '维度:' . $this->Location_X . " ";

      78                 $str  .= '精度:' . $this->Location_Y . " ";

      79                 $str  .= '地图缩放大小:' . $this->Scale . " ";

      80                 $str  .= '地理位置信息:' . $this->Label . " ";

      81                 $arr[] = $str;

      82                 $this->fun_xml('text', $arr);

      83                 break;

      84             case 'link':

      85                 $str   = "类型:链接消息 ";

      86                 $str  .= '标题:' . $this->Title . " ";

      87                 $str  .= '描述:' . $this->Description . " ";

      88                 $str  .= '链接:' . $this->Url . " ";

      89                 $arr[] = $str;

      90                 $this->fun_xml('text', $arr);

      91                 break;

      92              case 'event':

      93                 if($this->Event == 'subscribe')

      94                 {

                         //关注

                         做相应的处理

                         }

                }

     

    public function responseMsg()

     372     {   

     373         #$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

     374     $postStr = file_get_contents("php://input");

     375         

     376         if (!empty($postStr))

     377         {

     378             $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

     379         }

     382         foreach ($postObj AS $k => $v)

     383         {

     384             $str = $k . ' => ' . $v . " ";

     385             fwrite($file, $str);

     386         }   

     387         fwrite($file, " ");    

     388         fclose($file);

     389             $this->fromUsername = $postObj->FromUserName;

     390             $this->toUsername   = $postObj->ToUserName;

                  }   

     413         else

     414         {   

     415             echo "this a file for weixin API!";

     416             exit;

     417         }   

     418     }   

     
    至此已完成
    thinkphp 3.1环境
  • 相关阅读:
    iOS适配 旧项目工程在iOS9下不能正常显示
    字典的操作
    均摊时间复杂度
    C++基础
    机器学习入门学习线路
    C\C++对文件的读写操作
    python 函数基础
    关于string的练习题目
    C++之STL之string
    C++STL库之set的用法
  • 原文地址:https://www.cnblogs.com/qianlizeguo/p/6834525.html
Copyright © 2011-2022 走看看