来源:自学PHP网 时间:2015-04-14 12:38 作者: 阅读:次
[导读] 2014年6月全国大学英语四、六级考试考试成绩于2014年8月20日上午9时发布我们提供微信查询方法1、关注微信公众账号二、回复四六级三、输入姓名和准考证号四、返回查询结果代码实现...
2014年6月全国大学英语四、六级考试考试成绩于2014年8月20日上午9时发布 我们提供微信查询方法 1、关注微信公众账号 二、回复“四六级” 三、输入姓名和准考证号 四、返回查询结果
代码实现 <?php 2 /* 3 方倍工作室 2014年6月全国大学英语四六级考试成绩查询 4 CopyRight 2014 All Rights Reserved 5 */ 6 7 define("TOKEN", "weixin"); 8 9 $wechatObj = new wechatCallbackapiTest(); 10 if (!isset($_GET['echostr'])) { 11 $wechatObj->responseMsg(); 12 }else{ 13 $wechatObj->valid(); 14 } 15 16 class wechatCallbackapiTest 17 { 18 public function valid() 19 { 20 $echoStr = $_GET["echostr"]; 21 $signature = $_GET["signature"]; 22 $timestamp = $_GET["timestamp"]; 23 $nonce = $_GET["nonce"]; 24 $token = TOKEN; 25 $tmpArr = array($token, $timestamp, $nonce); 26 sort($tmpArr); 27 $tmpStr = implode($tmpArr); 28 $tmpStr = sha1($tmpStr); 29 if($tmpStr == $signature){ 30 echo $echoStr; 31 exit; 32 } 33 } 34 35 public function responseMsg() 36 { 37 $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; 38 if (!empty($postStr)){ 39 $this->logger("R ".$postStr); 40 $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); 41 $RX_TYPE = trim($postObj->MsgType); 42 43 switch ($RX_TYPE) 44 { 45 case "event": 46 $result = $this->receiveEvent($postObj); 47 break; 48 case "text": 49 $result = $this->receiveText($postObj); 50 break; 51 } 52 $this->logger("T ".$result); 53 echo $result; 54 }else { 55 echo ""; 56 exit; 57 } 58 } 59 60 private function receiveEvent($object) 61 { 62 $content = ""; 63 switch ($object->Event) 64 { 65 case "subscribe": 66 $content = array(); 67 $content[] = array("Title" =>"2014年6月全国大学英语四六级考试成绩查询","Description" =>"", "PicUrl" =>"http://365jia.cn/uploads/13/0301/5130c2ff93618.jpg", "Url" =>"http://apix.sinaapp.com/cet/index.php?openid=".$object->FromUserName); 68 break; 69 } 70 if(is_array($content)){ 71 $result = $this->transmitNews($object, $content); 72 }else{ 73 $result = $this->transmitText($object, $content); 74 } 75 return $result; 76 } 77 78 private function receiveText($object) 79 { 80 $keyword = trim($object->Content); 81 if (strstr($keyword, "四六级") || strstr($keyword, "英语")){ 82 $content = array(); 83 $content[] = array("Title" =>"2014年6月全国大学英语四六级考试成绩查询","Description" =>"", "PicUrl" =>"http://365jia.cn/uploads/13/0301/5130c2ff93618.jpg", "Url" =>"http://apix.sinaapp.com/cet/index.php?openid=".$object->FromUserName); 84 }else{ 85 $content = date("Y-m-d H:i:s",time())."\n技术支持 方倍工作室"; 86 } 87 if(is_array($content)){ 88 $result = $this->transmitNews($object, $content); 89 }else{ 90 $result = $this->transmitText($object, $content); 91 } 92 return $result; 93 } 94 95 private function transmitText($object, $content) 96 { 97 $textTpl = "<xml> 98 <ToUserName><![CDATA[%s]]></ToUserName> 99 <FromUserName><![CDATA[%s]]></FromUserName> 100 <CreateTime>%s</CreateTime> 101 <MsgType><![CDATA[text]]></MsgType> 102 <Content><![CDATA[%s]]></Content> 103 </xml>"; 104 $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content); 105 return $result; 106 } 107 108 private function transmitNews($object, $arr_item) 109 { 110 if(!is_array($arr_item)) 111 return; 112 113 $itemTpl = " <item> 114 <Title><![CDATA[%s]]></Title> 115 <Description><![CDATA[%s]]></Description> 116 <PicUrl><![CDATA[%s]]></PicUrl> 117 <Url><![CDATA[%s]]></Url> 118 </item> 119 "; 120 $item_str = ""; 121 foreach ($arr_item as $item) 122 $item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']); 123 124 $newsTpl = "<xml> 125 <ToUserName><![CDATA[%s]]></ToUserName> 126 <FromUserName><![CDATA[%s]]></FromUserName> 127 <CreateTime>%s</CreateTime> 128 <MsgType><![CDATA[news]]></MsgType> 129 <Content><![CDATA[]]></Content> 130 <ArticleCount>%s</ArticleCount> 131 <Articles> 132 $item_str</Articles> 133 </xml>"; 134 135 $result = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item)); 136 return $result; 137 } 138 139 private function logger($log_content) 140 { 141 } 142 } 143 144 145 ?> |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com