


Detailed tutorial on using the YII2 framework to develop and implement the form submission function in WeChat public accounts
When I first came into contact with WeChat, I had to create a form submission function. The requirement was that the form could only be seen by the mobile phone number that exists in the database. Through this article, I will share with you how to use the YII2 framework to implement the form submission function in WeChat public accounts. Friends who are interested should take a look.
I am new to WeChat and want to create a form submission function on a mobile phone.
The requirements are as follows:
The form can only be seen on mobile phone numbers that exist in the database.
The form can be submitted repeatedly.
You need to verify when entering the form for the first time
For shared pages, other people also need to verify after entering.
Because the openid of each mobile phone in the same official account is unique. Therefore, when viewing this form page on a mobile phone, the openid is saved in the database so that it can be verified next time it is submitted.
Below is my code. The YII2 framework is used.
Controller
//获得回调函数 public function actionCallback($code,$state){ $model = new tp_tstz_proposal(); $model1= new tp_tstz_staff(); // 微信开放平台网站应用的appid和秘钥secret $appid = ''; $secret = ''; $curl = new curl\Curl(); //获取access_token $wxresponse = $curl->get('https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code'); $wxresult = json_decode($wxresponse); if(isset($wxresult->errcode) && $wxresult->errcode > 0){ //分享出去,重新认证 return $this->render('login'); // 向微信请求授权时出错,打印错误码 // echo json_encode($wxresult); // exit; } $openid=$wxresult->openid; $result=$model1::find()->where(['openid'=>$openid])->one(); //如果OPENID存在就去表单 if(count($result)>0){ $key=123456; return $this->render('view',['model'=>$model,'key'=>$key]); }else{ return $this->render('tel',['model'=>$model1,'openid'=> $openid]); } }`
view layer
Very simple redirect page
header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8ba95fc51672e844&redirect_uri=http%3a%2f%2fjifen.wendu.cn%2fts%2fweb%2findex.php%3fr%3dproposal%2fcallback&response_type=code&scope=snsapi_base&state=123asd#wechat_redirect');
The returned path is the path to the controller.
On the form page, I first did a simple authentication
if(!isset($key)){ header('Location:http://jifen.wendu.cn/ts/web/index.php?r=say/login'); }
To determine whether it comes from the shared page, if it comes from the shared page It is necessary to re-verify to determine whether the openid of this mobile phone is in the database. If not, verify the mobile number.
That’s it, my first simple WeChat public account project.
The above is the detailed content of Detailed tutorial on using the YII2 framework to develop and implement the form submission function in WeChat public accounts. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these
