Current location - Quotes Website - Signature design - Enterprise wechat application open API receives messages.
Enterprise wechat application open API receives messages.
Hello! I'm glad to answer your question. The tp framework is used, so pay attention. This paper takes ThinkPHP version 3.2.3 PHP version 5.3 as an example.

Keng 1

Download the official example of the processing interface and put it in ThinkPHP >; Ku> WeChat (self-built) Directory

For WXBizMsgCrypt.php read WXBizMsgCrypt.class.php.

Declare the namespace wechat in WXBizMsgCrypt;

Introduce the class usewechat wxbizzmsgcrypt into the controller you need;

After that, use the official sample copy to enter your project. Even if the integration is completed, the process is quite simple, but! The writing of constructors has changed before and after PHP5.3. Constructors can no longer be named as function names after class names. The constructor must be declared with __construct. In other words, integration with official examples is bound to go wrong, provided that you also use the version after PHP5.3.

So we still need

Change the name of the wxbizzmsgcrypt function in the wxbizzmsgcrypt file to __construct.

Change the name of pkcs7Encoder function in pkcs7Encoder file to _ _ construction.

You're finished. It may not be suitable for the lower version of Thinkphp or php below 5.3. I haven't tested other versions.

Kenji

When filling in the callback information of the enterprise number and clicking Save is unsuccessful, it really works wonders to click it a few times more!

This is not a joke ~ ~ because the random signature sent by Enterprise to developers is likely to have a+sign. When you get the URL, php will automatically filter the+sign as a space, resulting in the inconsistency between the sent signature and the actual address signature, the signature verification failed, and the error 4000 1: signature verification error was reported.

Of course, you can also restore the space to a+sign, which can ensure that it is consistent with the signature address sent. (I think this is a small bug in the WeChat callback, and the signature should not have such a special symbol. )

Keng3

They all passed the verification, and they all returned to the clear text that WeChat wanted, but they still failed. What? Print locally, yes. Baidu has searched it all. I have tried everything, such as removing the BOM header and changing the header. I really decrypted it and sent the decryption result back to WeChat, but it still doesn't work, WTF. .

Did you really return to plaintext? Do you think it is right to print locally? Wrong. There is a thing called buffering.

The contents in the buffer will not be printed locally. When Wechat visits your website, the first thing you get is the contents of the buffer, not the plaintext you output. So the way to clear the buffer first is to use ob_clean () before echo, and it is estimated that other frameworks will do the same.