|
@@ -14,10 +14,19 @@ class Util
|
|
return $this->createNumber($prefix, $table, $where, $key);
|
|
return $this->createNumber($prefix, $table, $where, $key);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ # 获取某个setting值
|
|
|
|
+ public function setting($key, $account, $project = 'api')
|
|
|
|
+ {
|
|
|
|
+ $setting = Dever::db('platform_setting', 'api')->find(['key' => $key]);
|
|
|
|
+ $setting = Dever::db('account_setting', $project)->find(['account_id' => $account, 'platform_setting_id' => $setting['id']]);
|
|
|
|
+ $value = $setting['value'] ?? 0;
|
|
|
|
+ return $value;
|
|
|
|
+ }
|
|
|
|
+
|
|
# 获取openid 仅jspai和小程序需要openid
|
|
# 获取openid 仅jspai和小程序需要openid
|
|
- public function openid($account, $env, $uid, $result = [])
|
|
|
|
|
|
+ public function openid($account, $env, $uid, $result = [], $project = 'api')
|
|
{
|
|
{
|
|
- $account = Dever::db('account', 'api')->find(['key' => $account]);
|
|
|
|
|
|
+ $account = Dever::load('account', 'api')->get($account, $project);
|
|
if ($account) {
|
|
if ($account) {
|
|
$info = Dever::db('openid', 'api')->find(['account_id' => $account['id'], 'uid' => $uid, 'env' => $env]);
|
|
$info = Dever::db('openid', 'api')->find(['account_id' => $account['id'], 'uid' => $uid, 'env' => $env]);
|
|
if ($info) {
|
|
if ($info) {
|
|
@@ -33,7 +42,7 @@ class Util
|
|
} elseif ($env == 5) {
|
|
} elseif ($env == 5) {
|
|
# 小程序
|
|
# 小程序
|
|
$param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
|
|
$param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
|
|
- $data = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env);
|
|
|
|
|
|
+ $data = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env, 'run', $project);
|
|
if (isset($data['openid'])) {
|
|
if (isset($data['openid'])) {
|
|
$result['openid'] = $data['openid'];
|
|
$result['openid'] = $data['openid'];
|
|
$update['uid'] = $uid;
|
|
$update['uid'] = $uid;
|
|
@@ -48,6 +57,39 @@ class Util
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ # 获取token
|
|
|
|
+ public function token($account, $env, $project = 'api')
|
|
|
|
+ {
|
|
|
|
+ $account = Dever::load('account', 'api')->get($account, $project);
|
|
|
|
+ $result = '';
|
|
|
|
+ if ($env == 5) {
|
|
|
|
+ $appid = 'applet_appid';
|
|
|
|
+ $secret = 'applet_secret';
|
|
|
|
+ }
|
|
|
|
+ $appid = $this->setting($appid, $account['id'], $project);
|
|
|
|
+ $secret = $this->setting($secret, $account['id'], $project);
|
|
|
|
+ if ($account && $appid && $secret) {
|
|
|
|
+ $param = ['appid' => $appid, 'appsecret' => $secret];
|
|
|
|
+ $info = Dever::db('token', 'api')->find($param);
|
|
|
|
+ if ($info && time() <= $info['edate']) {
|
|
|
|
+ $result = $info['token'];
|
|
|
|
+ } else {
|
|
|
|
+ $data = Dever::load('account', 'api')->run($account, 'access_token', $param, 1, 'run', $project);
|
|
|
|
+ if (isset($data['access_token'])) {
|
|
|
|
+ $result = $data['access_token'];
|
|
|
|
+ $param['token'] = $result;
|
|
|
|
+ $param['edate'] = time() + $data['expires_in'];
|
|
|
|
+ if ($info) {
|
|
|
|
+ Dever::db('token', 'api')->update($info['id'], $param);
|
|
|
|
+ } else {
|
|
|
|
+ Dever::db('token', 'api')->insert($param);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
# 获取参数类型
|
|
# 获取参数类型
|
|
public function fieldType($platform_id)
|
|
public function fieldType($platform_id)
|
|
{
|
|
{
|
|
@@ -88,7 +130,7 @@ class Util
|
|
{
|
|
{
|
|
$info = Dever::db('format', 'api')->find($id);
|
|
$info = Dever::db('format', 'api')->find($id);
|
|
if ($info) {
|
|
if ($info) {
|
|
- $info['method'] = str_replace('{value}', "'{value}'", $info['method']);
|
|
|
|
|
|
+ //$info['method'] = str_replace('{value}', "'{value}'", $info['method']);
|
|
$value = \Dever\Helper\Str::val($info['method'], ['value' => $value]);
|
|
$value = \Dever\Helper\Str::val($info['method'], ['value' => $value]);
|
|
}
|
|
}
|
|
return $value;
|
|
return $value;
|