common/models/ApiUser.php
/**
    * Refresh Token if token expired 
    * @param  random $post_token string, random $refresh_token string
    */
Refresh Token if token expired
@param  random $post_token string, random $refresh_token string
Refresh Token if token expired @param random $post_token string random $refresh_token string
public function RefreshToken($post_token,$refresh_token){
        $token_field = static::find()->where(['token'=>$post_token])->where(['refresh_token'=>$refresh_token])->one();
        if(null!=$token_field){
            $token_field->expire = "no_expired";
            $token_field->token = Yii::$app->security->generateRandomString() . '_' . time();
            $token_field->refresh_token = Yii::$app->security->generateRandomString() . '_' . time();
            $date = Carbon::now()->addHours(8);
            $token_field->expiration_date = $date;
            if($token_field->save()){
                return $token_field; 
            }else{
                return 'error occured';
            }
        }else{
            return null;
        }
    }
public function RefreshToken ( $ post_token , $ refresh_token ) { $ token_field = static :: find ( ) -> where ( [ 'token' => $ post_token ] ) -> where ( [ 'refresh_token' => $ refresh_token ] ) -> one ( ) ; if ( null != $ token_field ) { $ token_field -> expire = " no_expired " ; $ token_field -> token = Yii :: $ app -> security -> generateRandomString ( ) . '_' . time ( ) ; $ token_field -> refresh_token = Yii :: $ app -> security -> generateRandomString ( ) . '_' . time ( ) ; $ date = Carbon :: now ( ) -> addHours ( 8 ) ; $ token_field -> expiration_date = $ date ; if ( $ token_field -> save ( ) ) { return $ token_field ; } else { return 'error occured' ; } } else { return null ; } }
Refresh Token if token expired
 @param  random $post_token string, random $refresh_token string
Refresh Token if token expired @param random $post_token string random $refresh_token string