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 = "类型:图片消息\n";
62 $str .= ‘图片链接:‘ . $this->PicUrl . "\n";
63 $str .= ‘MediaId:‘ . $this->MediaId . "\n";
64 $arr[] = $str;
65 $this->fun_xml(‘text‘, $arr);
66 break;
67 case ‘video‘:
68 $str = "类型:视频消息\n";
69 $str .= ‘图片链接:‘ . $this->PicUrl . "\n";
70 $str .= ‘MediaId:‘ . $this->MediaId . "\n";
71 $str .= ‘ThumbMediaId:‘ . $this->ThumbMediaId ."\n";
72 $arr[] = $str;
73 $this->fun_xml(‘text‘, $arr);
74 break;
75 case ‘location‘:
76 $str = "类型:地理位置消息\n";
77 $str .= ‘维度:‘ . $this->Location_X . "\n";
78 $str .= ‘精度:‘ . $this->Location_Y . "\n";
79 $str .= ‘地图缩放大小:‘ . $this->Scale . "\n";
80 $str .= ‘地理位置信息:‘ . $this->Label . "\n";
81 $arr[] = $str;
82 $this->fun_xml(‘text‘, $arr);
83 break;
84 case ‘link‘:
85 $str = "类型:链接消息\n";
86 $str .= ‘标题:‘ . $this->Title . "\n";
87 $str .= ‘描述:‘ . $this->Description . "\n";
88 $str .= ‘链接:‘ . $this->Url . "\n";
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 . "\n";
385 fwrite($file, $str);
386 }
387 fwrite($file, "\n");
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环境