首頁 >php教程 >php手册 >微信公众平台开发(103) 四六级成绩查询,103成绩查询

微信公众平台开发(103) 四六级成绩查询,103成绩查询

WBOY
WBOY原創
2016-06-13 09:27:001122瀏覽

微信公众平台开发(103) 四六级成绩查询,103成绩查询

2014年6月全国大学英语四、六级考试考试成绩于2014年8月20日上午9时发布

我们提供微信查询方法

1、关注微信公众账号

二、回复“四六级”

 三、输入姓名和准考证号

四、返回查询结果

 

代码实现

<span>  1</span> <?<span>php
</span><span>  2</span> <span>/*</span>
<span>  3</span> <span>    方倍工作室 2014年6月全国大学英语四六级考试成绩查询
</span><span>  4</span> <span>    CopyRight 2014 All Rights Reserved
</span><span>  5</span> <span>*/</span>
<span>  6</span> 
<span>  7</span> <span>define</span>("TOKEN", "weixin"<span>);
</span><span>  8</span> 
<span>  9</span> <span>$wechatObj</span> = <span>new</span><span> wechatCallbackapiTest();
</span><span> 10</span> <span>if</span> (!<span>isset</span>(<span>$_GET</span>['echostr'<span>])) {
</span><span> 11</span>     <span>$wechatObj</span>-><span>responseMsg();
</span><span> 12</span> }<span>else</span><span>{
</span><span> 13</span>     <span>$wechatObj</span>-><span>valid();
</span><span> 14</span> <span>}
</span><span> 15</span> 
<span> 16</span> <span>class</span><span> wechatCallbackapiTest
</span><span> 17</span> <span>{
</span><span> 18</span>     <span>public</span> <span>function</span><span> valid()
</span><span> 19</span> <span>    {
</span><span> 20</span>         <span>$echoStr</span> = <span>$_GET</span>["echostr"<span>];
</span><span> 21</span>         <span>$signature</span> = <span>$_GET</span>["signature"<span>];
</span><span> 22</span>         <span>$timestamp</span> = <span>$_GET</span>["timestamp"<span>];
</span><span> 23</span>         <span>$nonce</span> = <span>$_GET</span>["nonce"<span>];
</span><span> 24</span>         <span>$token</span> =<span> TOKEN;
</span><span> 25</span>         <span>$tmpArr</span> = <span>array</span>(<span>$token</span>, <span>$timestamp</span>, <span>$nonce</span><span>);
</span><span> 26</span>         <span>sort</span>(<span>$tmpArr</span><span>);
</span><span> 27</span>         <span>$tmpStr</span> = <span>implode</span>(<span>$tmpArr</span><span>);
</span><span> 28</span>         <span>$tmpStr</span> = <span>sha1</span>(<span>$tmpStr</span><span>);
</span><span> 29</span>         <span>if</span>(<span>$tmpStr</span> == <span>$signature</span><span>){
</span><span> 30</span>             <span>echo</span> <span>$echoStr</span><span>;
</span><span> 31</span>             <span>exit</span><span>;
</span><span> 32</span> <span>        }
</span><span> 33</span> <span>    }
</span><span> 34</span> 
<span> 35</span>     <span>public</span> <span>function</span><span> responseMsg()
</span><span> 36</span> <span>    {
</span><span> 37</span>         <span>$postStr</span> = <span>$GLOBALS</span>["HTTP_RAW_POST_DATA"<span>];
</span><span> 38</span>         <span>if</span> (!<span>empty</span>(<span>$postStr</span><span>)){
</span><span> 39</span>             <span>$this</span>->logger("R ".<span>$postStr</span><span>);
</span><span> 40</span>             <span>$postObj</span> = <span>simplexml_load_string</span>(<span>$postStr</span>, 'SimpleXMLElement',<span> LIBXML_NOCDATA);
</span><span> 41</span>             <span>$RX_TYPE</span> = <span>trim</span>(<span>$postObj</span>-><span>MsgType);
</span><span> 42</span> 
<span> 43</span>             <span>switch</span> (<span>$RX_TYPE</span><span>)
</span><span> 44</span> <span>            {
</span><span> 45</span>                 <span>case</span> "event":
<span> 46</span>                     <span>$result</span> = <span>$this</span>->receiveEvent(<span>$postObj</span><span>);
</span><span> 47</span>                     <span>break</span><span>;
</span><span> 48</span>                 <span>case</span> "text":
<span> 49</span>                     <span>$result</span> = <span>$this</span>->receiveText(<span>$postObj</span><span>);
</span><span> 50</span>                     <span>break</span><span>;
</span><span> 51</span> <span>            }
</span><span> 52</span>             <span>$this</span>->logger("T ".<span>$result</span><span>);
</span><span> 53</span>             <span>echo</span> <span>$result</span><span>;
</span><span> 54</span>         }<span>else</span><span> {
</span><span> 55</span>             <span>echo</span> ""<span>;
</span><span> 56</span>             <span>exit</span><span>;
</span><span> 57</span> <span>        }
</span><span> 58</span> <span>    }
</span><span> 59</span>     
<span> 60</span>     <span>private</span> <span>function</span> receiveEvent(<span>$object</span><span>)
</span><span> 61</span> <span>    {
</span><span> 62</span>         <span>$content</span> = ""<span>;
</span><span> 63</span>         <span>switch</span> (<span>$object</span>-><span>Event)
</span><span> 64</span> <span>        {
</span><span> 65</span>             <span>case</span> "subscribe":
<span> 66</span>                 <span>$content</span> = <span>array</span><span>();
</span><span> 67</span>                 <span>$content</span>[] = <span>array</span>("Title" =>"2014年6月全国大学英语四六级考试成绩查询","Description" =>"", "PicUrl" =>"http://365jia.cn/uploads/13/0301/5130c2ff93618.jpg", "Url" =>"http://apix.sinaapp.com/cet/index.php?openid=".<span>$object</span>-><span>FromUserName);
</span><span> 68</span>                 <span>break</span><span>;
</span><span> 69</span> <span>        }
</span><span> 70</span>         <span>if</span>(<span>is_array</span>(<span>$content</span><span>)){
</span><span> 71</span>             <span>$result</span> = <span>$this</span>->transmitNews(<span>$object</span>, <span>$content</span><span>);
</span><span> 72</span>         }<span>else</span><span>{
</span><span> 73</span>             <span>$result</span> = <span>$this</span>->transmitText(<span>$object</span>, <span>$content</span><span>);
</span><span> 74</span> <span>        }
</span><span> 75</span>         <span>return</span> <span>$result</span><span>;
</span><span> 76</span> <span>    }
</span><span> 77</span>   
<span> 78</span>     <span>private</span> <span>function</span> receiveText(<span>$object</span><span>)
</span><span> 79</span> <span>    {
</span><span> 80</span>         <span>$keyword</span> = <span>trim</span>(<span>$object</span>-><span>Content);
</span><span> 81</span>         <span>if</span> (<span>strstr</span>(<span>$keyword</span>, "四六级") || <span>strstr</span>(<span>$keyword</span>, "英语"<span>)){
</span><span> 82</span>             <span>$content</span> = <span>array</span><span>();
</span><span> 83</span>             <span>$content</span>[] = <span>array</span>("Title" =>"2014年6月全国大学英语四六级考试成绩查询","Description" =>"", "PicUrl" =>"http://365jia.cn/uploads/13/0301/5130c2ff93618.jpg", "Url" =>"http://apix.sinaapp.com/cet/index.php?openid=".<span>$object</span>-><span>FromUserName);
</span><span> 84</span>         }<span>else</span><span>{
</span><span> 85</span>             <span>$content</span> = <span>date</span>("Y-m-d H:i:s",<span>time</span>())."\n技术支持 方倍工作室"<span>;
</span><span> 86</span> <span>        }
</span><span> 87</span>         <span>if</span>(<span>is_array</span>(<span>$content</span><span>)){
</span><span> 88</span>             <span>$result</span> = <span>$this</span>->transmitNews(<span>$object</span>, <span>$content</span><span>);
</span><span> 89</span>         }<span>else</span><span>{
</span><span> 90</span>             <span>$result</span> = <span>$this</span>->transmitText(<span>$object</span>, <span>$content</span><span>);
</span><span> 91</span> <span>        }
</span><span> 92</span>         <span>return</span> <span>$result</span><span>;
</span><span> 93</span> <span>    }
</span><span> 94</span> 
<span> 95</span>     <span>private</span> <span>function</span> transmitText(<span>$object</span>, <span>$content</span><span>)
</span><span> 96</span> <span>    {
</span><span> 97</span>         <span>$textTpl</span> = "<span><xml>
</span><span> 98</span> <span><ToUserName><![CDATA[%s]]></ToUserName>
</span><span> 99</span> <span><FromUserName><![CDATA[%s]]></FromUserName>
</span><span>100</span> <span><CreateTime>%s</CreateTime>
</span><span>101</span> <span><MsgType><![CDATA[text]]></MsgType>
</span><span>102</span> <span><Content><![CDATA[%s]]></Content>
</span><span>103</span> </xml>"<span>;
</span><span>104</span>         <span>$result</span> = <span>sprintf</span>(<span>$textTpl</span>, <span>$object</span>->FromUserName, <span>$object</span>->ToUserName, <span>time</span>(), <span>$content</span><span>);
</span><span>105</span>         <span>return</span> <span>$result</span><span>;
</span><span>106</span> <span>    }
</span><span>107</span> 
<span>108</span>     <span>private</span> <span>function</span> transmitNews(<span>$object</span>, <span>$arr_item</span><span>)
</span><span>109</span> <span>    {
</span><span>110</span>         <span>if</span>(!<span>is_array</span>(<span>$arr_item</span><span>))
</span><span>111</span>             <span>return</span><span>;
</span><span>112</span> 
<span>113</span>         <span>$itemTpl</span> = "<span>    <item>
</span><span>114</span> <span>        <Title><![CDATA[%s]]></Title>
</span><span>115</span> <span>        <Description><![CDATA[%s]]></Description>
</span><span>116</span> <span>        <PicUrl><![CDATA[%s]]></PicUrl>
</span><span>117</span> <span>        <Url><![CDATA[%s]]></Url>
</span><span>118</span> <span>    </item>
</span><span>119</span> "<span>;
</span><span>120</span>         <span>$item_str</span> = ""<span>;
</span><span>121</span>         <span>foreach</span> (<span>$arr_item</span> <span>as</span> <span>$item</span><span>)
</span><span>122</span>             <span>$item_str</span> .= <span>sprintf</span>(<span>$itemTpl</span>, <span>$item</span>['Title'], <span>$item</span>['Description'], <span>$item</span>['PicUrl'], <span>$item</span>['Url'<span>]);
</span><span>123</span> 
<span>124</span>         <span>$newsTpl</span> = "<span><xml>
</span><span>125</span> <span><ToUserName><![CDATA[%s]]></ToUserName>
</span><span>126</span> <span><FromUserName><![CDATA[%s]]></FromUserName>
</span><span>127</span> <span><CreateTime>%s</CreateTime>
</span><span>128</span> <span><MsgType><![CDATA[news]]></MsgType>
</span><span>129</span> <span><Content><![CDATA[]]></Content>
</span><span>130</span> <span><ArticleCount>%s</ArticleCount>
</span><span>131</span> <span><Articles>
</span><span>132</span> <span>$item_str</span><span></Articles>
</span><span>133</span> </xml>"<span>;
</span><span>134</span> 
<span>135</span>         <span>$result</span> = <span>sprintf</span>(<span>$newsTpl</span>, <span>$object</span>->FromUserName, <span>$object</span>->ToUserName, <span>time</span>(), <span>count</span>(<span>$arr_item</span><span>));
</span><span>136</span>         <span>return</span> <span>$result</span><span>;
</span><span>137</span> <span>    }
</span><span>138</span> 
<span>139</span>     <span>private</span> <span>function</span> logger(<span>$log_content</span><span>)
</span><span>140</span> <span>    {
</span><span>141</span> <span>    }
</span><span>142</span> <span>}
</span><span>143</span> 
<span>144</span> 
<span>145</span> ?>

 

微信公众平台开发实例

京东或当当都有这本书卖《微信公众平台应用开发实战》作者钟志勇,腾讯公司资深软件研发工程师兼微信公众平台应用开发先驱者撰写,权威性毋庸置疑
  全面介绍微信公众平台应用开发所需各项技术,系统解读微信公众平台开放的API和各项高级功能,逐步讲解微信公众平台应用开发的流程、方法和技巧
  注重实战,不仅通过3个案例呈现了娱乐型、应用型、游戏型应用的完整开发过程,而且还实现了一个快速开发公众平台应用的框架,可以直接使用。
 

微信公众平台的高级功可以点进去页面显示不存在?

你是新注册的账号吗?要是新账号,不显示应该是因为还没被审核通过吧。要不是新账号,就清理下浏览器缓存,要么就换台机器试试。应该不会有别的原因了。
 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn