Just contact to do a form submission function, the requirement is that only in the database exists in the mobile phone number to see the form. The following through this article to share the use of the YII2 framework to achieve the public number of the form submission function, interested friends to see it together
Just contact, to do a form submit function on the phone.
Demand has these:
The form can only be seen on a mobile phone number that exists in the database.
Forms can be submitted repeatedly.
The first time you enter a form requires validation
Share out the page, others need to verify after entering.
Because the OpenID of each cell phone in the same public number is unique. So when the phone view this form page, the OpenID is stored in the database, so that the next submission can be verified.
Here's my Code. The YII2 framework is used.
Controller
Get the callback function Public function Actioncallback ($code, $state) {$model = new tp_tstz_proposal (); $model 1= new Tp_tstz_staff (); Open Platform website application AppID and secret key secret $appid = "; $secret = "; $curl = new Curl\curl (); Get 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) {//share, re-certify return $this->render (' Lo Gin '); Error in requesting authorization, print error code//echo Json_encode ($wxresult); Exit } $openid = $wxresult->openid; $result = $model 1::find ()->where ([' OpenID ' = $openid])->one (); If the OpenID exists, go to the form if (count ($result) >0) {$key = 123456; return $this->render (' View ', [' model ' = ' $model, ' key ' = ' $key]); }else{return $this->render (' tel ', [' model ' = + $model 1, ' 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 path returned is the path into the controller.
On the form page, I first made a simple certification
if (!isset ($key)) { header (' Location:http://jifen.wendu.cn/ts/web/index.php?r=say/login ');}
Judging whether it is from the shared page, if it is from the shared page to be re-verified to determine whether the database has the phone's OpenID. There is no verification of the mobile phone number.
That's probably it, my first simple public number project.
Summarize