-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_2.bak
120 lines (106 loc) · 3.13 KB
/
message_2.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* wechat php test
*/
//define your token
define("TOKEN", "weinxinfc_token");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
$wechatObj->responseMsg();
class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET["echostr"];
//valid signature , option
if($this->checkSignature()){
echo $echoStr;
// exit;
}
else{
exit;
}
}
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//$postStr = file_get_contents("php://input");
//extract post data
if(!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$userMsgType=$postObj->MsgType;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if($userMsgType=='image')
{
$msgType = "text";
$contentStr = "点击下方‘+’,发送您的位置,刚上传的图片即可展示在‘楼盘实景’,让更多的房友足不出户即可欣赏 ";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
//将数据插入到数据库
//$wechatId=$fromUsername;
//$url=$postObj->PicUrl;
//$estateId=getEstateId($toUsername);
//$insertSql = "insert into Picture_Wall (estate_id,wechat_id,url) values (".$estateId.",".$wechatId.",".$url.");";
//$db=new mysqli("112.124.55.78", "zunhao", "655075d7dd", "wxfc");
$filename = 'log';
$fh = fopen($filename, "w");
echo fwrite($fh, $insertSql);
fclose($fh);
//$db->query($insertSql);
echo $resultStr;
}else{
echo "Input something...";
}
}
else{
echo "";
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
private function getEstateId($appid){
$con = mysql_connect("112.124.55.78","zunhao","655075d7dd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("wxfc", $con);
$query = "select estate_id from Estate where app_id= ".$appid;
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$estate_id=$row['estate_id']
}
mysql_close($con);
return $estate_id;
}
private function getNickName($openId){
}
}
?>