Home >Backend Development >PHP Tutorial >(1) Basic configuration of WeChat public account development

(1) Basic configuration of WeChat public account development

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:08:041028browse

As a WeChat developer using code or to implement functions such as event response, the basic configuration of WeChat development is an indispensable link. This article roughly outlines the development configuration process.

1. Log in to the WeChat public platform: Development ---> Basic Configuration

(1) Basic configuration of WeChat public account development

2. There is "Server Configuration" on the basic configuration page, and the default is not In the enabled state, we need to click "Modify Configuration" first to fill in the relevant items

(1) Basic configuration of WeChat public account development

3. Fill in the following project content

(1) Basic configuration of WeChat public account development

  • URL: must start with http://, currently only Supports port 80, the server address must be an accessible and valid address (Note: Using the URL in this article as an example, I once saw a blog post filling in the URL address as http://tx.heivr.com/token, but in personal testing, the actual Unable to respond to events during development, modify the URL to a specific file to succeed );
  • EncodingAESKey can be randomly generated;
  • token: WeChat particularly emphasizes that the filled in URL needs to respond to the token, so in index.php needs to be verified, the code is as follows:

    <span> 1</span> <span>php
    </span><span> 2</span><span>define</span>("TOKEN", "此处填写你设置的token值"<span>);
    </span><span> 3</span><span> 4</span><span>$wechatObj</span> = <span>new</span><span> CallbackAPI;
    </span><span> 5</span><span>$wechatObj</span>-><span>valid();
    </span><span> 6</span><span> 7</span><span>class</span><span> CallbackAPI {
    </span><span> 8</span><span> 9</span><span>/*</span><span>*
    </span><span>10</span><span>     * 签名验证
    </span><span>11</span><span>     * @return [type] [description]
    </span><span>12</span><span>*/</span><span>13</span><span>public</span><span>function</span><span> valid() {
    </span><span>14</span><span>$echoStr</span> = <span>$_GET</span>["echostr"<span>];
    </span><span>15</span><span>$signature</span> = <span>$_GET</span>["signature"<span>];
    </span><span>16</span><span>$timestamp</span> = <span>$_GET</span>["timestamp"<span>];
    </span><span>17</span><span>$nonce</span> = <span>$_GET</span>["nonce"<span>];
    </span><span>18</span><span>$token</span> =<span> TOKEN;
    </span><span>19</span><span>//</span><span>将token、timestamp、nonce按字典序排序</span><span>20</span><span>$tmpArr</span> = <span>array</span>(<span>$token</span>, <span>$timestamp</span>, <span>$nonce</span><span>);
    </span><span>21</span><span>sort</span>(<span>$tmpArr</span><span>);      
    </span><span>22</span><span>$tmpStr</span> = <span>implode</span>(<span>$tmpArr</span><span>);
    </span><span>23</span><span>//</span><span>对tmpStr进行sha1加密</span><span>24</span><span>$tmpStr</span> = <span>sha1</span>(<span>$tmpStr</span><span>);
    </span><span>25</span><span>if</span>(<span>$tmpStr</span> == <span>$signature</span><span>){
    </span><span>26</span><span>header</span>('content-type:text'<span>);
    </span><span>27</span><span>echo</span><span>$echoStr</span><span>;
    </span><span>28</span><span>exit</span><span>;
    </span><span>29</span><span>        }
    </span><span>30</span><span>    }
    </span><span>31</span> }

    Run index.php in the browser. If the program is correct, you can see the returned string, and complete the verification at this time, and fill in the token in the code into the basic configuration In the corresponding position, click Submit. (Note: After submission, a "token verification failed" prompt may appear. If the code and parameters are checked correctly, you need to click a few more times to submit successfully)

4. After the submission is successful, Click the "Enable" button to enter the developer mode. After this mode is enabled, the functions ---> Some functions such as custom menus will not be available. If you want to use it, just click "Disable"

(1) Basic configuration of WeChat public account development

Hereby declare: The relevant articles are all compiled from the information and the problems encountered in the actual development situation after reading the blog posts of great experts. If you can find the original blog, you will definitely sign it. If you cannot find the original blog and quote the content, please contact the original blogger. Haihan

The above introduces (1) the basic configuration of WeChat public account development, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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