PHP WeChat Enterprise callback mode opening and usage example sharing

Source: Internet
Author: User
This article mainly introduces the PHP Enterprise number callback mode opening and usage, combined with specific examples of the PHP Enterprise number callback mode to open and use the method, the code is provided with detailed explanatory notes to facilitate the reader to understand, the need for friends can refer to. I hope that you understand the enterprise number callback mode to open and use Help.


Summer internship, leading the development of enterprise number. Here to record the problems encountered, share to meet the same problem of small partners, hope to help small partners. Enterprise number registration part of the need to say, today record enterprise number-callback mode to open the PHP section.

In fact, the development of the document is really very detailed, and the use of the official demo, as long as a slight change can be used directly. But why do you always prompt for errors?

Let me first post the code that I verified the successful callback mode to open


<?php//callback to open include_once "wxbizmsgcrypt.php";//Assume the enterprise number on the public platform set the parameters as follows $encodingaeskey = "xxx"; $token = "xxx"; $corpId = " XXX ";///fill in your own relevant parameters, consistent with the public platform/*------------Use example one: Validation callback URL---------------* When the enterprise turns on callback mode, the enterprise number sends a GET request to the authentication URL assuming click Verification, The enterprise received a similar request: * get/cgi-bin/wxpush?msg_signature=5c45ff5e21c57e6ad56bac8758b79b1d9ac89fd3xtamp=1409659589&nonce= 263014780&echostr=p9nazczydtytweshep1vc5x9xho%2fqyx3zpb4yka9skld1dsh3iyt3tp3zndtp%2b4rpcs8tgae7oabo% 2bfzxvnaqq%3d%3d* http/1.1 Host:qy.weixin.qq.com When the request is received, the enterprise should 1. Resolves the parameters of the GET request, including the message body signature (msg_signature), timestamp (timestamp), Random string (nonce) and random encrypted strings (ECHOSTR), which are pushed by the public platform, are noted as URL decoding. 2. Verify the correctness of the message body Signature 3. Echostr the original text, the original text as a GET request response, return to the public platform 2nd, 3 steps can be provided by the Public Platform library function Verifyurl to achieve. *///$sVerifyMsgSig = Httputils.parseurl ("Msg_signature"); $sVerifyMsgSig = $_get["Msg_signature"];//" 5C45FF5E21C57E6AD56BAC8758B79B1D9AC89FD3 ";//$sVerifyTimeStamp = Httputils.parseurl (" timestamp "); $ Sverifytimestamp = $_get["timestamp"];//"1409659589";//$sVerifyNonce = Httputils.parseurl ("nonce"); $sVerifyNonCE = $_get["nonce"];//"263014780";//$sVerifyEchoStr = Httputils.parseurl ("Echostr"); $sVerifyEchoStr = $_get["Echostr "];//" p9nazczydtytweshep1vc5x9xho/qyx3zpb4yka9skld1dsh3iyt3tp3zndtp+4rpcs8tgae7oabo+fzxvnaqq== ";//Clear text required to return $ Echostr = ""; $wxcpt = new Wxbizmsgcrypt ($token, $encodingAesKey, $corpId); $errCode = $wxcpt->verifyurl ($  Sverifymsgsig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $SECHOSTR); if ($errCode = = 0) {echo $sEchoStr; Verify the URL is successful, return SECHOSTR//httputils.setresponce ($SECHOSTR);} else {print ("ERR:". $errCode. "\ n");}


It can be seen that the above code and demo to the basic consistent, a day ago the same code also verified the unsuccessful, after the study found that the URL to verify the domain name must be a trusted domain name. PS: I use Sina cloud, but I do not have real-name authentication, so there is a risk, when I real-name certification, it opened successfully.

Sentiment: Official documents are not wrong at any time, it is necessary to read the official documents carefully. It is also important that the domain name must be a trusted domain name during the enterprise number-callback mode.

Related recommendations:

PHP public number development, keyword reply using switch error

PHP Public number third-party platform full-network publishing problem

Public number Development Configuration Common error message Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.