<?php /** * WeChat PHP Test */ Define your Token Define ("TOKEN", "TOKEN on your Application"); $WECHATOBJ = new Wechatcallbackapitest (); $WECHATOBJ->valid (); Class Wechatcallbackapitest { Public Function Valid () { $ECHOSTR = $_get["Echostr"]; Valid signature, option if ($this->checksignature ()) { $this->responsemsg (); Exit } } Public Function responsemsg () { Get post data, May is due to the different environments $POSTSTR = $GLOBALS ["Http_raw_post_data"]; Extract Post Data
if (!empty ($POSTSTR)) {
$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', libxml_nocdata);
$fromUsername = $POSTOBJ->fromusername;
$toUsername = $POSTOBJ->tousername;
$keyword = Trim ($postObj->content);
$time = time ();
$msgType = "text";
$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 (!empty ($keyword))
{
$CONTENTSTR = $this->keyrep ($keyword);
if (empty ($CONTENTSTR))
{
$CONTENTSTR = "You are intentional, no culture is really terrible";//You are intentional, no culture really terrible;
}
$CONTENTSTR = @iconv (' UTF-8 ', ' gb2312 ', $keyword);
$RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
Echo $resultStr;
}else{
$contentStr = ' No culture really terrible, incredibly can't type! ';//$this->keyrep ($keyword);
$CONTENTSTR = @iconv (' UTF-8 ', ' gb2312 ', $keyword);
$RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);
Echo $resultStr;
} }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;
}
}
function Keyrep ($key)
{
return $key;
if ($key = = ' Hi ' | | $key = ' in? ' | | $key = ' Hello ') {
$MT = Mt_rand (1,17);
$array = Array (1=> ' suicide, later) ... ',2=> ' Something for me please shout! ',3=> ' I was running naked, had rushed out of the service area ',4=> ' I now position: WC; posture: squat; face: twitch; state: Force ... ',5=> ' to eat, if you are handsome, please contact me, if you are a beautiful woman ..... Even if you are beautiful, I have to eat first, ',6=> '
In the bath ~ declined to sit on the sidelines!! ^_^ 0 ',7=> ' have bears out?] I'm going to snare and come back as soon as possible. ',8=> ' Hello, I am 500, would you be 250? ',9=> ' Hello! Garbled ah, again send ',10=> '
It's not that I ignore you, but time is hard to resist! ',11=> ' What you just said, I didn't see clearly, please say it again! ',12=> ' hair more than a few times ah ~ ~ More than a few times I will return to you. ',13=> ' This man has died, something burning! ',14=> ' good, not anxious oh ... ',15=> ' hello. I'm going to kill a couple of people and come back soon. ',16=> ' I have become immortal? Buddha said that there is smoke, no fire can not be a fairy. ',17=> '
You want to talk to me? Are you really going to talk to me? Are you sure you want to say something? Must you say it? Then you say, this is the automatic reply, anyway I can't see in fact I am in ~ just don't return you to take me how? '
);
return $array [$MT];
}
if ($key = = ' by ' | | $key = ' AH ' | | $key = ' ")
{
$MT = Mt_rand (1,19);
$array = Array (1=> ' The beginning of the person) sex is good? ',2=> ' The way forward? I hope you can go down on your own? And I'm riding the ',3=> ' joke what is it? That's what I'm saying to you right now. ',4=> ' Everybody says I'm ugly? In fact, I'm just not obvious. ',5=> ' A; how did the pig die? B; How do I know ',6=> ' when you're not dead?
Obama has killed two people with his namesake? Altman, you have to be careful. ',7=> ' Some people alive? He's dead. Some people are alive? ',8=> ', sister, you're on a boat? Brother, I'm walking ashore. "It is said that very stupid people see all are singing out." ',9=> ' I've only got two things in my life? That's not going to happen. ',10=> '
Past this village? There's no store. That's because there's a branch. ',11=> ' I thought you were just a ball? Didn't think? You're a real ball. ',12=> ' You finally come, I've been looking for you for n years, what did you do to Mars? I'm going to Pluto and I'll talk to you later, don't walk away ',13=> ' you have the right to remain silent, everything you say will be recorded as a record. You can ask for a proxy server if the network will not be available for you to assign one. ',14=> ' I am being wanted by Interpol worldwide, if you have the message of this person, please call the local alarm phone ',15=> ' bath ~ declined to sit on the sidelines!! ^_^ 0 ',16=> ', here is the mobile Secretary, Meimei please send again, I will contact you, sister please send another two times, I will contact you, brother, brother will not send again, because hair also don't contact you! ',17=> '
In fact, I am in ~ just don't return what do you take me? ',18=> ' What you just said, I didn't see clearly, please say it again! ',19=> ' well-behaved, not anxious ... ');
return $array [$MT];
}
if ($key = = ' Excuse me ')
{
$MT = Mt_rand (1,5);
$array = Array (1=> ' My face oil??) I do not know ',2=> ' go, I invite you to eat ',3=> ' This person has died, something burning! ',4=> ' Hello! What the hell! Garbled ah, again hair ',5=> ' joke is what?? is what I'm saying to you right now. ');
return $array [$MT];
}
Return "";
}
function Keylist ()
{
$array = Array (1=> ' Hi ',2=> ' hello ',3=> ' by ',4=> ' in ',5=> ' ask ');
}
} ?> |