/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PublicNumber::find(); $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(['id' => $this->id, 'type' => $this->type, 'create_time' => $this->create_time, 'update_time' => $this->update_time, 'order_id' => $this->order_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'appid', $this->appid])->andFilterWhere(['like', 'appsecret', $this->appsecret])->andFilterWhere(['like', 'encoding_aes_key', $this->encoding_aes_key])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'token', $this->token]); return $dataProvider; }
protected function initWeChat() { //首先获取传过来的unique_id(用于本系统内唯一标识公众号) $unique_id = Yii::$app->request->get('unique_id'); if (empty($unique_id)) { Error::output(Error::ERR_FIFA); } //根据传过来unique_id定位是哪个公众号 $publicNumber = PublicNumber::find()->where(['unique_id' => $unique_id])->asArray()->one(); if (empty($publicNumber)) { Error::output(Error::ERR_FIFA); } //获取到该公众号appid以及appsecret以及token来实例化$wechat $this->wechat = Yii::createObject(['class' => 'weixin\\components\\WeChat', 'options' => ['token' => $publicNumber['token'], 'appid' => $publicNumber['appid'], 'appsecret' => $publicNumber['appsecret'], 'encodingaeskey' => $publicNumber['encoding_aes_key']]]); }
private function getPublicNumber($pid) { //如果开启了缓存,先从缓存取 $publicNumber = []; if (Yii::$app->params['enable_cache']) { $publicNumber = Yii::$app->cache->get('public_number_' . $pid); } if (empty($publicNumber)) { $publicNumber = PublicNumber::find()->where(['id' => $pid])->asArray()->one(); if (empty($publicNumber)) { return []; } //之后缓存起来(过期时间为一天) Yii::$app->cache->set('public_number_' . $pid, json_encode($publicNumber), 3600 * 24); } else { $publicNumber = json_decode($publicNumber, 1); } return $publicNumber; }
protected function findModel($id) { if (($model = PublicNumber::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('yii', 'Page not found.')); } }