[Go] For details about the public development URL and token, urltoken
Many people do not understand what the url and token are in the server configuration of the Developer Center of the public account. I don't understand what the tutorial is. This article details this question.
Step 1: as a developer of a public account, when someone else enters your public account, they will certainly see some webpages or send you some information. You need to automatically reply in real time, so you need a 24-hour server to serve users. The url we want to fill in is the address of the server you provide, provided that you can access and control the address of this server. The token is used for verification.
Step 2: Then you need a server, which can be purchased by yourself or Sina sae or Baidu bae. You can go to the Developer Center to register a developer account.And perform real-name Authentication! (Friends who do not perform real-name authentication cannot succeed)
Step 3: after registration, go to the console to create a new application.
Step 4: after the application is created, go to code management on the left, and prompt us to create a new version. Click "OK" to create a new version. Select the edit code option in the first figure. The second figure is displayed. Double-click index. php to edit the code on this page.
Step 5: copy the following code with punctuation. Change weixin in define ("TOKEN", "weixin") to your own token, for example, zijidetoken. Then click Save in the upper right corner.
<?php/** * wechat php test *///define your tokendefine("TOKEN", "weixin");$wechatObj = new wechatCallbackapiTest();$wechatObj->valid();class wechatCallbackapiTest{public function valid(){ $echoStr = $_GET["echostr"]; //valid signature , option if($this->checkSignature()){ echo $echoStr; exit; } } public function responseMsg(){//get post data, May be due to the different environments$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; //extract post dataif (!empty($postStr)){ $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $textTpl = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content><FuncFlag>0</FuncFlag></xml>"; if(!empty( $keyword )){ $msgType = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr; }else{ echo "Input something..."; } }else { echo ""; exit; } }private function checkSignature(){ $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"];$token = TOKEN;$tmpArr = array($token, $timestamp, $nonce);sort($tmpArr);$tmpStr = implode( $tmpArr );$tmpStr = sha1( $tmpStr );if( $tmpStr == $signature ){return true;}else{return false;}}}?>
Step 6: Click index again in the first figure. PHP file, select access through URL to get the second figure, copy the url in the address bar, this is the URL you need to fill in, the token you need to enter is the token you modified in the previous step.
Step 7: after entering the information, the submission is successful. Now, you can start public development.
Step 8: Conclusion 1. Developers must pass real-name authentication, otherwise they will prompt a failure to verify the token. 2. php knowledge is required for development.
This article is from Baidu. I am just a porter!