WeChat authorized login and storage of user information (fastadmin development project)

Recently I made a WeChat voting system. This is the first time that a WeChat project has been developed, so I hereby record the
WeChat voting system. The highest priority is to authorize login and obtain user information
. 1. First, you need to apply for a WeChat official account (the one used this time It is the service number)
2. In the basic configuration of the WeChat public platform, get the appid and secret key, and fill in the whitelist, and fill in as you want
. 3. This time I use the authorized login plug-in developed by myself, and directly unzip the plug-in to addons In the directory, then find the application/extra/addons.php file, and add the code in the array

'get_weixin_auth' => 
    array (
      0 => 'weixin',
    ),
    'get_weixin_config' => 
    array (
      0 => 'weixin',
    ),
    'wx_login' => 
    array (
      0 => 'weixin',
    ),
    'get_weixin_upload_single' => 
    array (
      0 => 'weixin',
    ),
    'get_weixin_upload_multiple' => 
    array (
      0 => 'weixin',
    ),
    'get_weixin_location' => 
    array (
      0 => 'weixin',
    ),
    'get_weixin_share' => 
    array (
      0 => 'weixin',
    ),

3. The foreground call method is

public function wxlogin(){
        hook('get_weixin_auth',['backUrl'=>'此处填写回调地址']);
    }

4. The operation of storing user information should be performed before jumping to the project homepage

public function saveinfo(){
        $data=input('');
        $res=db('voter')->where('openid',$data['openid'])->find();
        if($res){
            session('user',$res);
            $this->user=$res;
            $this->uid=$res['id'];
            $this->redirect(url("index/index"));
        }
        else{
            $udata['nickname']=$data['nickname'];
            $udata['openid']=$data['openid'];
            $udata['headimage']=$data['headimgurl'];
            $out=db('voter')->insert($udata);
            if($out){
                $res=db('voter')->where('openid',$data['openid'])->find();
                session('user',$res);
                $this->user=$res;
                $this->uid=$res['id'];
                $this->redirect(url("index/index"));
            }
            else{
                $this->error('保存信息出错');
            }
        }
    }

5. After the configuration is complete, find the inserted plug-in (WeChat development) in the fastadmin background, and then configure the appid and appsecret
6. The interface permissions on the WeChat public platform-"Web Service- "Web Authorization-"Web Authorization to obtain basic user information, Click Modify, fill in the domain names as required, and fill in each one.
I encountered a problem at this step, and it has not been resolved so far. . . This project was originally written on the virtual host of Western Digital, but after this step, it was still unsuccessful. It showed that the directory of the web server (or virtual host) pointed to by xxx could not be accessed. Please check the network settings. The domain name is a registered domain name, and the file specified by him is downloaded and placed in the directory. The file can be accessed successfully through direct access, but this error is still displayed. Finally, after various attempts have been tried, it still fails, so I have to contact Western Digital Technology, they asked me to contact WeChat customer service to solve it. Obviously, I can directly access the files specified by others. It is definitely not a problem on WeChat. Faced with this kind of dumping behavior, I can only put the project on another server. The development was done in minutes, and there was no such problem at all. . Although the project has been solved, there is still such a problem that cannot be solved.
7. This project also made a mistake, because the data set is the front desk, I provide an interface, however, did not inherit this base class interface unauthorized access, directory structure a bit messy, so the resulting modified bug back when very angry
if Which great god can solve the problem in the article, I hope the great god can give some pointers, I am grateful

Guess you like

Origin blog.csdn.net/qq_36129701/article/details/82842224