Home > php教程 > php手册 > body text

微信轻接触,信轻接触

WBOY
Release: 2016-06-13 09:05:37
Original
1015 people have browsed it

微信轻接触,信轻接触

微信越来越火了,但我一直对微信似乎没有什么感觉。我觉得有了QQ,基本上对腾讯的其它产品没有兴趣了。

不过,近期一个同学,打算建立一个微官网。知道我对网页技术这块有所了解,便希望让我制作一个。之后,我便下载了微信,注册了公众号......阅读一些开发者文档后,才发微信里面有很多我从前没有了解到的东西。

说了一堆,下面简单的说一下微官网制作过程吧:

1、进入微信公众平台:https://mp.weixin.qq.com/,注册一个公众号,注册过程简单,就不介绍了。

2、登录公众号后,打开公众号设置,填写一些设置信息,当然,最好把公众号的头像给上传一个,这样就有了自己公众号的形象了。

3、点击“开发者中心”,有一个“服务器配置”项,填写一个你自己的网站(用于做公众号平台的)地址,地址是一个与公众号做接口用的网址页面(一般是动态的文件地址,比如.php或.asp或.jsp等),我这里使用的开发语言是php,所以注册的地址是:http://www.xxxxxxxxxx.com/weixin/wx.php。

4、填写Token,这个就是一个密钥一样的东西,你随便拟一个字符串,相当于口令。我设置的是 wwwcom2015。

5、消息加密方式,填写明文即可,用于测试已够用了。

6、然后在你对应网站服务器的weixin/wx.php文件当中,写一个类文件,比如class wxcall{}。

7、在wxcall里面至少写以下这几个方法:

(1)验证消息真实性:

<span>private</span> <span>function</span><span> checkSignature()
    {
      </span><span>$signature</span> = <span>$_GET</span>["signature"<span>];
      </span><span>$timestamp</span> = <span>$_GET</span>["timestamp"<span>];
      </span><span>$nonce</span> = <span>$_GET</span>["nonce"<span>];
      </span><span>$token</span> =<span> TOKEN;
      </span><span>$tmpArr</span> = <span>array</span>(<span>$token</span>, <span>$timestamp</span>, <span>$nonce</span><span>);
      </span><span>sort</span>(<span>$tmpArr</span>,<span> SORT_STRING);
      </span><span>$tmpStr</span> = <span>implode</span>( <span>$tmpArr</span><span> );
      </span><span>$tmpStr</span> = <span>sha1</span>( <span>$tmpStr</span><span> );
      </span><span>if</span>( <span>$tmpStr</span> == <span>$signature</span><span> ){
             </span><span>return</span> <span>true</span><span>;
      }</span><span>else</span><span>{
             </span><span>return</span> <span>false</span><span>;
      }
    }</span>
Copy after login

(2)验证:

<span>function</span><span> valid(){
</span><span>if</span>(<span>$this</span>-><span>checkSignature()){
</span><span>echo</span> <span>$_GET</span>['echostr'<span>];
</span><span>exit</span><span>;
}
}</span>
Copy after login

(3)回复消息:

<span>function</span><span> responseMsg(){

</span><span>//</span><span>写你自己想要回复消息的一系列动作</span>
<span>
}</span>
Copy after login

8、通过上面几个方法,验证消息的真实性后(一般验证一次就可以管2个小时了),就可以回复消息了。

 

至少消息如何回复,回复的内容有什么技巧。下回再分说。

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!