1. Configuration parameters
define('WEIXIN_APPID', 'wxzzzzzzzz'); define('WEIXIN_APPSECRET', 'ouewjdsaudsamkh'); define('WEIXIN_TOKEN', '9973833232232'); define('WEIXIN_NOTIFY_URL', '/xx/xx'); define('WEIXIN_MCHID', '322221121'); define('WEIXIN_KEY', 'xddsdswewew');
1) WeChat official account development ID
WEIXIN_APPID: Application ID
WEIXIN_APPSECRET: Application key
Enter the homepage of the public platform and click on the Developer Center, you can see that these two are available in the configuration page by default.
2) Server configuration
WEIXIN_TOKEN, that is, token token, custom, must be in English or numeric, with a length of 3-32 characters.
The URL server address, which means the entrance address of the WeChat official account. In this page, I will do signature verification or receive event messages, and click to view WeChat-related documents.
1. Signature verification: When modifying the configuration, you need to use this address to perform signature verification.
2. Receive event messages: It means pushing some messages when you are following, and you can do some specific logical operations.
3) WeChat payment configuration
Click on the WeChat Payment Menu
WEIXIN_MCHID: Merchant number, you can view it in the merchant information
WEIXIN_NOTIFY_URL: WeChat Pay asynchronous callback API, which can update order status, send push and other logic
WEIXIN_KEY: To set this payment key, you must log in to the WeChat Pay Merchant Platform. After logging in, click to enter API security, then download the certificate and set the key yourself, and it will be OK.
2. Request and debugging
There is a very convenient curl in php, here is CURLOPT_SSL_VERIFYPEER. This attribute was not added at the beginning, and the data returned every time when requesting the WeChat server is false. Later, I used firefox's HttpRequester to simulate the request. I can return to the data. After searching for the information, I found that I want to set this property.
CURLOPT_SSL_VERIFYPEER: Whether to detect whether the server's certificate is issued by an authorized CA certified by a regular browser
/**
* Original POST
* @param $url The url address requested
* @param $raw raw data, can be a string or an array
* @return mixed Return the request value
*/
public function rawpost($url, $raw)
{
$resource = curl_init();
curl_setopt($resource, CURLOPT_POST, true);
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_POSTFIELDS, $raw);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($resource, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($resource, CURLOPT_HTTPHEADER, array('Expect:'));
$data = curl_exec($resource);
curl_close($resource);
return $data;
}
Here we recommend HttpRequester, this plugin can simulate various submissions such as post and get, and you can also choose from content type.
WeChat development also provides an online testing interface.Click to view the WeChat public platform interface debugging tool 。
When requesting debugging, WeChat will return various return codes.Click to view the global return code description 。