Home  >  Article  >  Backend Development  >  Configuration and requests for WeChat public platform development, WeChat public platform_PHP tutorial

Configuration and requests for WeChat public platform development, WeChat public platform_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:44:24812browse

Configuration and requests for WeChat public platform development, WeChat public platform

1. Configuration parameters

define('WEIXIN_APPID', 'wxzzzzzzzz');
define('WEIXIN_APPSECRET', 'ouewjdsaudsamkh');
define('WEIXIN_TOKEN', '9973833232232');
define('WEIXIN_NOTIFY_URL', 'http://xx.com/xx/xx');
define('WEIXIN_MCHID', '322221121');
define('WEIXIN_KEY', 'xddsdswewew');

1) WeChat public account ID is under development

WEIXIN_APPID: Application ID

WEIXIN_APPSECRET: Application Key

Go to the homepage of the public platform, click on the Developer Center, and you will be able to see that in the configuration page, these two are available by default.

2) Server configuration

WEIXIN_TOKEN, which is the token, is customized and must be in English or numbers, with a length of 3-32 characters.

URL server address, which is the entrance address of the WeChat official account. In this page, I will do signature verification or receive event messages, click to view WeChat related documents.

1. Signature verification: When modifying the configuration, signature verification needs to be done through this address

2. Receive event messages: It means pushing some messages when you pay attention, and you can do some specific logical operations

3) WeChat payment configuration

Click on the WeChat payment menu

WEIXIN_MCHID: Merchant number, which can be viewed in the merchant information

WEIXIN_NOTIFY_URL: WeChat payment asynchronous callback API, which can update order status, send push and other logic

WEIXIN_KEY: To set this payment key, you need to log in to the WeChat payment merchant platform. After logging in, click to enter API security, then download the certificate and set the key yourself, and it is 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 was false. Later, I used firefox's HttpRequester to simulate a request, and I could return to the data. After searching for the information, I found that I needed to set this attribute.

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 requested url address
* @param $raw original data, which can be a string or an array
* @return mixed Returns 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 plug-in can simulate various submissions such as post and get. The content type can also be selected.

WeChat development also provides a place to test the interface online. Click to view the WeChat public platform interface debugging tool.

When requesting debugging, WeChat will return various return codes. Click to view global return code description.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1049123.htmlTechArticleConfiguration and requests for WeChat public platform development, WeChat public platform 1. Configuration parameters define('WEIXIN_APPID', 'wxzzzzzzzz ');define('WEIXIN_APPSECRET', 'ouewjdsaudsamkh');define('WEIXIN...
Statement:
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