微信公众平台开发四六级成绩查询

@date:2015-02-02 20:57:00

我们提供微信查询方法

1、关注微信公众账号

 

二、回复“四六级”

 

 三、输入姓名和准考证号

四、返回查询结果

 

代码实现



<?php /* 方倍工作室 2014年6月全国大学英语四六级考试成绩查询 CopyRight 2014 All Rights Reserved */

define("TOKEN", "weixin");

wechatObj = new wechatCallbackapiTest(); if (!isset(_GET['echostr'])) {
wechatObj->responseMsg(); }else{ wechatObj->valid();
}

class wechatCallbackapiTest
{
public function valid()
{
echoStr = _GET["echostr"];
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){
echo $echoStr;
exit;
}
}

</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> responseMsg()
{
    </span><span style="color: #800080;">$postStr</span> = <span style="color: #800080;">$GLOBALS</span>["HTTP_RAW_POST_DATA"<span style="color: #000000;">];
    </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$postStr</span><span style="color: #000000;">)){
        </span><span style="color: #800080;">$this</span>-&gt;logger("R ".<span style="color: #800080;">$postStr</span><span style="color: #000000;">);
        </span><span style="color: #800080;">$postObj</span> = <span style="color: #008080;">simplexml_load_string</span>(<span style="color: #800080;">$postStr</span>, 'SimpleXMLElement',<span style="color: #000000;"> LIBXML_NOCDATA);
        </span><span style="color: #800080;">$RX_TYPE</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$postObj</span>-&gt;<span style="color: #000000;">MsgType);

        </span><span style="color: #0000ff;">switch</span> (<span style="color: #800080;">$RX_TYPE</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">case</span> "event":
                <span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>-&gt;receiveEvent(<span style="color: #800080;">$postObj</span><span style="color: #000000;">);
                </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;
            </span><span style="color: #0000ff;">case</span> "text":
                <span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>-&gt;receiveText(<span style="color: #800080;">$postObj</span><span style="color: #000000;">);
                </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;
        }
        </span><span style="color: #800080;">$this</span>-&gt;logger("T ".<span style="color: #800080;">$result</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
    }</span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
        </span><span style="color: #0000ff;">echo</span> ""<span style="color: #000000;">;
        </span><span style="color: #0000ff;">exit</span><span style="color: #000000;">;
    }
}

</span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span> receiveEvent(<span style="color: #800080;">$object</span><span style="color: #000000;">)
{
    </span><span style="color: #800080;">$content</span> = ""<span style="color: #000000;">;
    </span><span style="color: #0000ff;">switch</span> (<span style="color: #800080;">$object</span>-&gt;<span style="color: #000000;">Event)
    {
        </span><span style="color: #0000ff;">case</span> "subscribe":
            <span style="color: #800080;">$content</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
            </span><span style="color: #800080;">$content</span>[] = <span style="color: #0000ff;">array</span>("Title" =&gt;"2014年6月全国大学英语四六级考试成绩查询","Description" =&gt;"", "PicUrl" =&gt;"http://365jia.cn/uploads/13/0301/5130c2ff93618.jpg", "Url" =&gt;"http://apix.sinaapp.com/cet/index.php?openid=".<span style="color: #800080;">$object</span>-&gt;<span style="color: #000000;">FromUserName);
            </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;
    }
    </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$content</span><span style="color: #000000;">)){
        </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>-&gt;transmitNews(<span style="color: #800080;">$object</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">);
    }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
        </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>-&gt;transmitText(<span style="color: #800080;">$object</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
}

</span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span> receiveText(<span style="color: #800080;">$object</span><span style="color: #000000;">)
{
    </span><span style="color: #800080;">$keyword</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$object</span>-&gt;<span style="color: #000000;">Content);
    </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">strstr</span>(<span style="color: #800080;">$keyword</span>, "四六级") || <span style="color: #008080;">strstr</span>(<span style="color: #800080;">$keyword</span>, "英语"<span style="color: #000000;">)){
        </span><span style="color: #800080;">$content</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
        </span><span style="color: #800080;">$content</span>[] = <span style="color: #0000ff;">array</span>("Title" =&gt;"2014年6月全国大学英语四六级考试成绩查询","Description" =&gt;"", "PicUrl" =&gt;"http://365jia.cn/uploads/13/0301/5130c2ff93618.jpg", "Url" =&gt;"http://apix.sinaapp.com/cet/index.php?openid=".<span style="color: #800080;">$object</span>-&gt;<span style="color: #000000;">FromUserName);
    }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
        </span><span style="color: #800080;">$content</span> = <span style="color: #008080;">date</span>("Y-m-d H:i:s",<span style="color: #008080;">time</span>())."\n技术支持 方倍工作室"<span style="color: #000000;">;
    }
    </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$content</span><span style="color: #000000;">)){
        </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>-&gt;transmitNews(<span style="color: #800080;">$object</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">);
    }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
        </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>-&gt;transmitText(<span style="color: #800080;">$object</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
}

</span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span> transmitText(<span style="color: #800080;">$object</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">)
{
    </span><span style="color: #800080;">$textTpl</span> = "<span style="color: #000000;">&lt;xml&gt;

<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
result = sprintf(textTpl, object->FromUserName, object->ToUserName, time(), content); return result;
}

</span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span> transmitNews(<span style="color: #800080;">$object</span>, <span style="color: #800080;">$arr_item</span><span style="color: #000000;">)
{
    </span><span style="color: #0000ff;">if</span>(!<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$arr_item</span><span style="color: #000000;">))
        </span><span style="color: #0000ff;">return</span><span style="color: #000000;">;

    </span><span style="color: #800080;">$itemTpl</span> = "<span style="color: #000000;">    &lt;item&gt;
    &lt;Title&gt;&lt;![CDATA[%s]]&gt;&lt;/Title&gt;
    &lt;Description&gt;&lt;![CDATA[%s]]&gt;&lt;/Description&gt;
    &lt;PicUrl&gt;&lt;![CDATA[%s]]&gt;&lt;/PicUrl&gt;
    &lt;Url&gt;&lt;![CDATA[%s]]&gt;&lt;/Url&gt;
&lt;/item&gt;

";
item_str = ""; foreach (arr_item as item) item_str .= sprintf(itemTpl, item['Title'], item['Description'], item['PicUrl'], $item['Url']);

    </span><span style="color: #800080;">$newsTpl</span> = "<span style="color: #000000;">&lt;xml&gt;

<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<Content><![CDATA[]]></Content>
<ArticleCount>%s</ArticleCount>
<Articles>
$item_str</Articles>
</xml>
";

    </span><span style="color: #800080;">$result</span> = <span style="color: #008080;">sprintf</span>(<span style="color: #800080;">$newsTpl</span>, <span style="color: #800080;">$object</span>-&gt;FromUserName, <span style="color: #800080;">$object</span>-&gt;ToUserName, <span style="color: #008080;">time</span>(), <span style="color: #008080;">count</span>(<span style="color: #800080;">$arr_item</span><span style="color: #000000;">));
    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
}

</span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span> logger(<span style="color: #800080;">$log_content</span><span style="color: #000000;">)
{
}

}

?>

 

Build by Loppo 0.6.14