Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = App::find()->where(['app_active' => 0]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['app_id' => $this->app_id, 'service_id' => $this->service_id, 'app_active' => $this->app_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'authorizer_appid', $this->authorizer_appid])->andFilterWhere(['like', 'app_type', $this->app_type])->andFilterWhere(['like', 'app_name', $this->app_name])->andFilterWhere(['like', 'app_origin_id', $this->app_origin_id])->andFilterWhere(['like', 'app_alias', $this->app_alias])->andFilterWhere(['like', 'app_logo', $this->app_logo])->andFilterWhere(['like', 'app_des', $this->app_des])->andFilterWhere(['like', 'app_qrlogo', $this->app_qrlogo])->andFilterWhere(['like', 'authorizer_access_token', $this->authorizer_access_token])->andFilterWhere(['like', 'authorizer_info', $this->authorizer_info])->orderBy(['created_at' => SORT_DESC]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * undocumented function
  *
  * @return void
  * @author
  **/
 public function actionCreateWechat()
 {
     if (Yii::$app->request->get('auth_code', false)) {
         // 获取Token信息
         $token = Token::getInstance();
         $auth_code = Yii::$app->request->get('auth_code', false);
         $authorizer_access_token = $token->getAuthorizerAccessToken($auth_code, false);
         $authorizer_info = $token->getAuthorizerInfo();
         $authorizer_all = $token->getAuthorizerInfo(false);
         if ($authorizer_info) {
             $mApp = new App();
             // 判断账号是否已经被授权
             $app_id = $authorizer_access_token->authorizer_appid;
             if (!$mApp->find()->where(['authorizer_appid' => $app_id, 'app_active' => 0])->one()) {
                 // 保存二维码
                 $qrlog_name = md5($app_id) . ".jpg";
                 if (!file_exists(Yii::getAlias('@service/web/uploads/weixin'))) {
                     mkdir(Yii::getAlias('@service/web/uploads/weixin'));
                 }
                 file_put_contents(Yii::getAlias('@service/web/uploads/weixin/') . $qrlog_name, file_get_contents($authorizer_info->qrcode_url));
                 // 存入数据
                 $data['App'] = ['service_id' => $this->user->id, 'authorizer_appid' => $app_id, 'authorizer_access_token' => json_encode($authorizer_access_token->authorizer_all), 'app_service_type' => $authorizer_info->service_type_info->id, 'app_name' => $authorizer_info->nick_name, 'app_origin_id' => $authorizer_info->user_name, 'app_logo' => $authorizer_info->head_img, 'app_qrlogo' => $qrlog_name, 'app_alias' => $authorizer_info->alias, 'authorizer_info' => json_encode($authorizer_all)];
                 if ($mApp->load($data) && $mApp->save(false)) {
                     Yii::$app->session->setFlash('success', '授权成功:' . $authorizer_info->nick_name);
                     return $this->redirect('wechat');
                 }
             } else {
                 Yii::$app->session->setFlash('error', '授权异常:此公众号已被授权到另一个账号了');
                 return $this->redirect('wechat');
             }
         }
     }
     $base_url = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s";
     $data['rd_url'] = sprintf($base_url, $this->config->platform_info->appId, $this->token->getPreAuthCode(), urlencode(Url::current([], true)));
     return $this->render('create-wechat', ['data' => $data]);
 }