Example #1
0
 public static function refreshAccessToken()
 {
     $tableName = MGh::tableName();
     $gh_ids = Yii::$app->db->createCommand("SELECT gh_id FROM {$tableName}")->queryColumn();
     foreach ($gh_ids as $gh_id) {
         Yii::$app->wx->clearGh();
         Yii::$app->wx->setGhId($gh_id);
         //U::W(['old', $gh_id, Yii::$app->wx->getAccessToken()]);
         Yii::$app->wx->getAccessToken(true);
         //U::W(['new', $gh_id, Yii::$app->wx->getAccessToken()]);
     }
 }
Example #2
0
 public function getGh()
 {
     if ($this->_gh !== null) {
         return $this->_gh;
     }
     if (empty($this->_gh_id) && empty($this->_appid)) {
         U::W(debug_backtrace());
         U::D("gh_id and appid can can not be empty at the same time!");
     }
     $db = \Yii::$app->db;
     $tableName = \app\models\MGh::tableName();
     if (!empty($this->_gh_id)) {
         $command = $db->createCommand("SELECT * FROM {$tableName} WHERE gh_id=:gh_id", [':gh_id' => $this->_gh_id]);
     } else {
         $command = $db->createCommand("SELECT * FROM {$tableName} WHERE appid=:appid", [':appid' => $this->_appid]);
     }
     //$db->beginCache(YII_DEBUG ? 10 : 3600);
     $row = $command->queryOne();
     //$db->endCache();
     if ($row === false) {
         U::D("no exists in db!, gh_id={$this->_gh_id}, appid={$this->_appid}");
     }
     $this->_gh = $row;
     return $row;
 }