search
HomeWeChat AppletWeChat DevelopmentA preliminary study on the development of WeChat development platform

WeChat and the open platform that followed WeChat have become really popular recently. I have always wanted to try out a WeChat platform. I recently had a good idea and wanted to implement it as soon as possible. Fortunately, WeChat does not require any UI or other design, it only needs to show the logic. In fact, if the WeChat public platform is only used as a platform for publishing information, it is "Edit mode "In fact, there is no need to type code. It is just that in the developer mode, developers need to design certain logic and code to achieve specific functions. Next, let’s talk about the start of development:

1. Develop WeChat The public platform must first have server resources. Of course, the editing mode does not count. The so-called editing mode is a public account that simply pushes a message every day. Server resources are available in various clouds and servers. BAE/ is recommended. SAE/Nuts/Alibaba, etc., each has its own advantages, and due to competition, some free resources will be given away, which is enough to practice

##. #a. Apply for a BAE account and create an application. If it is a test, go to the homepage of the WeChat public platform to download the test

PHP code, and just change the TOKEN to your own TOKEN, such as the PHP below. Test code, the logic of the code is very clear, that is, a verification process, and can also define part of the logical operations Upload this file and create version 1 of your own application:

<?php
/**
  * wechat php test
  */

//define your token
define("TOKEN", "weixin");//此时你的微信公众平台的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 data
		if (!empty($postStr)){
                
              	$postObj = simplexml_load_string($postStr, &#39;SimpleXMLElement&#39;, 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;
		}
	}
}

?>

The new version was created successfully. As shown in the figure, the application is created successfully:

A preliminary study on the development of WeChat development platform

2. Enter the developer mode of the WeChat public platform

A preliminary study on the development of WeChat development platform

You need to verify separately to become a developer mode. Please note that the URL in the picture below must be filled in correctly, which is the URL of a platform application you just applied for. Remember to be accurate. URL, otherwise an error "404 NOTFOUND" will be reported

A preliminary study on the development of WeChat development platform

A preliminary study on the development of WeChat development platform##Slide the upper right corner to enable the

button

.

##You can successfully enable the development mode

A preliminary study on the development of WeChat development platformAt this point, you can define various functions and logic in the code to meet your needs and start the magical WeChat public platform. trip.

The above is the detailed content of A preliminary study on the development of WeChat development platform. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software