1, 进入微信公众平台,开启自动回复功能
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 }