<commit_before><?php

namespace frontend\controllers;

use Yii;
use frontend\models\Project;
use frontend\models\RelUserProject;
use frontend\models\User;
use yii\web\Session;

class JoinController extends \yii\web\Controller
{
    public $userinfo;

    public $projinfo;

    public function actionIndex()
    {
        $session = Yii::$app->session;
//        echo urlencode('http://m.lifeqx.com/join?uid=1');
//        return;
//        echo '<br>';
//        echo urlencode('http://m.example.com/join');
        //return $this->render('index');


        //检查参数
        if(!isset($_GET['state'],$_GET['uid'])){
            return $this->redirect("/join/error?code=20000");
        }

        $project_id = $_GET['state'];
        $owner_id   = $_GET['uid'];

        $rel = RelUserProject::findOne(['user_id'=>$owner_id,'project_id'=>$project_id,'is_manager'=>1]);

        if(empty($rel)){
            return $this->redirect("/join/error?code=50001");
        }


        //微信AppID和秘钥
        $appid  = Yii::$app->params['wx_appid'];
        $secret = Yii::$app->params['wx_appsecret'];

        //获取access_token和openid
        $url    = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$_GET['code']."&grant_type=authorization_code";
        $token_json = file($url);
        $token = json_decode($token_json[0]);

        //获取用户数据
        if(isset($token) && !empty($token->access_token)){
            $access_token   = $token->access_token;
            $openid         = $token->openid;
            $url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
            $member_json = file($url);
            $member = json_decode($userinfo_json[0]);
            //print_r($userinfo);
        }

//        $userinfo['openid']   = 'odTkbwhEqPaDQweliB9avKJTyIWA';
//        $userinfo['nickname'] = 'Sam';
//        $userinfo['sex']      = 1;
//        $userinfo['language'] = 'zh_CN';
//        $userinfo['city']     = '长宁';
//        $userinfo['province'] = '上海';
//        $userinfo['country']  = '中国';
//        $userinfo['headimgurl'] = 'http://wx.qlogo.cn/mmopen/a0ObXfhfLicMzxGGyTdrYUjZ7qWp7ZlOMju5z2ibGVd2pBcicpNacYg3SqJKVu1jgMCc6PPKniaQOoYy2b324cyf9A/0';


        //项目
        $proj  = Project::findOne($project_id);
        //$proj  = $proj->toArray();

        //邀请人
        $owner = User::findOne($owner_id);
        //$owner = $owner->toArray();

        //$_SESSION['userinfo'] = $userinfo;
        //$_SESSION['projinfo'] = $proj;
        $session->set('member', $member);
        $session->set('proj', $proj);
<commit_msg>frontend join<commit_after><?php

namespace frontend\controllers;

use Yii;
use frontend\models\Project;
use frontend\models\RelUserProject;
use frontend\models\User;
use yii\web\Session;

class JoinController extends \yii\web\Controller
{
    public $userinfo;

    public $projinfo;

    public function actionIndex()
    {
        $session = Yii::$app->session;
//        echo urlencode('http://m.lifeqx.com/join?uid=1');
//        return;
//        echo '<br>';
//        echo urlencode('http://m.example.com/join');
        //return $this->render('index');


        //检查参数
        if(!isset($_GET['state'],$_GET['uid'])){
            return $this->redirect("/join/error?code=20000");
        }

        $project_id = $_GET['state'];
        $owner_id   = $_GET['uid'];

        $rel = RelUserProject::findOne(['user_id'=>$owner_id,'project_id'=>$project_id,'is_manager'=>1]);

        if(empty($rel)){
            return $this->redirect("/join/error?code=50001");
        }


        //微信AppID和秘钥
        $appid  = Yii::$app->params['wx_appid'];
        $secret = Yii::$app->params['wx_appsecret'];

        //获取access_token和openid
        $url    = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$_GET['code']."&grant_type=authorization_code";
        $token_json = file($url);
        $token = json_decode($token_json[0]);

        //获取用户数据
        if(isset($token) && !empty($token->access_token)){
            $access_token   = $token->access_token;
            $openid         = $token->openid;
            $url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
            $member_json = file($url);
            $member = json_decode($member_json[0]);
            //print_r($userinfo);
        }

//        $userinfo['openid']   = 'odTkbwhEqPaDQweliB9avKJTyIWA';
//        $userinfo['nickname'] = 'Sam';
//        $userinfo['sex']      = 1;
//        $userinfo['language'] = 'zh_CN';
//        $userinfo['city']     = '长宁';
//        $userinfo['province'] = '上海';
//        $userinfo['country']  = '中国';
//        $userinfo['headimgurl'] = 'http://wx.qlogo.cn/mmopen/a0ObXfhfLicMzxGGyTdrYUjZ7qWp7ZlOMju5z2ibGVd2pBcicpNacYg3SqJKVu1jgMCc6PPKniaQOoYy2b324cyf9A/0';


        //项目
        $proj  = Project::findOne($project_id);
        //$proj  = $proj->toArray();

        //邀请人
        $owner = User::findOne($owner_id);
        //$owner = $owner->toArray();

        //$_SESSION['userinfo'] = $userinfo;
        //$_SESSION['projinfo'] = $proj;
        $session->set('member', $member);
        $session->set('proj', $proj);

{'fraction_non_alphanumeric': 0.1946969696969697, 'fraction_numerical': 0.012121212121212121, 'mean_word_length': 2.478919631093544, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '117003', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1891, 'n_words': 217}