|
|
@@ -92,7 +92,7 @@ class GTClient
|
|
|
try {
|
|
|
$this->auth();
|
|
|
} catch (Exception $e) {
|
|
|
- echo $e->getMessage();
|
|
|
+ echo $e->getMessage();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -139,6 +139,23 @@ class GTClient
|
|
|
|
|
|
public function auth()
|
|
|
{
|
|
|
+ $ptStyle = Yii::$app->params['ptStyle'];
|
|
|
+ if (is_numeric($ptStyle) == false) {
|
|
|
+ \common\components\util::fail('个推所属平台未明确');
|
|
|
+ }
|
|
|
+ $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => $ptStyle], true);
|
|
|
+ if (empty($open)) {
|
|
|
+ \common\components\util::fail('个推所属平台没有找到');
|
|
|
+ }
|
|
|
+ $expireDate = $open->gtTokenDeadTime ?? '';
|
|
|
+ $current = date("Y-m-d H:i:s");
|
|
|
+ if ($current < $expireDate) {
|
|
|
+ $token = $open->gtToken ?? '';
|
|
|
+ $this->authToken = $token;
|
|
|
+ \common\components\noticeUtil::push("从数据库获取个推token", '15280215347');
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
$auth = new GTAuthRequest();
|
|
|
$auth->setAppkey($this->appkey);
|
|
|
$timeStamp = $this->getMicroTime();
|
|
|
@@ -147,7 +164,18 @@ class GTClient
|
|
|
$auth->setTimestamp($timeStamp);
|
|
|
$rep = $this->userApi()->auth($auth);
|
|
|
if ($rep["code"] == 0) {
|
|
|
- $this->authToken = $rep["data"]["token"];
|
|
|
+ $token = $rep["data"]["token"] ?? '';
|
|
|
+ $expireTime = $rep["data"]["expire_time"] ?? '';
|
|
|
+ $expireTime = bcdiv($expireTime, 1000);
|
|
|
+ $expireTime = bcsub($expireTime, 3600);
|
|
|
+ $expireDate = date("Y-m-d H:i:s", $expireTime);
|
|
|
+ $open->gtToken = $token;
|
|
|
+ $open->gtTokenDeadTime = $expireDate;
|
|
|
+ $open->save();
|
|
|
+
|
|
|
+ \common\components\noticeUtil::push("从接口获取个推token", '15280215347');
|
|
|
+
|
|
|
+ $this->authToken = $token;
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|