$this->app_id, 'app_secret' => $this->app_secret, ]; return $this->https_post($api_url, $params); // $result = [ // 'data' => [ // "access_token" => "clt.4874669616136b06ab3d8ca4550adf07OGg6sVIrOKjp2p3w7fJYLQhcC6Z8_hl", // "description" => "", // "error_code" => 0, // "expires_in" => 7200, // "log_id" => "20250522152945A1F02B01A0C1DC0F8CE2", // ], // "message" => "success", // ]; } /** * 2.2 获取access_token * - access_token 有效期仅有 15 天 * * @param $code * * @return mixed */ public function access_token($code) { $api_url = self::Douyin_Url . '/webcast/game/oauth/access_token/'; $params = [ 'app_id' => $this->app_id, 'app_secret' => $this->app_secret, 'code' => $code, ]; return $this->https_post($api_url, $params); // $result = [ // 'data' => [ // "access_token" => "act.3.Db88ppxc_2nckhTcjbE9Z2-lZ9PMcp4CrzRQckv7rrzaPOT8a7TkU4Ls9W9dCCmOok13FWfiE1hySTT0PtyxnxaG4Fs_wIbTPaQa729YfZ54kZRow5Ic2W8gZtpL7n-E1ArbGPp-bG0lUZ5AfX_Cf01NVwSfqBVv3eezpQ==_lf", // "description" => "", // "error_code" => "0", // "expires_in" => "1296000", // "log_id" => "20250521100953C76761CDD18B97348C5A", // "open_id" => "_0003YHzVQz7jHbDlXzei6geJ0FR3hhRoVbQ", // "refresh_expires_in" => "2592000", // "refresh_token" => "rft.62a7620229764c902b1c0f7da87c5815HEPO6yeLoPKtFxwdA0BvxOp1In5F_lf", // "scope" => "user_info", // ], // "message" => "success", // ]; } /** * 2.3 刷新access_token * - 刷新 access_token,有效期为 30 天。 * - 最多能再获取 5 次新的 refresh_token,最长续期为 15 + 30 + 30 * 5 = 195 天。 * * @param $refresh_token * * @return mixed */ public function refresh_token($refresh_token) { $api_url = self::Douyin_Url . '/webcast/game/oauth/refresh_token/'; $params = [ 'app_id' => $this->app_id, 'refresh_token' => $refresh_token, ]; return $this->https_post($api_url, $params); } /** * 2.4 刷新refresh_token * - 通过旧的 refresh_token 获取新的 refresh_token,调用后旧 refresh_token 会失效,新 refresh_token 有 30 天有效期。最多只能获取 5 次新的 refresh_token,5 次过后需要用户重新授权。 * * @param $refresh_token * * @return mixed */ public function renew_refresh_token($refresh_token) { $api_url = self::Douyin_Url . '/webcast/game/oauth/renew_refresh_token/'; $params = [ 'app_id' => $this->app_id, 'refresh_token' => $refresh_token, ]; return $this->https_post($api_url, $params); } /** * 3.4.7 游戏内授权后回调抖音游戏 * * @param $client_token * @param $is_agree 是否同意授权: 0=拒绝,1=同意 * @param $uid 游戏账号ID * @param $scheme 抖音跳转游戏scheme的参数,回调时需要透传带上 * * @return mixed */ public function jump_game_auth_callback($client_token, $is_agree, $uid, $scheme){ $api_url = self::Douyin_Url . '/api/webcast/v1/game/doulink/jump_game_auth_callback/'; $headers = [ 'access-token' => $client_token, ]; $params = [ 'is_agree' => $is_agree, 'game_user_id' => $uid, 'extra_json' => $scheme, ]; return $this->https_post($api_url, $params, $headers); } }