Files
opencode b7613ba082 部署仓库初始化:epay 部署配置、补丁与插件
- docker-compose.prod.yml:挂载 epay-ui.css/js/head.php 补丁到 staging(镜像升级不丢)
- docker/nginx.conf:补丁静态资源 no-cache,改版立即生效
- patches/:
  - test.php 修复 paytype JSON 对象导致测试支付页空白
  - epay-ui.css 后台全屏/侧栏加宽/导航两列布局覆盖
  - epay-ui.js 去除页面容器宽度限制 + 侧栏当前菜单自动滚动
  - head.php 资源 ?v= 版本号强制回源
  - functions.php is_public_url 白名单等既有补丁
- plugins/ 支付插件源码
- .gitignore 排除 .env 等敏感与临时文件
2026-10-21 13:05:20 +08:00

61 lines
1.9 KiB
PHP

<?php
namespace DouYinPay;
use Exception;
class DouyinOauth
{
private $client_key;
private $client_secret;
public function __construct($client_key, $client_secret)
{
$this->client_key = $client_key;
$this->client_secret = $client_secret;
}
public function get_openid($redirect_uri, $state = null)
{
if (isset($_GET['code'])) {
$code = $_GET['code'];
$data = $this->callback($code);
return $data['open_id'];
}else{
$this->login($redirect_uri, $state);
}
}
public function login($redirect_uri, $state = null)
{
$param = [
"client_key" => $this->client_key,
"scope" => "login_id",
"response_type" => "code",
"redirect_uri" => $redirect_uri,
];
if($state) $param['state'] = $state;
$url = 'https://aweme.snssdk.com/passport/open/silent_auth/?' . http_build_query($param);
Header("Location: $url");
exit;
}
public function callback(string $code): array
{
$param = [
"client_key" => $this->client_key,
"client_secret" => $this->client_secret,
"code" => $code,
"grant_type" => "authorization_code"
];
$url = 'https://open.douyin.com/oauth/access_token/';
$res = get_curl($url, http_build_query($param));
$data = json_decode($res, true);
if (isset($data['data']['error_code']) && $data['data']['error_code'] == 0) {
return $data['data'];
} elseif (isset($data['data']['error_code'])) {
throw new Exception('Openid获取失败 [' . $data['data']['error_code'] . ']' . $data['data']['description']);
} else {
throw new Exception('Openid获取失败,原因未知');
}
}
}