WeChat light contact, letter light contact_PHP tutorial

WBOY
Release: 2016-07-13 09:55:19
Original
877 people have browsed it

Light touch on WeChat, light touch on letter

WeChat is becoming more and more popular, but I always seem to have no feeling about WeChat. I feel that with QQ, I basically have no interest in other Tencent products.

However, a classmate recently planned to build a micro-official website. Knowing that I know something about web technology, I wanted to let me make one. After that, I downloaded WeChat and registered a public account... After reading some developer documents, I sent a message to WeChat. There were many things in WeChat that I had not learned before.

Having said a lot, let’s briefly talk about the process of making the micro-official website:

1. Enter the WeChat public platform: https://mp.weixin.qq.com/ and register a public account. The registration process is simple and I won’t introduce it here.

2. After logging in to the official account, open the official account settings and fill in some setting information. Of course, it is best to upload an avatar of the official account, so that you have the image of your own official account.

3. Click "Developer Center", there is a "Server Configuration" item, fill in the address of your own website (used as a public account platform), the address is a URL page used to interface with the public account ( Generally it is a dynamic file address, such as .php or .asp or .jsp, etc.). The development language I use here is php, so the registered address is: http://www.xxxxxxxxxx.com/weixin/wx.php.

4. Fill in the Token, which is like a key. You can draw a string at will, which is equivalent to a password. I set it up to wwwcom2015.

5. Message encryption method, just fill in the plain text, which is enough for testing.

6. Then write a class file in the weixin/wx.php file corresponding to your website server, such as class wxcall{}.

7. Write at least the following methods in wxcall:

(1) Verify the authenticity of the message:

<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) Verification:

<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) Reply message:

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

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

8. After verifying the authenticity of the message through the above methods (generally one verification can take 2 hours), you can reply to the message.

At least how to reply to the message and what skills are there in the reply content. More on that next time.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/992390.htmlTechArticleWeChat light contact, light contact WeChat is becoming more and more popular, but I always seem to have no feeling about WeChat. I feel that with QQ, I basically have no interest in other Tencent products. However...
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 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!