php微信开发之关键词回复功能

本文原创自news.mkq.online
本文地址:news.wpj.online
版权声明:本文为原创文章,版权牛站www.niuzhan.com所有
本文实例为大家分享了php微信开发之关键词回复的具体代码,供大家参考,具体内容如下

view sourceprint?
01

10
$wechatObj->responseMsg();
11
class wechatCallbackapiTest
12
{
13
public function valid()
14
{
15
$echoStr = $_GET[“echostr”];
16

17
//valid signature , option
18
if($this->checkSignature()){
19
echo $echoStr;
20
exit;
21
}
22
}
23

24
public function responseMsg()
25
{
26
//get post data, May be due to the different environments
27
$postStr = $GLOBALS[“HTTP_RAW_POST_DATA”];
28

29
//extract post data
30
if (!empty($postStr)){
31

32
p o s t O b j = s i m p l e x m l l o a d s t r i n g ( postObj = simplexml_load_string( postObj=simplexmlloadstring(postStr, ‘SimpleXMLElement’, LIBXML_NOCDATA);
33
$fromUsername = $postObj->FromUserName;
34
$toUsername = $postObj->ToUserName;
35
k e y w o r d = t r i m ( keyword = trim( keyword=trim(postObj->Content);
36
$time = time();
37
$textTpl = “ %s 0”;
38
if(!empty( $keyword ))
39
{
40
m s g T y p e = " t e x t " ; 41 i f ( msgType = "text"; 41 if( msgType="text";41if(keyword==“1”){
42
KaTeX parse error: Expected 'EOF', got '}' at position 23: …Str = "qiphon";}̲ 43 if(keyword==“2”){
44
KaTeX parse error: Expected 'EOF', got '}' at position 36: …环境违法行为举报奖励办法》";}̲ 45 if(keyword==“3”){
46
$contentStr = “31离婚协议\n32租房合同\n33交通事故协议书”;}
47
r e s u l t S t r = s p r i n t f ( resultStr = sprintf( resultStr=sprintf(textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
48
echo $resultStr;
49
}else{
50
echo “Input something…”;
51
}
52

53
}else {
54
echo “”;
55
exit;
56
}
57
}
58

59
private function checkSignature()
60
{
61
$signature = $_GET[“signature”];
62
$timestamp = $_GET[“timestamp”];
63
$nonce = $_GET[“nonce”];
64

65
$token = TOKEN;
66
t m p A r r = a r r a y ( tmpArr = array( tmpArr=array(token, $timestamp, n o n c e ) ; 67 s o r t ( nonce); 67 sort( nonce);67sort(tmpArr);
68
$tmpStr = implode( $tmpArr );
69
$tmpStr = sha1( $tmpStr );
70

71
if( $tmpStr == $signature ){
72
return true;
73
}else{
74
return false;
75
}
76
}
77
}
78

79
?>
以上就是本文的全部内容,希望对大家的学习有所帮助。

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页