提交 533a60fa 编写于 作者: 李光春's avatar 李光春

- 优化接口

上级 25b5d7e4
## v6.0.112 / 2020-09-08
- 优化接口
## v6.0.111 / 2020-09-08
- 更新微信公众平台的分享接口
......
......@@ -53,8 +53,7 @@ class ApiController extends stdClass
* 加密相关的东西
* @var string
*/
private $aes_md5 = '';
private $aes_md5_iv = '';
private $aes_md5, $aes_md5_iv = '';
/**
* ApiController constructor.
......@@ -84,7 +83,7 @@ class ApiController extends stdClass
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function error($msg = 'error', $code = 1, $data = [])
public function error($msg = 'error', $code = 1, $data = []): void
{
throw new HttpResponseException(json([
'code' => $code,
......@@ -100,7 +99,7 @@ class ApiController extends stdClass
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function success($data = [], $msg = 'success', $code = 0)
public function success($data = [], $msg = 'success', $code = 0): void
{
throw new HttpResponseException(json([
'code' => $code,
......@@ -157,7 +156,7 @@ class ApiController extends stdClass
* @param string $url 跳转链接
* @param integer $code 跳转代码
*/
public function redirect($url, $code = 301)
public function redirect($url, $code = 301): void
{
throw new HttpResponseException(redirect($url, $code));
}
......@@ -172,7 +171,7 @@ class ApiController extends stdClass
public function callback($name, &$one = [], &$two = []): bool
{
if (is_callable($name)) {
return call_user_func($name, $this, $one, $two);
return $name($this, $one, $two);
}
foreach ([$name, "_{$this->app->request->action()}{$name}"] as $method) {
if (method_exists($this, $method) && false === $this->$method($one, $two)) {
......
......@@ -71,7 +71,7 @@ class Controller extends stdClass
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function error($info, $data = '{-null-}', $code = 0)
public function error($info, $data = '{-null-}', $code = 0): void
{
if ($data === '{-null-}') {
$data = new stdClass();
......@@ -87,7 +87,7 @@ class Controller extends stdClass
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function success($info, $data = '{-null-}', $code = 1)
public function success($info, $data = '{-null-}', $code = 1): void
{
if ($data === '{-null-}') {
$data = new stdClass();
......@@ -102,7 +102,7 @@ class Controller extends stdClass
* @param string $url 跳转链接
* @param integer $code 跳转代码
*/
public function redirect($url, $code = 301)
public function redirect($url, $code = 301): void
{
throw new HttpResponseException(redirect($url, $code));
}
......@@ -112,7 +112,7 @@ class Controller extends stdClass
* @param string $tpl 模板名称
* @param array $vars 模板变量
*/
public function fetch($tpl = '', $vars = [])
public function fetch($tpl = '', $vars = []): void
{
foreach ($this as $name => $value) {
$vars[$name] = $value;
......@@ -126,7 +126,7 @@ class Controller extends stdClass
* @param mixed $value 变量的值
* @return $this
*/
public function assign($name, $value = '')
public function assign($name, $value = ''): self
{
if (is_string($name)) {
$this->$name = $value;
......@@ -147,10 +147,10 @@ class Controller extends stdClass
* @param mixed $two 回调引用参数2
* @return boolean
*/
public function callback($name, &$one = [], &$two = [])
public function callback($name, &$one = [], &$two = []): bool
{
if (is_callable($name)) {
return call_user_func($name, $this, $one, $two);
return $name($this, $one, $two);
}
foreach ([$name, "_{$this->app->request->action()}{$name}"] as $method) {
if (method_exists($this, $method) && false === $this->$method($one, $two)) {
......
......@@ -38,7 +38,7 @@ class Mysql
* @param string $cache_name
* @return $this
*/
public function name(string $cache_name)
public function name(string $cache_name): self
{
$this->cache_name = $cache_name;
return $this;
......@@ -49,7 +49,7 @@ class Mysql
* @param int $cache_expire
* @return $this
*/
public function expire(int $cache_expire)
public function expire(int $cache_expire): self
{
$this->cache_expire = $cache_expire;
return $this;
......@@ -61,7 +61,7 @@ class Mysql
* @return bool
* @throws DtaException
*/
public function set($cache_value)
public function set($cache_value): bool
{
$this->judge();
$result = Db::table($this->table)
......@@ -94,7 +94,7 @@ class Mysql
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function delete()
public function delete(): bool
{
$this->judge();
$result = Db::table($this->table)
......@@ -110,7 +110,7 @@ class Mysql
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function update($cache_value)
public function update($cache_value): bool
{
$this->judge();
$result = Db::table($this->table)
......@@ -129,7 +129,7 @@ class Mysql
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function inc(int $int = 1)
public function inc(int $int = 1): bool
{
$cache_value = (int)$this->get();
$result = Db::table($this->table)
......@@ -147,7 +147,7 @@ class Mysql
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function dec(int $int = 1)
public function dec(int $int = 1): bool
{
$cache_value = (int)$this->get();
$result = Db::table($this->table)
......@@ -161,7 +161,7 @@ class Mysql
/**
* @throws DtaException
*/
private function judge()
private function judge(): void
{
if (empty($this->cache_name)) {
throw new DtaException("名称未配置");
......
......@@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService;
/**
* 定义当前版本
*/
const VERSION = '6.0.111';
const VERSION = '6.0.112';
if (!function_exists('get_ip_info')) {
/**
......
......@@ -28,6 +28,9 @@ use Exception;
*/
class DtaException extends Exception
{
/**
* @return string
*/
public function errorMessage()
{
return $this->getMessage();
......
......@@ -67,13 +67,13 @@ class ThinkException extends Handle
* @return bool
* @throws DtaException
*/
private function show($msg)
private function show($msg): bool
{
if (empty($msg)) {
return true;
}
$nt = config('dtapp.exception.type', '');
if (!empty($nt) && $nt == 'dingtalk') {
if (!empty($nt) && $nt === 'dingtalk') {
$access_token = config('dtapp.exception.dingtalk.access_token', '');
if (!empty($access_token)) {
return DingTalkService::instance()
......@@ -81,7 +81,7 @@ class ThinkException extends Handle
->text($msg);
}
}
if (!empty($nt) && $nt == 'qyweixin') {
if (!empty($nt) && $nt === 'qyweixin') {
$key = config('dtapp.exception.qyweixin.key', '');
if (!empty($key)) {
return QyService::instance()
......
......@@ -82,7 +82,7 @@ class Arrays
* @param array $array
* @return array
*/
public function unique(array $array)
public function unique(array $array): array
{
$out = array();
foreach ($array as $key => $value) {
......@@ -102,7 +102,7 @@ class Arrays
* @param int $sort_type
* @return array
*/
public function sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC)
public function sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC): array
{
$key_arrays = array();
if (is_array($arrays)) {
......
......@@ -33,9 +33,9 @@ class Decimals
* @param $num
* @return int
*/
public function intval($num)
public function intval($num): int
{
return intval($num);
return (int)$num;
}
/**
......
......@@ -66,7 +66,7 @@ class Files
//先删除目录下的文件:
$dh = opendir($name);
while ($file = readdir($dh)) {
if ($file != "." && $file != "..") {
if ($file !== "." && $file !== "..") {
$fullpath = $name . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
......
......@@ -35,10 +35,7 @@ class Ints
*/
public function isEvenNumbers(int $num): bool
{
if ($num % 2 == 0) {
return true;
}
return false;
return $num % 2 === 0;
}
/**
......@@ -48,9 +45,6 @@ class Ints
*/
public function isOddNumbers(int $num): bool
{
if ($num % 2 == 0) {
return false;
}
return true;
return !($num % 2 === 0);
}
}
......@@ -37,26 +37,26 @@ class Randoms
* @return string
* @throws Exception
*/
public function generate(int $length = 6, int $type = 1)
public function generate(int $length = 6, int $type = 1): string
{
// 取字符集数组
$number = range(0, 9);
$lowerLetter = range('a', 'z');
$upperLetter = range('A', 'Z');
// 根据type合并字符集
if ($type == 1) {
if ($type === 1) {
$charset = $number;
} elseif ($type == 2) {
} elseif ($type === 2) {
$charset = $lowerLetter;
} elseif ($type == 3) {
} elseif ($type === 3) {
$charset = $upperLetter;
} elseif ($type == 4) {
} elseif ($type === 4) {
$charset = array_merge($number, $lowerLetter);
} elseif ($type == 5) {
} elseif ($type === 5) {
$charset = array_merge($number, $upperLetter);
} elseif ($type == 6) {
} elseif ($type === 6) {
$charset = array_merge($lowerLetter, $upperLetter);
} elseif ($type == 7) {
} elseif ($type === 7) {
$charset = array_merge($number, $lowerLetter, $upperLetter);
} else {
$charset = $number;
......@@ -66,25 +66,25 @@ class Randoms
for ($i = 0; $i < $length; $i++) {
$str .= $charset[random_int(0, count($charset) - 1)];
// 验证规则
if ($type == 4 && strlen($str) >= 2) {
if ($type === 4 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type == 5 && strlen($str) >= 2) {
if ($type === 5 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type == 6 && strlen($str) >= 2) {
if ($type === 6 && strlen($str) >= 2) {
if (!preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type == 7 && strlen($str) >= 3) {
if ($type === 7 && strlen($str) >= 3) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -2);
$i -= 2;
......
......@@ -230,7 +230,7 @@ class Requests
*/
public function getWebsiteAddress(): string
{
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')) ? 'https://' : 'http://';
return $http_type . $_SERVER['HTTP_HOST'] . "/";
}
}
......@@ -69,7 +69,7 @@ class Returns
* @param array $data 数据
* @param array $ext 扩展字段
*/
public function jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = [])
public function jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = []): void
{
if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge([
......
......@@ -81,14 +81,14 @@ class Strings
if (strpos($str, $del) !== false) {
$var = explode($del, $str);
foreach ($var as $v) {
if ($v == $nee) {
if ($v === $nee) {
return true;
}
}
return false;
}
return $str == $nee;
return $str === $nee;
}
/**
......
......@@ -58,7 +58,7 @@ class Times
date_default_timezone_set('Asia/Shanghai');
$msec = 0;
list($msec, $sec) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
return (float)sprintf('%.0f', ((float)$msec + (float)$sec) * 1000);
}
/**
......@@ -71,7 +71,7 @@ class Times
{
date_default_timezone_set('Asia/Shanghai');
$end_time = strtotime($end_time);
$start_time = $start_time == '' ? time() : strtotime($start_time);
$start_time = $start_time === '' ? time() : strtotime($start_time);
return $end_time - $start_time;
}
......
......@@ -46,7 +46,7 @@ class UnIqIds
$chars = $numbs;
}
if ((int)$type === 2) {
$chars = "{$chars}";
$chars = ($chars);
}
if ((int)$type === 3) {
$chars = "{$numbs}{$chars}";
......
......@@ -63,7 +63,7 @@ class Urls
{
$buff = "";
foreach ($data as $k => $v) {
if ($k != "sign" && $v !== "" && !is_array($v)) {
if ($k !== "sign" && $v !== "" && !is_array($v)) {
$buff .= $k . "=" . $v . "&";
}
}
......
......@@ -36,7 +36,7 @@ class Xmls
* @return string
* @throws DtaException
*/
public function toXml(array $values)
public function toXml(array $values): string
{
if (!is_array($values) || count($values) <= 0) {
throw new DtaException('数组数据异常!');
......
......@@ -35,7 +35,7 @@ class BeAryChatService extends Service
* @param string $content 消息内容
* @return bool 发送结果
*/
public function text(string $webhook, string $content)
public function text(string $webhook, string $content): bool
{
return $this->sendMsg($webhook, [
'text' => $content
......@@ -48,16 +48,13 @@ class BeAryChatService extends Service
* @param array $data 消息内容数组
* @return bool 发送结果
*/
private function sendMsg(string $webhook, array $data)
private function sendMsg(string $webhook, array $data): bool
{
$result = HttpService::instance()
->url($webhook)
->data($data)
->toArray();
if ($result['code'] !== 0) {
return true;
}
return false;
return $result['code'] !== 0;
}
}
......@@ -37,8 +37,14 @@ class DingTalkService extends Service
*/
private $msg_type = 'text';
/**
* @var
*/
private $access_token;
/**
* @var string
*/
private $oapi_url = "https://oapi.dingtalk.com/";
/**
......@@ -46,7 +52,7 @@ class DingTalkService extends Service
* @param string $str
* @return $this
*/
public function accessToken(string $str)
public function accessToken(string $str): self
{
$this->access_token = $str;
return $this;
......@@ -58,7 +64,7 @@ class DingTalkService extends Service
* @return bool 发送结果
* @throws DtaException
*/
public function text(string $content)
public function text(string $content): bool
{
$this->msg_type = 'text';
return $this->sendMsg([
......@@ -74,7 +80,7 @@ class DingTalkService extends Service
* @return bool 发送结果
* @throws DtaException
*/
private function sendMsg(array $data)
private function sendMsg(array $data): bool
{
if (empty($this->access_token)) {
throw new DtaException("请检查access_token");
......
......@@ -21,15 +21,15 @@ namespace DtApp\ThinkLibrary\service\Ip;
class IpIpDistrictInfo
{
public $country_name = '';
public $region_name = '';
public $city_name = '';
public $district_name = '';
public $china_admin_code = '';
public $covering_radius = '';
public $longitude = '';
public $latitude = '';
/**
* @var
*/
public $country_name , $region_name, $city_name , $district_name , $china_admin_code, $covering_radius,$longitude , $latitude = '';
/**
* IpIpDistrictInfo constructor.
* @param array $data
*/
public function __construct(array $data)
{
foreach ($data AS $field => $value) {
......@@ -37,6 +37,10 @@ class IpIpDistrictInfo
}
}
/**
* @param $name
* @return mixed
*/
public function __get($name)
{
return $this->{$name};
......
......@@ -25,17 +25,17 @@ use InvalidArgumentException;
class IpIpReader
{
const IPV4 = 1;
const IPV6 = 2;
public const IPV4 = 1;
public const IPV6 = 2;
private $file = NULL;
private $file;
private $fileSize = 0;
private $nodeCount = 0;
private $nodeOffset = 0;
private $meta = [];
private $database = '';
private $database;
/**
* Reader constructor.
......@@ -49,7 +49,10 @@ class IpIpReader
$this->init();
}
private function init()
/**
* @throws Exception
*/
private function init(): void
{
if (is_readable($this->database) === FALSE) {
throw new InvalidArgumentException("The IP Database file \"{$this->database}\" does not exist or is not readable.");
......@@ -73,7 +76,7 @@ class IpIpReader
}
$fileSize = 4 + $metaLength + $this->meta['total_size'];
if ($fileSize != $this->fileSize) {
if ($fileSize !== $this->fileSize) {
throw new Exception('IP Database size error.');
}
......@@ -86,7 +89,7 @@ class IpIpReader
* @param string $language
* @return array|NULL
*/
public function find($ip, $language)
public function find($ip, $language): ?array
{
if (is_resource($this->file) === FALSE) {
throw new BadMethodCallException('IPIP DB closed.');
......@@ -102,7 +105,9 @@ class IpIpReader
if (strpos($ip, '.') !== FALSE && !$this->supportV4()) {
throw new InvalidArgumentException("The Database not support IPv4 address.");
} elseif (strpos($ip, ':') !== FALSE && !$this->supportV6()) {
}
if (strpos($ip, ':') !== FALSE && !$this->supportV6()) {
throw new InvalidArgumentException("The Database not support IPv6 address.");
}
......@@ -123,6 +128,11 @@ class IpIpReader
return NULL;
}
/**
* @param $ip
* @param $language
* @return array|false|null
*/
public function findMap($ip, $language)
{
$array = $this->find($ip, $language);
......@@ -133,7 +143,14 @@ class IpIpReader
return array_combine($this->meta['fields'], $array);
}
/**
* @var int
*/
private $v4offset = 0;
/**
* @var array
*/
private $v6offsetCache = [];
/**
......@@ -141,7 +158,7 @@ class IpIpReader
* @return int
* @throws Exception
*/
private function findNode($ip)
private function findNode($ip): int
{
$binary = inet_pton($ip);
$bitCount = strlen($binary) * 8; // 32 | 128
......@@ -186,7 +203,9 @@ class IpIpReader
if ($node === $this->nodeCount) {
return 0;
} elseif ($node > $this->nodeCount) {
}
if ($node > $this->nodeCount) {
return $node;
}
......@@ -224,7 +243,10 @@ class IpIpReader
return $this->read($this->file, $resolved, $size);
}
public function close()
/**
*
*/
public function close(): void
{
if (is_resource($this->file) === TRUE) {
fclose($this->file);
......@@ -254,16 +276,25 @@ class IpIpReader
return '';
}
public function supportV6()
/**
* @return bool
*/
public function supportV6(): bool
{
return ($this->meta['ip_version'] & self::IPV6) === self::IPV6;
}
public function supportV4()
/**
* @return bool
*/
public function supportV4(): bool
{
return ($this->meta['ip_version'] & self::IPV4) === self::IPV4;
}
/**
* @return array
*/
public function getMeta()
{
return $this->meta;
......
......@@ -31,13 +31,16 @@ use think\App;
*/
class IpIpService extends Service
{
public $reader = null;
/**
* @var IpIpReader|null
*/
public $reader;
/**
* IP数据库文件存放位置
* @var mixed
*/
private $ipPath = '';
private $ipPath;
/**
* IpIpService constructor.
......
......@@ -53,7 +53,7 @@ class MapService extends Service
* @param $str
* @return $this
*/
public function key(string $str)
public function key(string $str): self
{
$this->key = $str;
return $this;
......@@ -64,7 +64,7 @@ class MapService extends Service
* @param $str
* @return $this
*/
public function ak(string $str)
public function ak(string $str): self
{
$this->ak = $str;
return $this;
......@@ -75,7 +75,7 @@ class MapService extends Service
* @param string $str
* @return $this
*/
public function ip(string $str)
public function ip(string $str): self
{
$this->ip = $str;
return $this;
......
......@@ -41,7 +41,7 @@ class OnlineService extends Service
* @param string $str
* @return $this
*/
public function ip(string $str)
public function ip(string $str): self
{
$this->ip = $str;
return $this;
......@@ -151,8 +151,7 @@ class OnlineService extends Service
$res = iconv('gbk', 'utf-8', $res);
$res = substr($res, strpos($res, "{"));
$res = substr($res, 0, -2);
$res = str_replace("city", '"city"', $res);
$res = str_replace("province", '"province"', $res);
$res = str_replace(array("city", "province"), array('"city"', '"province"'), $res);
$res = json_decode($res, true);
return $res;
}
......@@ -221,7 +220,7 @@ class OnlineService extends Service
throw new DtaException('请检查阿里-阿里云配置信息 appcode');
}
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$headers[] = "Authorization:APPCODE " . $appcode;
$querys = "ip={$this->ip}";
$bodys = "";
$url = $host . $path . "?" . $querys;
......
......@@ -226,15 +226,15 @@ class QqWryService extends Service
break;
}
// CZ88.NET表示没有有效信息
if (trim($location['all']) == 'CZ88.NET') {
if (trim($location['all']) === 'CZ88.NET') {
$location['all'] = $this->unknown;
}
if (trim($location['extend']) == 'CZ88.NET') {
if (trim($location['extend']) === 'CZ88.NET') {
$location['extend'] = '';
}
$location['all'] = iconv("gb2312", "UTF-8//IGNORE", $location['all']);
$location['extend'] = iconv("gb2312", "UTF-8//IGNORE", $location['extend']);
$location['extend'] = $location['extend'] === null ? '' : $location['extend'];
$location['extend'] = $location['extend'] ?? '';
$parseData = $this->parseLocation($location['all']);
$location['state'] = $parseData[0];
$location['city'] = $parseData[1];
......
......@@ -34,18 +34,18 @@ class RouteService extends Service
* @param int $status
* @param bool $parameter
*/
public function redirect(string $url = '', int $status = 302, bool $parameter = false)
public function redirect(string $url = '', int $status = 302, bool $parameter = false): void
{
if (empty($url)) {
$url = request()->scheme() . "://" . request()->host();
}
$param = http_build_query(request()->param());
if ($status == 301) {
if ($status === 301) {
header('HTTP/1.1 301 Moved Permanently');
}
if (empty($parameter)) {
header("Location: {$url}");
} elseif (empty($parameter) == false && empty($param) == true) {
} elseif (empty($parameter) === false && empty($param) === true) {
header("Location: {$url}");
} else {
header("Location: {$url}?{$param}");
......
......@@ -28,6 +28,9 @@ use DtApp\ThinkLibrary\Service;
*/
class StorageService extends Service
{
/**
* @var string
*/
private $path = '', $remotely = '';
/**
......@@ -35,7 +38,7 @@ class StorageService extends Service
* @param string $path
* @return $this
*/
public function path(string $path)
public function path(string $path): self
{
$this->path = $path;
return $this;
......@@ -46,7 +49,7 @@ class StorageService extends Service
* @param string $remotely
* @return $this
*/
public function remotely(string $remotely)
public function remotely(string $remotely): self
{
$this->remotely = $remotely;
return $this;
......@@ -56,7 +59,7 @@ class StorageService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->path = config('dtapp.storage.path');
return $this;
......@@ -67,13 +70,13 @@ class StorageService extends Service
* @param string $name 保存的文件名
* @return array
*/
public function save(string $name)
public function save(string $name): array
{
if (empty($this->path)) {
$this->getConfig();
}
// 判断文件夹是否存在
is_dir($this->path) or mkdir($this->path, 0777, true);
is_dir($this->path) || mkdir($concurrentDirectory = $this->path, 0777, true) || is_dir($concurrentDirectory);
$return_content = $this->http_get_data($this->remotely);
$fp = @fopen("{$this->path}{$name}", "a"); //将文件绑定到流
fwrite($fp, $return_content); //写入文件
......@@ -99,8 +102,7 @@ class StorageService extends Service
curl_setopt($ch, CURLOPT_URL, $url);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
ob_end_clean();
$return_content = ob_get_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $return_content;
}
......@@ -141,7 +143,7 @@ class StorageService extends Service
} elseif ($bytes >= 1024) {
$bytes = round($bytes / 1024 * 100) / 100 . 'KB';
} else {
$bytes = $bytes . 'Bytes';
$bytes .= 'Bytes';
}
return $bytes;
}
......@@ -150,7 +152,7 @@ class StorageService extends Service
* 获取文件路径
* @return string
*/
public function getPath()
public function getPath(): string
{
if (empty($this->path)) {
$this->getConfig();
......
......@@ -38,7 +38,7 @@ class SystemService extends Service
* @param boolean|string $fillSuffix 补上后缀
* @return string
*/
public function uri($url = '', array $vars = [], $suffix = true, $domain = false, $fillSuffix = false)
public function uri($url = '', array $vars = [], $suffix = true, $domain = false, $fillSuffix = false): string
{
$default_app = config('app.default_app', 'index');
$default_action = config('route.default_action', 'index');
......@@ -56,9 +56,9 @@ class SystemService extends Service
$location = $this->app->route->buildUrl($url, [])->suffix($suffix)->domain($domain)->build();
}
if (empty($vars)) {
$location = substr($location . "{$pathinfo_depr}" . $this->arr_to_str($vars, $pathinfo_depr), 0, -1) . ".{$url_html_suffix}";
$location = substr($location . ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr), 0, -1) . ".{$url_html_suffix}";
} else {
$location = $location . "{$pathinfo_depr}" . $this->arr_to_str($vars, $pathinfo_depr) . ".{$url_html_suffix}";
$location .= ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr) . ".{$url_html_suffix}";
}
} else {
$location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build();
......@@ -82,6 +82,9 @@ class SystemService extends Service
return $t;
}
/**
* @var array
*/
private $result = [];
/**
......@@ -97,11 +100,9 @@ class SystemService extends Service
public function mac()
{
switch (strtolower(PHP_OS)) {
case 'unix':
break;
case "solaris":
break;
case "aix":
case 'unix':
break;
case "linux":
$this->getLinux();
......@@ -136,21 +137,21 @@ class SystemService extends Service
* Windows系统
* @return array
*/
private function getWindows()
private function getWindows(): array
{
@exec("ipconfig /all", $this->result);
if ($this->result) {
return $this->result;
} else {
$ipconfig = $_SERVER["WINDIR"] . "\system32\ipconfig.exe";
if (is_file($ipconfig)) {
@exec($ipconfig . " /all", $this->result);
return $this->result;
} else {
@exec($_SERVER["WINDIR"] . "\system\ipconfig.exe /all", $this->result);
return $this->result;
}
}
$ipconfig = $_SERVER["WINDIR"] . "\system32\ipconfig.exe";
if (is_file($ipconfig)) {
@exec($ipconfig . " /all", $this->result);
return $this->result;
}
@exec($_SERVER["WINDIR"] . "\system\ipconfig.exe /all", $this->result);
return $this->result;
}
/**
......
......@@ -36,7 +36,7 @@ class WorkKileService extends Service
* @param string $content 消息内容
* @return bool 发送结果
*/
public function text(string $webhook, string $user, string $content)
public function text(string $webhook, string $user, string $content): bool
{
return $this->sendMsg($webhook, [
'user' => $user,
......@@ -50,15 +50,12 @@ class WorkKileService extends Service
* @param array $data 消息内容数组
* @return bool 发送结果
*/
private function sendMsg(string $webhook, array $data)
private function sendMsg(string $webhook, array $data): bool
{
$result = HttpService::instance()
->url($webhook)
->data($data)
->toArray();
if ($result['code'] == 200) {
return true;
}
return false;
return $result['code'] === 200;
}
}
......@@ -31,27 +31,46 @@ use OSS\OssClient;
*/
class OssService extends Service
{
/**
* @var
*/
private $accessKeyId, $accessKeySecret, $endpoint, $bucket;
/**
* @param string $accessKeyId
* @return $this
*/
public function accessKeyId(string $accessKeyId)
{
$this->accessKeyId = $accessKeyId;
return $this;
}
/**
* @param string $accessKeySecret
* @return $this
*/
public function accessKeySecret(string $accessKeySecret)
{
$this->accessKeySecret = $accessKeySecret;
return $this;
}
public function endpoint(string $endpoint)
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
public function bucket(string $bucket)
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
......@@ -61,7 +80,7 @@ class OssService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->accessKeyId = config('dtapp.aliyun.oss.access_key_id');
$this->accessKeySecret = config('dtapp.aliyun.oss.access_key_secret');
......
......@@ -31,12 +31,25 @@ use DtApp\ThinkLibrary\service\curl\HttpService;
*/
class AmApService extends Service
{
/**
* @var string
*/
private $url = "https://restapi.amap.com/v3/";
/**
* @var string
*/
private $key = "";
/**
* @var string
*/
private $output = "JSON";
/**
* @param string $key
* @return $this
*/
public function key(string $key)
{
$this->key = $key;
......@@ -47,7 +60,7 @@ class AmApService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->key = config('dtapp.amap.key');
return $this;
......
......@@ -31,26 +31,45 @@ use Exception;
*/
class BosService extends Service
{
/**
* @var
*/
private $accessKeyId, $secretAccessKey, $endpoint, $bucket;
/**
* @param string $accessKeyId
* @return $this
*/
public function accessKeyId(string $accessKeyId)
{
$this->accessKeyId = $accessKeyId;
return $this;
}
/**
* @param string $secretAccessKey
* @return $this
*/
public function secretAccessKey(string $secretAccessKey)
{
$this->secretAccessKey = $secretAccessKey;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint)
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket)
{
$this->bucket = $bucket;
......@@ -61,7 +80,7 @@ class BosService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->accessKeyId = config('dtapp.baidu.bos.access_key_id');
$this->secretAccessKey = config('dtapp.baidu.bos.secret_access_key');
......@@ -77,7 +96,7 @@ class BosService extends Service
* @return bool
* @throws Exception
*/
public function upload(string $object, string $filePath)
public function upload(string $object, string $filePath): bool
{
if (empty($this->accessKeyId) || empty($this->secretAccessKey) || empty($this->endpoint)) {
$this->getConfig();
......
......@@ -31,13 +31,26 @@ use DtApp\ThinkLibrary\service\curl\HttpService;
*/
class LbsYunService extends Service
{
/**
* @var string
*/
private $url = "http://api.map.baidu.com/";
/**
* @var string
*/
private $ak = "";
/**
* @var string
*/
private $output = "json";
public function ak(string $ak)
/**
* @param string $ak
* @return $this
*/
public function ak(string $ak): self
{
$this->ak = $ak;
return $this;
......@@ -47,7 +60,7 @@ class LbsYunService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->ak = config('dtapp.baidu.lbs.ak');
return $this;
......
......@@ -32,19 +32,50 @@ use DtApp\ThinkLibrary\service\curl\BtService;
*/
class ApiService extends Service
{
/**
* @var string
*/
private $url = '';
/**
* @var int
*/
private $page = 1;
/**
* @var int
*/
private $limit = 15;
/**
* @var string
*/
private $order = 'id desc';
/**
* @var array
*/
private $where = [];
/**
* @var
*/
private $contents, $backtrack, $key, $panel;
public function key(string $key)
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* @param string $panel
* @return $this
*/
public function panel(string $panel)
{
$this->panel = $panel;
......@@ -55,7 +86,7 @@ class ApiService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->key = config('dtapp.bt.key');
$this->panel = config('dtapp.bt.panel');
......@@ -87,7 +118,7 @@ class ApiService extends Service
*/
public function getSites()
{
$this->url = $this->mimes('GetDataList');
$this->url = "crontab?action=GetDataList";
$this->where['type'] = 'sites';
return $this;
}
......@@ -98,7 +129,7 @@ class ApiService extends Service
*/
public function getDatabases()
{
$this->url = $this->mimes('getData');
$this->url = 'data?action=getData';
$this->where['tojs'] = 'database.get_list';
$this->where['table'] = 'databases';
$this->where['limit'] = $this->limit;
......@@ -113,7 +144,7 @@ class ApiService extends Service
*/
public function getFirewalls()
{
$this->url = $this->mimes('getData');
$this->url = 'data?action=getData';
$this->where['tojs'] = 'firewall.get_list';
$this->where['table'] = 'firewall';
$this->where['limit'] = $this->limit;
......@@ -128,7 +159,7 @@ class ApiService extends Service
*/
public function getLogs()
{
$this->url = $this->mimes('getData');
$this->url = 'data?action=getData';
$this->where['tojs'] = 'firewall.get_log_list';
$this->where['table'] = 'logs';
$this->where['limit'] = $this->limit;
......@@ -143,7 +174,7 @@ class ApiService extends Service
*/
public function getNews()
{
$this->url = $this->mimes('get_settings');
$this->url = 'config?action=get_settings';
return $this;
}
......@@ -153,7 +184,7 @@ class ApiService extends Service
*/
public function getCronTabs()
{
$this->url = $this->mimes('getData');
$this->url = 'data?action=getData';
$this->where['tojs'] = 'site.get_list';
$this->where['table'] = 'sites';
$this->where['limit'] = $this->limit;
......@@ -168,7 +199,7 @@ class ApiService extends Service
*/
public function getTypes()
{
$this->url = $this->mimes('get_site_types');
$this->url = 'site?action=get_site_types';
return $this;
}
......@@ -178,7 +209,7 @@ class ApiService extends Service
*/
public function getSoFts()
{
$this->url = $this->mimes('get_soft_list');
$this->url = 'plugin?action=get_soft_list';
$this->where['p'] = $this->page;
$this->where['tojs'] = 'soft.get_list';
return $this;
......@@ -190,7 +221,7 @@ class ApiService extends Service
*/
public function getDiskInfo()
{
$this->url = $this->mimes('GetDiskInfo');
$this->url = 'system?action=GetDiskInfo';
return $this;
}
......@@ -200,7 +231,7 @@ class ApiService extends Service
*/
public function getSystemTotal()
{
$this->url = $this->mimes('GetSystemTotal');
$this->url = 'system?action=GetSystemTotal';
return $this;
}
......@@ -210,7 +241,7 @@ class ApiService extends Service
*/
public function getUserInfo()
{
$this->url = $this->mimes('GetUserInfo');
$this->url = 'ssl?action=GetUserInfo';
return $this;
}
......@@ -220,7 +251,7 @@ class ApiService extends Service
*/
public function getNetWork()
{
$this->url = $this->mimes('GetNetWork');
$this->url = 'system?action=GetNetWork';
return $this;
}
......@@ -230,7 +261,7 @@ class ApiService extends Service
*/
public function getPlugin()
{
$this->url = $this->mimes('get_index_list');
$this->url = 'plugin?action=get_index_list';
return $this;
}
......@@ -240,7 +271,7 @@ class ApiService extends Service
*/
public function getSoft()
{
$this->url = $this->mimes('get_soft_list');
$this->url = 'plugin?action=get_soft_list';
return $this;
}
......@@ -250,16 +281,16 @@ class ApiService extends Service
*/
public function getUpdatePanel()
{
$this->url = $this->mimes('UpdatePanel');
$this->url = 'ajax?action=UpdatePanel';
return $this;
}
/**
* 当前页码
* @param int $is
* @return ApiService
* @return $this
*/
public function page(int $is = 1)
public function page(int $is = 1): self
{
$this->page = $is;
return $this;
......@@ -268,9 +299,9 @@ class ApiService extends Service
/**
* 返回数量
* @param int $is
* @return ApiService
* @return $this
*/
public function limit(int $is = 15)
public function limit(int $is = 15): self
{
$this->limit = $is;
return $this;
......@@ -281,7 +312,7 @@ class ApiService extends Service
* @param string $ss
* @return $this
*/
public function order(string $ss = 'id desc')
public function order(string $ss = 'id desc'): self
{
$this->order = $ss;
return $this;
......@@ -292,7 +323,7 @@ class ApiService extends Service
* @param array $array
* @return ApiService
*/
public function where($array = [])
public function where($array = []): ApiService
{
$this->where = $array;
return $this;
......@@ -300,8 +331,9 @@ class ApiService extends Service
/**
* 获取数据和总数
* @return $this
*/
private function getDataWithOrderOpt()
private function getDataWithOrderOpt(): self
{
$this->backtrack['data'] = $this->contents['data'];
$this->backtrack['orderOpt'] = $this->contents['orderOpt'];
......@@ -310,8 +342,9 @@ class ApiService extends Service
/**
* 获取数据和总数
* @return $this
*/
private function getDataWithCount()
private function getDataWithCount(): self
{
if (empty($this->contents['data'])) {
$this->contents['data'] = [];
......@@ -342,7 +375,7 @@ class ApiService extends Service
* @return $this
* @throws DtaException
*/
private function getHttp()
private function getHttp(): self
{
//请求面板接口
$this->contents = $this->HttpPostCookie($this->url, $this->where);
......@@ -357,7 +390,7 @@ class ApiService extends Service
public function toArray()
{
$this->getHttp();
if ($this->where['type'] == 'sites') {
if ($this->where['type'] === 'sites') {
$this->getDataWithOrderOpt();
} else {
$this->getDataWithCount();
......@@ -371,20 +404,6 @@ class ApiService extends Service
return json_decode($this->backtrack, true);
}
/**
* 获取文件的信息
* @param $name
* @return string
*/
private function mimes($name): string
{
$mimes = include __DIR__ . '/bin/mimes.php';
if (isset($mimes[$name])) {
return '/' . $mimes[$name];
}
return '';
}
/**
* 发起POST请求
* @param string $url 网址
......@@ -408,7 +427,7 @@ class ApiService extends Service
throw new \RuntimeException(sprintf('Directory "%s" was not created', $file));
}
if (!file_exists($cookie_file)) {
$fp = fopen($cookie_file, 'w+');
$fp = fopen($cookie_file, 'wb+');
fclose($fp);
}
if (empty($this->key)) {
......
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
return [
'getData' => 'data?action=getData',
'GetDataList' => 'crontab?action=GetDataList',
'get_settings' => 'config?action=get_settings',
'GetNetWork' => 'system?action=GetNetWork',
'GetDiskInfo' => 'system?action=GetDiskInfo',
'get_site_types' => 'site?action=get_site_types',
'GetSystemTotal' => 'system?action=GetSystemTotal',
'UpdatePanel' => 'ajax?action=UpdatePanel',
'get_soft_list' => 'plugin?action=get_soft_list',
'get_index_list' => 'plugin?action=get_index_list',
'GetUserInfo' => 'ssl?action=GetUserInfo',
];
......@@ -23,14 +23,25 @@ use DtApp\ThinkLibrary\Service;
class AesService extends Service
{
/**
* @var
*/
private $key, $iv;
public function key($str)
/**
* @param $str
* @return $this
*/
public function key($str): self
{
$this->key = $str;
return $this;
}
/**
* @param $str
* @return $this
*/
public function iv($str)
{
$this->iv = $str;
......
......@@ -30,8 +30,19 @@ use think\exception\HttpException;
*/
class BtService extends Service
{
/**
* @var
*/
private $url, $key, $panel, $output, $cookie;
/**
* @var array
*/
private $data = [];
/**
* @var int
*/
private $timeout = 60;
/**
......@@ -39,7 +50,7 @@ class BtService extends Service
* @param string $str
* @return $this
*/
public function key(string $str)
public function key(string $str): self
{
$this->key = $str;
return $this;
......@@ -50,7 +61,7 @@ class BtService extends Service
* @param string $str
* @return $this
*/
public function panel(string $str)
public function panel(string $str): self
{
$this->panel = $str;
return $this;
......@@ -61,7 +72,7 @@ class BtService extends Service
* @param string $str
* @return $this
*/
public function url(string $str)
public function url(string $str): self
{
$this->url = $str;
return $this;
......@@ -72,7 +83,7 @@ class BtService extends Service
* @param string $str
* @return $this
*/
public function cookie(string $str)
public function cookie(string $str): self
{
$this->cookie = $str;
return $this;
......@@ -83,7 +94,7 @@ class BtService extends Service
* @param int $int
* @return $this
*/
public function timeout(int $int)
public function timeout(int $int): self
{
$this->timeout = $int;
return $this;
......@@ -94,7 +105,7 @@ class BtService extends Service
* @param array $array
* @return $this
*/
public function data(array $array)
public function data(array $array): self
{
$this->data = $array;
return $this;
......@@ -127,7 +138,7 @@ class BtService extends Service
* 发起请求
* @return $this
*/
private function http()
private function http(): self
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->panel . $this->url);
......@@ -150,7 +161,7 @@ class BtService extends Service
* 构造带有签名的关联数组
* @return array
*/
private function getKeyData()
private function getKeyData(): array
{
$time = time();
return array(
......
......@@ -29,9 +29,24 @@ use think\exception\HttpException;
*/
class HttpService extends Service
{
/**
* @var
*/
private $url, $data, $cert, $output;
/**
* @var int
*/
private $timeout = 60;
/**
* @var string
*/
private $method = 'GET';
/**
* @var string
*/
private $headers = 'application/json;charset=utf-8';
/**
......@@ -39,7 +54,7 @@ class HttpService extends Service
* @param string $str
* @return $this
*/
public function url(string $str)
public function url(string $str): self
{
$this->url = $str;
return $this;
......@@ -50,7 +65,7 @@ class HttpService extends Service
* @param $str
* @return $this
*/
public function data($str)
public function data($str): self
{
if (is_array($str)) {
$this->data = json_encode($str, JSON_UNESCAPED_UNICODE);
......@@ -65,7 +80,7 @@ class HttpService extends Service
* @param $str
* @return $this
*/
public function headers(string $str)
public function headers(string $str): self
{
$this->headers = $str;
return $this;
......@@ -76,7 +91,7 @@ class HttpService extends Service
* @param int $int
* @return $this
*/
public function timeout(int $int)
public function timeout(int $int): self
{
$this->timeout = $int;
return $this;
......@@ -88,7 +103,7 @@ class HttpService extends Service
* @param string $sslKeyPath
* @return $this
*/
public function cert(string $sslCertPath, string $sslKeyPath)
public function cert(string $sslCertPath, string $sslKeyPath): self
{
$this->cert = [
'key' => $sslKeyPath,
......@@ -101,7 +116,7 @@ class HttpService extends Service
* GET请求方式
* @return $this
*/
public function get()
public function get(): self
{
$this->method = 'GET';
return $this;
......@@ -111,7 +126,7 @@ class HttpService extends Service
* POST请求方式
* @return $this
*/
public function post()
public function post(): self
{
$this->method = 'POST';
return $this;
......@@ -121,7 +136,7 @@ class HttpService extends Service
* XML请求方式
* @return $this
*/
public function xml()
public function xml(): self
{
$this->method = 'XML';
return $this;
......@@ -131,7 +146,7 @@ class HttpService extends Service
* XML请求方式
* @return $this
*/
public function file()
public function file(): self
{
$this->method = 'FILE';
return $this;
......@@ -266,11 +281,9 @@ class HttpService extends Service
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLCERT, $this->cert['cert']);
curl_setopt($ch, CURLOPT_SSLKEY, $this->cert['key']);
} else {
if (substr($this->url, 0, 5) == 'https') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名
}
} else if (strpos($this->url, 'https') === 0) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名
}
if (!empty($this->headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: ' . $this->headers));
......
......@@ -40,6 +40,9 @@ use stdClass;
*/
class WatermarkService extends Service
{
/**
* @var
*/
private $url, $apiUrl, $itemId, $dytk, $contents, $backtrack, $storage, $storagePath;
/**
......@@ -76,7 +79,7 @@ class WatermarkService extends Service
* @param string $path
* @return $this
*/
public function storage(string $type, string $path)
public function storage(string $type, string $path): self
{
$this->storage = $type;
$this->storagePath = $path;
......@@ -132,7 +135,7 @@ class WatermarkService extends Service
* 获取音乐信息
* @return string
*/
public function getMusicInfo()
public function getMusicInfo(): string
{
$this->getApi();
$data = json_decode($this->contents, true);
......@@ -185,7 +188,7 @@ class WatermarkService extends Service
* 获取接口全部信息
* @return $this
*/
public function getApi()
public function getApi(): self
{
$this->apiUrl = "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={$this->itemId}&dytk={$this->dytk}";
$this->contents = $this->getContents($this->apiUrl);
......@@ -217,13 +220,13 @@ class WatermarkService extends Service
$backtrack['share_info']['title'] = $item_list['share_info']['share_title'];
$backtrack['share_info']['url'] = $item_list['share_url'];
// 音乐信息
$backtrack['music_info']['id'] = isset($item_list['music']['id']) ? $item_list['music']['id'] : '';
$backtrack['music_info']['mid'] = isset($item_list['music']['mid']) ? $item_list['music']['mid'] : '';
$backtrack['music_info']['title'] = isset($item_list['music']['title']) ? $item_list['music']['title'] : '';
$backtrack['music_info']['author'] = isset($item_list['music']['author']) ? $item_list['music']['author'] : '';
$backtrack['music_info']['id'] = $item_list['music']['id'] ?? '';
$backtrack['music_info']['mid'] = $item_list['music']['mid'] ?? '';
$backtrack['music_info']['title'] = $item_list['music']['title'] ?? '';
$backtrack['music_info']['author'] = $item_list['music']['author'] ?? '';
$backtrack['music_info']['avatar'] = isset($item_list['music']) ? $this->cMusicAvatar($item_list['music']) : '';
$backtrack['music_info']['play'] = isset($item_list['music']['play_url']['uri']) ? $item_list['music']['play_url']['uri'] : '';
$backtrack['music_info']['cover'] = isset($item_list['music']['cover_large']['url_list'][0]) ? $item_list['music']['cover_large']['url_list'][0] : '';
$backtrack['music_info']['play'] = $item_list['music']['play_url']['uri'] ?? '';
$backtrack['music_info']['cover'] = $item_list['music']['cover_large']['url_list'][0] ?? '';
// 视频信息
$backtrack['video_info']['vid'] = $item_list['video']['vid'];
$backtrack['video_info']['desc'] = $item_list['desc'];
......@@ -235,7 +238,7 @@ class WatermarkService extends Service
$backtrack['video_info']['cover'] = $cVideoAvatar['cover'];
$backtrack['video_info']['play'] = $this->cVideoPlayUrl($item_list['video']['play_addr']['url_list'][0], 'play');
$backtrack['video_info']['playwm'] = $this->cVideoPlayUrl($item_list['video']['play_addr']['url_list'][0], 'playwm');
$this->storagePath = $this->storagePath . $backtrack['author_info']['uid'] . "/";
$this->storagePath .= $backtrack['author_info']['uid'] . "/";
if (!empty($this->storage)) {
// 保存文件
// 作者头像
......@@ -530,7 +533,7 @@ class WatermarkService extends Service
$new_yun_path = config("dtapp.storage.domain_list.{$domain_name}") . "upload/watermark/{$yun_path}";
// 本地存储
// 作者头像
$backtrack['yun']['author_info']['avatar'] = "{$new_yun_path}" . $backtrack['author_info']['uid'] . ".jpeg";
$backtrack['yun']['author_info']['avatar'] = ($new_yun_path) . $backtrack['author_info']['uid'] . ".jpeg";
// 音频头像
$backtrack['yun']['music_info']['avatar'] = $new_yun_path . $backtrack['music_info']['mid'] . ".jpeg";
// 音频文件
......@@ -602,11 +605,13 @@ class WatermarkService extends Service
{
if (strpos($url, 'douyin.com') !== false) {
return $url;
} else if (strpos($url, 'iesdouyin.com') !== false) {
}
if (strpos($url, 'iesdouyin.com') !== false) {
return $url;
} else {
return '';
}
return '';
}
/**
......@@ -687,21 +692,10 @@ class WatermarkService extends Service
* @param $data
* @return string
*/
private function cAuthorAvatar($data)
private function cAuthorAvatar($data): string
{
// 1080x1080
if (isset($data['avatar_larger']['url_list'][0])) {
return $data['avatar_larger']['url_list'][0];
}
// 720x720
if (isset($data['avatar_medium']['url_list'][0])) {
return $data['avatar_medium']['url_list'][0];
}
// 100x100
if (isset($data['avatar_thumb']['url_list'][0])) {
return $data['avatar_thumb']['url_list'][0];
}
return '';
return $data['avatar_larger']['url_list'][0] ?? $data['avatar_medium']['url_list'][0] ?? $data['avatar_thumb']['url_list'][0] ?? '';
}
/**
......@@ -709,21 +703,10 @@ class WatermarkService extends Service
* @param $data
* @return string
*/
private function cMusicAvatar($data)
private function cMusicAvatar($data): string
{
// 1080x1080
if (isset($data['cover_hd']['url_list'][0])) {
return $data['cover_hd']['url_list'][0];
}
// 720x720
if (isset($data['cover_medium']['url_list'][0])) {
return $data['cover_medium']['url_list'][0];
}
// 100x100
if (isset($data['cover_thumb']['url_list'][0])) {
return $data['cover_thumb']['url_list'][0];
}
return '';
return $data['cover_hd']['url_list'][0] ?? $data['cover_medium']['url_list'][0] ?? $data['cover_thumb']['url_list'][0] ?? '';
}
/**
......@@ -731,7 +714,7 @@ class WatermarkService extends Service
* @param $data
* @return array
*/
private function cVideoAvatar($data)
private function cVideoAvatar($data): array
{
$array = [];
$array['dynamic'] = '';
......@@ -760,7 +743,7 @@ class WatermarkService extends Service
*/
private function cVideoPlayUrl($url, $type)
{
if ($type == 'play') {
if ($type === 'play') {
$headers = get_headers(str_replace("/playwm/", "/play/", $url), TRUE);
} else {
$headers = get_headers($url, TRUE);
......
......@@ -30,27 +30,46 @@ use Obs\ObsClient;
*/
class ObsService extends Service
{
/**
* @var
*/
private $key, $secret, $endpoint, $bucket;
public function key(string $key)
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
public function secret(string $secret)
/**
* @param string $secret
* @return $this
*/
public function secret(string $secret): self
{
$this->secret = $secret;
return $this;
}
public function endpoint(string $endpoint)
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
public function bucket(string $bucket)
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
......@@ -60,7 +79,7 @@ class ObsService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->key = config('dtapp.huaweicloud.obs.key');
$this->secret = config('dtapp.huaweicloud.obs.secret');
......@@ -75,7 +94,7 @@ class ObsService extends Service
* @param $filePath
* @return bool
*/
public function upload(string $object, string $filePath)
public function upload(string $object, string $filePath): bool
{
if (empty($this->key) || empty($this->secret) || empty($this->endpoint)) {
$this->getConfig();
......
......@@ -107,7 +107,7 @@ class UnionService extends Service
* @param string $secretKey
* @return $this
*/
public function secretKey(string $secretKey)
public function secretKey(string $secretKey): self
{
$this->secret_key = $secretKey;
return $this;
......@@ -129,7 +129,7 @@ class UnionService extends Service
* @param array $param
* @return $this
*/
public function param(array $param)
public function param(array $param): self
{
$this->param = $param;
return $this;
......@@ -139,7 +139,7 @@ class UnionService extends Service
* 网络请求
* @throws DtaException
*/
private function http()
private function http(): void
{
//生成签名
$sign = $this->createSign();
......@@ -156,7 +156,7 @@ class UnionService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->app_key = config('dtapp.jd.union.app_key');
$this->secret_key = config('dtapp.jd.union.secret_key');
......@@ -166,7 +166,7 @@ class UnionService extends Service
/**
* 网站/APP获取推广链接接口
* https://union.jd.com/openplatform/api/10421
* @return array|mixed
* @return $this
*/
public function promotionCommonGet()
{
......@@ -177,7 +177,7 @@ class UnionService extends Service
/**
* 社交媒体获取推广链接接口【申请】
* https://union.jd.com/openplatform/api/10424
* @return array|mixed
* @return $this
*/
public function promotionBySubUnionIdGet()
{
......@@ -188,7 +188,7 @@ class UnionService extends Service
/**
* 工具商获取推广链接接口【申请】
* https://union.jd.com/openplatform/api/10425
* @return array|mixed
* @return $this
*/
public function promotionByUnionIdGet()
{
......@@ -199,7 +199,7 @@ class UnionService extends Service
/**
* 订单行查询接口
* https://union.jd.com/openplatform/api/12707
* @return array|mixed
* @return $this
*/
public function orderRowQuery()
{
......@@ -210,7 +210,7 @@ class UnionService extends Service
/**
* 奖励订单查询接口【申请】
* https://union.jd.com/openplatform/api/11781
* @return array|mixed
* @return $this
*/
public function orderBonusQuery()
{
......@@ -221,7 +221,7 @@ class UnionService extends Service
/**
* 创建推广位【申请】
* https://union.jd.com/openplatform/api/10429
* @return array|mixed
* @return $this
*/
public function positionCreate()
{
......@@ -232,7 +232,7 @@ class UnionService extends Service
/**
* 查询推广位【申请】
* https://union.jd.com/openplatform/api/10428
* @return array|mixed
* @return $this
*/
public function positionQuery()
{
......@@ -243,7 +243,7 @@ class UnionService extends Service
/**
* 获取PID【申请】
* https://union.jd.com/openplatform/api/10430
* @return array|mixed
* @return $this
*/
public function userPidGet()
{
......@@ -254,7 +254,7 @@ class UnionService extends Service
/**
* 关键词商品查询接口【申请】
* https://union.jd.com/openplatform/api/10421
* @return array|mixed
* @return $this
*/
public function goodsQuery()
{
......@@ -265,7 +265,7 @@ class UnionService extends Service
/**
* 京粉精选商品查询接口
* https://union.jd.com/openplatform/api/10417
* @return array|mixed
* @return $this
*/
public function goodsJIngFenQuery()
{
......@@ -282,7 +282,7 @@ class UnionService extends Service
/**
* 根据skuid查询商品信息接口
* https://union.jd.com/openplatform/api/10422
* @return array|mixed
* @return $this
*/
public function goodsPromotionGoodsInfoQuery()
{
......@@ -293,7 +293,7 @@ class UnionService extends Service
/**
* 礼金创建【申请】
* https://union.jd.com/openplatform/api/12246
* @return array|mixed
* @return $this
*/
public function couponGiftGet()
{
......@@ -304,7 +304,7 @@ class UnionService extends Service
/**
* 礼金停止【申请】
* https://union.jd.com/openplatform/api/12240
* @return array|mixed
* @return $this
*/
public function couponGiftStop()
{
......@@ -315,7 +315,7 @@ class UnionService extends Service
/**
* 礼金效果数据
* https://union.jd.com/openplatform/api/12248
* @return array|mixed
* @return $this
*/
public function statisticsGifTCouponQuery()
{
......@@ -352,23 +352,23 @@ class UnionService extends Service
$this->params['param_json'] = json_encode($this->param, JSON_UNESCAPED_UNICODE);
$this->http();
$response = Strings::replace('.', '_', $this->method) . "_response";
if (isset($this->output["$response"]['result'])) {
if (is_array($this->output["$response"]['result'])) {
return $this->output["$response"]['result'];
}
if (is_object($this->output["$response"]['result'])) {
$this->output = json_encode($this->output["$response"]['result'], JSON_UNESCAPED_UNICODE);
if (isset($this->output[$response]['result'])) {
if (is_array($this->output[$response]['result'])) {
return $this->output[$response]['result'];
}
return json_decode($this->output["$response"]['result'], true);
} else {
if (is_array($this->output)) {
return $this->output;
if (is_object($this->output[$response]['result'])) {
$this->output = json_encode($this->output[$response]['result'], JSON_UNESCAPED_UNICODE);
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
return json_decode($this->output, true);
return json_decode($this->output[$response]['result'], true);
}
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
return json_decode($this->output, true);
}
/**
......@@ -376,7 +376,7 @@ class UnionService extends Service
* @return string
* @throws DtaException
*/
private function createSign()
private function createSign(): string
{
if (empty($this->secret_key)) {
$this->getConfig();
......@@ -387,7 +387,7 @@ class UnionService extends Service
$sign = $this->secret_key;
ksort($this->params);
foreach ($this->params as $key => $val) {
if ($key != '' && $val != '') {
if ($key !== '' && $val !== '') {
$sign .= $key . $val;
}
}
......@@ -400,11 +400,11 @@ class UnionService extends Service
* 组参
* @return string
*/
private function createStrParam()
private function createStrParam(): string
{
$strParam = '';
foreach ($this->params as $key => $val) {
if ($key != '' && $val != '') {
if ($key !== '' && $val !== '') {
$strParam .= $key . '=' . urlencode($val) . '&';
}
}
......@@ -415,7 +415,7 @@ class UnionService extends Service
* 获取频道ID
* @return array[]
*/
public function getEliteIdList()
public function getEliteIdList(): array
{
return [
[
......
......@@ -30,16 +30,17 @@ use DtApp\ThinkLibrary\service\curl\HttpService;
*/
class VientianeService extends Service
{
private $url = "https://way.jd.com/";
private $param, $app_key;
/**
* @var
*/
private $url, $param, $app_key;
/**
* 您申请的appkey
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey)
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
......@@ -50,7 +51,7 @@ class VientianeService extends Service
* @param array $param
* @return $this
*/
public function param(array $param)
public function param(array $param): self
{
$this->param = $param;
return $this;
......@@ -63,7 +64,7 @@ class VientianeService extends Service
*/
public function pm25Cities()
{
$this->url = "{$this->url}pm25/cities";
$this->url = "https://way.jd.com/pm25/cities";
return $this->http();
}
......@@ -73,7 +74,7 @@ class VientianeService extends Service
*/
public function heFreeWeather()
{
$this->url = "{$this->url}he/freeweather";
$this->url = "https://way.jd.com/he/freeweather";
return $this->http();
}
......@@ -83,7 +84,7 @@ class VientianeService extends Service
*/
public function jiSuApiWeather()
{
$this->url = "{$this->url}jisuapi/weather";
$this->url = "https://way.jd.com/jisuapi/weather";
return $this->http();
}
......@@ -93,7 +94,7 @@ class VientianeService extends Service
*/
public function jiSuApiSearch()
{
$this->url = "{$this->url}jisuapi/search";
$this->url = "https://way.jd.com/jisuapi/search";
return $this->http();
}
......@@ -103,7 +104,7 @@ class VientianeService extends Service
*/
public function rtBaSiaIpAreaDict()
{
$this->url = "{$this->url}RTBAsia/ip_area_dict";
$this->url = "https://way.jd.com/RTBAsia/ip_area_dict";
return $this->http();
}
......
......@@ -31,27 +31,46 @@ use Ks3ServiceException;
*/
class Ks3Service extends Service
{
/**
* @var
*/
private $accessKeyID, $accessKeySecret, $endpoint, $bucket;
/**
* @param string $accessKeyID
* @return $this
*/
public function accessKeyID(string $accessKeyID)
{
$this->accessKeyID = $accessKeyID;
return $this;
}
/**
* @param string $accessKeySecret
* @return $this
*/
public function accessKeySecret(string $accessKeySecret)
{
$this->accessKeySecret = $accessKeySecret;
return $this;
}
public function endpoint(string $endpoint)
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
public function bucket(string $bucket)
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
......@@ -61,7 +80,7 @@ class Ks3Service extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->accessKeyID = config('dtapp.ksyun.ks3.access_key_iD');
$this->accessKeySecret = config('dtapp.ksyun.ks3.access_key_secret');
......@@ -86,7 +105,7 @@ class Ks3Service extends Service
if (empty($this->bucket)) {
$this->getConfig();
}
$content = fopen($filePath, "r");
$content = fopen($filePath, 'rb');
$args = [
"Bucket" => $this->bucket,
"Key" => $object,
......
......@@ -43,22 +43,10 @@ class JinBaoService extends Service
private $type = '';
/**
* 开放平台分配的clientId
* 开放平台分配的
* @var string
*/
private $client_id = '';
/**
* 开放平台分配的clientSecret
* @var string
*/
private $client_secret = '';
/**
* 通过code获取的access_token(无需授权的接口,该字段不参与sign签名运算)
* @var string
*/
private $access_token = '';
private $client_id, $client_secret = '';
/**
* 响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写
......@@ -87,7 +75,7 @@ class JinBaoService extends Service
/*
* 配置开放平台分配的clientId
*/
public function clientId(string $clientId)
public function clientId(string $clientId): self
{
$this->client_id = $clientId;
return $this;
......@@ -98,7 +86,7 @@ class JinBaoService extends Service
* @param string $clientSecret
* @return $this
*/
public function clientSecret(string $clientSecret)
public function clientSecret(string $clientSecret): self
{
$this->client_secret = $clientSecret;
return $this;
......@@ -109,7 +97,7 @@ class JinBaoService extends Service
* @param string $dataType
* @return $this
*/
public function dataType(string $dataType)
public function dataType(string $dataType): self
{
$this->data_type = $dataType;
return $this;
......@@ -120,7 +108,7 @@ class JinBaoService extends Service
* @param array $param
* @return $this
*/
public function param(array $param)
public function param(array $param): self
{
$this->param = $param;
return $this;
......@@ -128,10 +116,10 @@ class JinBaoService extends Service
/**
* 网络请求
* @return JinBaoService
* @return $this
* @throws DtaException
*/
private function http()
private function http(): self
{
//生成签名
$sign = $this->createSign();
......@@ -150,7 +138,7 @@ class JinBaoService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->client_id = config('dtapp.pinduoduo.jinbao.client_id');
$this->client_secret = config('dtapp.pinduoduo.jinbao.client_secret');
......@@ -162,7 +150,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search
* @return $this
*/
public function goodsSearch()
public function goodsSearch(): self
{
$this->type = 'pdd.ddk.goods.search';
return $this;
......@@ -173,7 +161,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.generate
* @return $this
*/
public function goodsPidGenerate()
public function goodsPidGenerate(): self
{
$this->type = 'pdd.ddk.goods.pid.generate';
return $this;
......@@ -184,7 +172,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.query
* @return $this
*/
public function goodsPidQuery()
public function goodsPidQuery(): self
{
$this->type = 'pdd.ddk.goods.pid.query';
return $this;
......@@ -195,7 +183,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.detail.get
* @return $this
*/
public function orderDetailGet()
public function orderDetailGet(): self
{
$this->type = 'pdd.ddk.order.detail.get';
return $this;
......@@ -206,7 +194,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.list.increment.get
* @return $this
*/
public function orderListIncrementGet()
public function orderListIncrementGet(): self
{
$this->type = 'pdd.ddk.order.list.increment.get';
return $this;
......@@ -217,7 +205,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.list.range.get
* @return $this
*/
public function orderListRangeGet()
public function orderListRangeGet(): self
{
$this->type = 'pdd.ddk.order.list.range.get';
return $this;
......@@ -228,7 +216,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.finance.cpa.query
* @return $this
*/
public function financeCpaQuery()
public function financeCpaQuery(): self
{
$this->type = 'pdd.ddk.finance.cpa.query';
return $this;
......@@ -239,7 +227,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.promotion.url.generate
* @return $this
*/
public function goodsPromotionUrlGenerate()
public function goodsPromotionUrlGenerate(): self
{
$this->type = 'pdd.ddk.goods.promotion.url.generate';
return $this;
......@@ -250,7 +238,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.weapp.qrcode.url.gen
* @return $this
*/
public function weAppQrcodeUrlGen()
public function weAppQrcodeUrlGen(): self
{
$this->type = 'pdd.ddk.weapp.qrcode.url.gen';
return $this;
......@@ -261,7 +249,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.zs.unit.url.gen
* @return $this
*/
public function goodsZsUitUrlGen()
public function goodsZsUitUrlGen(): self
{
$this->type = 'pdd.ddk.goods.zs.unit.url.gen';
return $this;
......@@ -272,7 +260,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.resource.url.gen
* @return $this
*/
public function resourceUrlGen()
public function resourceUrlGen(): self
{
$this->type = 'pdd.ddk.resource.url.gen';
return $this;
......@@ -283,7 +271,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.theme.prom.url.generate
* @return $this
*/
public function themePromUrlGenerate()
public function themePromUrlGenerate(): self
{
$this->type = 'pdd.ddk.theme.prom.url.generate';
return $this;
......@@ -294,7 +282,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.mall.url.gen
* @return $this
*/
public function mallUrlGen()
public function mallUrlGen(): self
{
$this->type = 'pdd.ddk.mall.url.gen';
return $this;
......@@ -305,7 +293,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.rp.prom.url.generate
* @return $this
*/
public function rpPromUrlGenerate()
public function rpPromUrlGenerate(): self
{
$this->type = 'pdd.ddk.rp.prom.url.generate';
return $this;
......@@ -316,7 +304,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.detail
* @return $this
*/
public function goodsDetail()
public function goodsDetail(): self
{
$this->type = 'pdd.ddk.goods.detail';
return $this;
......@@ -327,7 +315,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.unit.query
* @return $this
*/
public function goodsUnitQuery()
public function goodsUnitQuery(): self
{
$this->type = 'pdd.ddk.goods.unit.query';
return $this;
......@@ -338,7 +326,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.basic.info.get
* @return $this
*/
public function goodsBasicInfoGet()
public function goodsBasicInfoGet(): self
{
$this->type = 'pdd.ddk.goods.basic.info.get';
return $this;
......@@ -349,7 +337,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.coupon.info.query
* @return $this
*/
public function couponInfoQuery()
public function couponInfoQuery(): self
{
$this->type = 'pdd.ddk.coupon.info.query';
return $this;
......@@ -360,7 +348,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.mall.goods.list.get
* @return $this
*/
public function goodsListGet()
public function goodsListGet(): self
{
$this->type = 'pdd.ddk.mall.goods.list.get';
return $this;
......@@ -371,7 +359,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.top.goods.list.query
* @return $this
*/
public function topGoodsListQuery()
public function topGoodsListQuery(): self
{
$this->type = 'pdd.ddk.top.goods.list.query';
return $this;
......@@ -382,7 +370,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.recommend.get
* @return $this
*/
public function goodsRecommendGet()
public function goodsRecommendGet(): self
{
$this->type = 'pdd.ddk.goods.recommend.get';
return $this;
......@@ -393,7 +381,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.theme.list.get
* @return $this
*/
public function themeListGet()
public function themeListGet(): self
{
$this->type = 'pdd.ddk.theme.list.get';
return $this;
......@@ -404,7 +392,7 @@ class JinBaoService extends Service
* https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.theme.goods.search
* @return $this
*/
public function themeGoodsSearch()
public function themeGoodsSearch(): self
{
$this->type = 'pdd.ddk.theme.goods.search';
return $this;
......@@ -415,7 +403,7 @@ class JinBaoService extends Service
* https://open.pinduoduo.com/application/document/api?id=pdd.ddk.cms.prom.url.
* @return $this
*/
public function cmsPromUrlGenerate()
public function cmsPromUrlGenerate(): self
{
$this->type = 'pdd.ddk.cms.prom.url.generate';
return $this;
......@@ -426,7 +414,7 @@ class JinBaoService extends Service
* https://open.pinduoduo.com/application/document/api?id=pdd.ddk.live.detail
* @return $this
*/
public function liveDetail()
public function liveDetail(): self
{
$this->type = 'pdd.ddk.live.detail';
return $this;
......@@ -437,7 +425,7 @@ class JinBaoService extends Service
* https://open.pinduoduo.com/application/document/api?id=pdd.ddk.live.list
* @return $this
*/
public function liveList()
public function liveList(): self
{
$this->type = 'pdd.ddk.live.list';
return $this;
......@@ -448,7 +436,7 @@ class JinBaoService extends Service
* https://open.pinduoduo.com/application/document/api?id=pdd.ddk.live.url.gen
* @return $this
*/
public function liveUrlGen()
public function liveUrlGen(): self
{
$this->type = 'pdd.ddk.live.url.gen';
return $this;
......@@ -459,7 +447,7 @@ class JinBaoService extends Service
* https://open.pinduoduo.com/application/document/api?id=pdd.ddk.lottery.url.gen
* @return $this
*/
public function lotteryUrlGen()
public function lotteryUrlGen(): self
{
$this->type = 'pdd.ddk.lottery.url.gen';
return $this;
......@@ -470,7 +458,7 @@ class JinBaoService extends Service
* https://open.pinduoduo.com/application/document/api?id=pdd.ddk.member.authority.query
* @return $this
*/
public function memberAuthorityQuery()
public function memberAuthorityQuery(): self
{
$this->type = 'pdd.ddk.member.authority.query';
return $this;
......@@ -525,7 +513,7 @@ class JinBaoService extends Service
* @param $object
* @return array
*/
private function object2array(&$object)
private function object2array(&$object): array
{
if (is_object($object)) {
$arr = (array)($object);
......@@ -545,7 +533,7 @@ class JinBaoService extends Service
* @return string
* @throws DtaException
*/
private function createSign()
private function createSign(): string
{
if (empty($this->client_secret)) {
$this->getConfig();
......@@ -556,7 +544,7 @@ class JinBaoService extends Service
$sign = $this->client_secret;
ksort($this->param);
foreach ($this->param as $key => $val) {
if ($key != '' && $val != '') {
if ($key !== '' && $val !== '') {
$sign .= $key . $val;
}
}
......@@ -569,11 +557,11 @@ class JinBaoService extends Service
* 组参
* @return string
*/
private function createStrParam()
private function createStrParam(): string
{
$strParam = '';
foreach ($this->param as $key => $val) {
if ($key != '' && $val != '' && !is_array($val)) {
if ($key !== '' && $val !== '' && !is_array($val)) {
$strParam .= $key . '=' . urlencode($val) . '&';
}
}
......@@ -584,7 +572,7 @@ class JinBaoService extends Service
* 获取频道ID
* @return array[]
*/
public function getChannelTypeList()
public function getChannelTypeList(): array
{
return [
[
......@@ -636,7 +624,7 @@ class JinBaoService extends Service
* 获取频道来源ID
* @return array[]
*/
public function getResourceTypeList()
public function getResourceTypeList(): array
{
return [
[
......
......@@ -32,21 +32,36 @@ use Qiniu\Storage\UploadManager;
*/
class KodoService extends Service
{
/**
* @var
*/
private $accessKey, $secretKey, $bucket;
public function accessKey(string $accessKey)
/**
* @param string $accessKey
* @return $this
*/
public function accessKey(string $accessKey): self
{
$this->accessKey = $accessKey;
return $this;
}
public function secretKey(string $secretKey)
/**
* @param string $secretKey
* @return $this
*/
public function secretKey(string $secretKey): self
{
$this->secretKey = $secretKey;
return $this;
}
public function bucket(string $bucket)
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
......@@ -56,7 +71,7 @@ class KodoService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->accessKey = config('dtapp.qiniu.kodo.access_key');
$this->secretKey = config('dtapp.qiniu.kodo.secret_key');
......@@ -71,7 +86,7 @@ class KodoService extends Service
* @return bool
* @throws Exception
*/
public function upload(string $object, string $filePath)
public function upload(string $object, string $filePath): bool
{
if (empty($this->accessKey) || empty($this->secretKey) || empty($this->bucket)) {
$this->getConfig();
......
......@@ -39,22 +39,16 @@ class TbkService extends Service
private $sandbox = false;
/**
* TOP分配给应用的AppKey
* TOP分配给应用的
* @var string
*/
private $app_key = "";
/**
* TOP分配给应用的AppSecret
* @var string
*/
private $app_secret = "";
private $app_key, $app_secret = "";
/**
* API接口名称
* @var string
*/
private $method = '', $response = '';
private $method = '';
/**
* 签名的摘要算法
......@@ -90,7 +84,7 @@ class TbkService extends Service
* 是否为沙箱
* @return $this
*/
public function sandbox()
public function sandbox(): self
{
$this->sandbox = true;
return $this;
......@@ -101,7 +95,7 @@ class TbkService extends Service
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey)
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
......@@ -112,7 +106,7 @@ class TbkService extends Service
* @param string $appSecret
* @return $this
*/
public function appSecret(string $appSecret)
public function appSecret(string $appSecret): self
{
$this->app_secret = $appSecret;
return $this;
......@@ -123,7 +117,7 @@ class TbkService extends Service
* @param string $signMethod
* @return $this
*/
public function signMethod(string $signMethod)
public function signMethod(string $signMethod): self
{
$this->sign_method = $signMethod;
return $this;
......@@ -134,7 +128,7 @@ class TbkService extends Service
* @param array $param
* @return $this
*/
public function param(array $param)
public function param(array $param): self
{
$this->param = $param;
return $this;
......@@ -144,7 +138,7 @@ class TbkService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->app_key = config('dtapp.taobao.tbk.app_key');
$this->app_secret = config('dtapp.taobao.tbk.app_secret');
......@@ -156,7 +150,7 @@ class TbkService extends Service
* https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.263c669aWmp4ds&source=search&docId=43328&docType=2
* @return $this
*/
public function orderDetailsGet()
public function orderDetailsGet(): self
{
$this->method = 'taobao.tbk.order.details.get';
return $this;
......@@ -165,9 +159,9 @@ class TbkService extends Service
/**
* 订单查询 - 淘宝客-推广者-维权退款订单查询
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=40173&docType=2
* @return array|mixed
* @return $this
*/
public function relationRefund()
public function relationRefund(): self
{
$this->method = 'taobao.tbk.relation.refund';
return $this;
......@@ -177,9 +171,9 @@ class TbkService extends Service
/**
* 处罚订单 - 淘宝客-推广者-处罚订单查询
* https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.120a669amFgNIC&source=search&docId=40121&docType=2
* @return array|mixed
* @return $this
*/
public function dgPunishOrderGet()
public function dgPunishOrderGet(): self
{
$this->method = 'taobao.tbk.dg.punish.order.get';
return $this;
......@@ -188,9 +182,9 @@ class TbkService extends Service
/**
* 拉新订单&效果 - 淘宝客-推广者-新用户订单明细查询
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=33892&docType=2
* @return array|mixed
* @return $this
*/
public function DgNewUserOrderGet()
public function DgNewUserOrderGet(): self
{
$this->method = 'taobao.tbk.dg.newuser.order.get';
return $this;
......@@ -199,9 +193,9 @@ class TbkService extends Service
/**
* 拉新订单&效果 - 淘宝客-推广者-拉新活动对应数据查询
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=36836&docType=2
* @return array|mixed
* @return $this
*/
public function dgNewUserOrderSum()
public function dgNewUserOrderSum(): self
{
$this->method = 'taobao.tbk.dg.newuser.order.sum';
return $this;
......@@ -210,9 +204,9 @@ class TbkService extends Service
/**
* 超级红包发放个数 - 淘宝客-推广者-查询超级红包发放个数
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=47593&docType=2
* @return array|mixed
* @return $this
*/
public function dgVegasSendReport()
public function dgVegasSendReport(): self
{
$this->method = 'taobao.tbk.dg.vegas.send.report';
return $this;
......@@ -221,9 +215,9 @@ class TbkService extends Service
/**
* 活动转链(更新版) - 淘宝客-推广者-官方活动信息获取
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=48340&docType=2
* @return array|mixed
* @return $this
*/
public function activityInfoGet()
public function activityInfoGet(): self
{
$this->method = 'taobao.tbk.activity.info.get';
return $this;
......@@ -232,9 +226,9 @@ class TbkService extends Service
/**
* 活动转链 - 淘宝客-推广者-官方活动转链
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=41918&docType=2
* @return array|mixed
* @return $this
*/
public function activityLinkGet()
public function activityLinkGet(): self
{
$this->method = 'taobao.tbk.activitylink.get';
return $this;
......@@ -243,10 +237,10 @@ class TbkService extends Service
/**
* 淘口令 - 淘宝客-公用-淘口令生成
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=31127&docType=2
* @return array|mixed
* @return $this
* @throws DtaException
*/
public function tpWdCreate()
public function tpWdCreate(): self
{
if (isset($this->param['text']) && strlen($this->param['text']) < 5) {
throw new DtaException('请检查text参数长度');
......@@ -258,9 +252,9 @@ class TbkService extends Service
/**
* 长短链 - 淘宝客-公用-长链转短链
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=27832&docType=2
* @return array|mixed
* @return $this
*/
public function spreadGet()
public function spreadGet(): self
{
$this->method = 'taobao.tbk.spread.get';
return $this;
......@@ -269,9 +263,9 @@ class TbkService extends Service
/**
* 聚划算商品搜索接口
* https://open.taobao.com/api.htm?docId=28762&docType=2&scopeId=16517
* @return array|mixed
* @return $this
*/
public function itemsSearch()
public function itemsSearch(): self
{
$this->method = 'taobao.ju.items.search';
return $this;
......@@ -280,9 +274,9 @@ class TbkService extends Service
/**
* 淘抢购api
* https://open.taobao.com/api.htm?docId=27543&docType=2&scopeId=16517
* @return array|mixed
* @return $this
*/
public function juTqgGet()
public function juTqgGet(): self
{
if (!isset($this->param['fields'])) {
$this->param['fields'] = "click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time";
......@@ -294,9 +288,9 @@ class TbkService extends Service
/**
* 淘礼金 - 淘宝客-推广者-淘礼金创建
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=40173&docType=2
* @return array|mixed
* @return $this
*/
public function dgVegasTljCreate()
public function dgVegasTljCreate(): self
{
$this->method = 'taobao.tbk.dg.vegas.tlj.create';
return $this;
......@@ -305,9 +299,9 @@ class TbkService extends Service
/**
* 淘礼金 - 淘宝客-推广者-淘礼金发放及使用报表
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=43317&docType=2
* @return array|mixed
* @return $this
*/
public function dgVegasTljInstanceReport()
public function dgVegasTljInstanceReport(): self
{
$this->method = 'taobao.tbk.dg.vegas.tlj.instance.report';
return $this;
......@@ -316,9 +310,9 @@ class TbkService extends Service
/**
* 私域用户管理 - 淘宝客-公用-私域用户邀请码生成
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=38046&docType=2
* @return array|mixed
* @return $this
*/
public function scInvIteCodeGet()
public function scInvIteCodeGet(): self
{
$this->method = 'taobao.tbk.sc.invitecode.get';
return $this;
......@@ -327,9 +321,9 @@ class TbkService extends Service
/**
* 私域用户管理 - 淘宝客-公用-私域用户备案信息查询
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=37989&docType=2
* @return array|mixed
* @return $this
*/
public function scPublisherInfoGet()
public function scPublisherInfoGet(): self
{
$this->method = 'taobao.tbk.sc.publisher.info.get';
return $this;
......@@ -338,9 +332,9 @@ class TbkService extends Service
/**
* 私域用户管理 - 淘宝客-公用-私域用户备案
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=37988&docType=2
* @return array|mixed
* @return $this
*/
public function scPublisherInfoSave()
public function scPublisherInfoSave(): self
{
$this->method = 'taobao.tbk.sc.publisher.info.save';
return $this;
......@@ -350,9 +344,9 @@ class TbkService extends Service
* 商品详情&券详情查询 - 淘宝客-公用-淘宝客商品详情查询(简版)
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=24518&docType=2
* https://open.alimama.com/#!/function?id=25
* @return array|mixed
* @return $this
*/
public function itemInfoGet()
public function itemInfoGet(): self
{
$this->method = 'taobao.tbk.item.info.get';
return $this;
......@@ -362,9 +356,9 @@ class TbkService extends Service
* 商品详情&券详情查询 - 淘宝客-公用-阿里妈妈推广券详情查询
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=31106&docType=2
* https://open.alimama.com/#!/function?id=25
* @return array|mixed
* @return $this
*/
public function couponGet()
public function couponGet(): self
{
$this->method = 'taobao.tbk.coupon.get';
return $this;
......@@ -374,9 +368,9 @@ class TbkService extends Service
* 商品/店铺搜索 - 淘宝客-推广者-物料搜索
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=35896&docType=2
* https://open.alimama.com/#!/function?id=27
* @return array|mixed
* @return $this
*/
public function dgMaterialOptional()
public function dgMaterialOptional(): self
{
$this->method = 'taobao.tbk.dg.material.optional';
return $this;
......@@ -386,9 +380,9 @@ class TbkService extends Service
* 商品/店铺搜索 - 淘宝客-推广者-店铺搜索
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=24521&docType=2
* https://open.alimama.com/#!/function?id=27
* @return array|mixed
* @return $this
*/
public function shopGet()
public function shopGet(): self
{
if (!isset($this->param['fields'])) {
$this->param['fields'] = "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url";
......@@ -402,9 +396,9 @@ class TbkService extends Service
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=33947&docType=2
* http://wsd.591hufu.com/taokelianmeng/424.html
* https://open.alimama.com/#!/function?id=28
* @return array|mixed
* @return $this
*/
public function dgOpTiUsMaterial()
public function dgOpTiUsMaterial(): self
{
$this->method = 'taobao.tbk.dg.optimus.material';
return $this;
......@@ -414,9 +408,9 @@ class TbkService extends Service
* 图文内容 - 淘宝客-推广者-图文内容输出
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=31137&docType=2
* https://open.alimama.com/#!/function?id=30
* @return array|mixed
* @return $this
*/
public function contentGet()
public function contentGet(): self
{
$this->method = 'taobao.tbk.content.get';
return $this;
......@@ -426,9 +420,9 @@ class TbkService extends Service
* 图文内容 - 淘宝客-推广者-图文内容效果数据
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=37130&docType=2
* https://open.alimama.com/#!/function?id=30
* @return array|mixed
* @return $this
*/
public function contentEffectGet()
public function contentEffectGet(): self
{
$this->method = 'taobao.tbk.content.effect.get';
return $this;
......@@ -438,9 +432,9 @@ class TbkService extends Service
/**
* 图文内容 - 淘宝客-推广者-商品出词
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=37538&docType=2
* @return array|mixed
* @return $this
*/
public function itemWordGet()
public function itemWordGet(): self
{
$this->method = 'taobao.tbk.item.word.get';
return $this;
......@@ -449,9 +443,9 @@ class TbkService extends Service
/**
* 淘宝客-推广者-商品链接转换
* https://open.taobao.com/api.htm?docId=24516&docType=2&scopeId=11653
* @return array|mixed
* @return $this
*/
public function itemConvert()
public function itemConvert(): self
{
if (!isset($this->param['fields'])) {
$this->param['fields'] = "num_iid,click_url";
......@@ -463,9 +457,9 @@ class TbkService extends Service
/**
* 淘宝客-公用-链接解析出商品id
* https://open.taobao.com/api.htm?docId=28156&docType=2
* @return array|mixed
* @return $this
*/
public function itemClickExtract()
public function itemClickExtract(): self
{
$this->method = 'taobao.tbk.item.click.extract';
return $this;
......@@ -474,9 +468,9 @@ class TbkService extends Service
/**
* 淘宝客-公用-商品关联推荐
* https://open.taobao.com/api.htm?docId=24517&docType=2
* @return array|mixed
* @return $this
*/
public function itemRecommendGet()
public function itemRecommendGet(): self
{
$this->method = 'taobao.tbk.item.recommend.get';
return $this;
......@@ -485,9 +479,9 @@ class TbkService extends Service
/**
* 淘宝客-公用-店铺关联推荐
* https://open.taobao.com/api.htm?docId=24522&docType=2
* @return array|mixed
* @return $this
*/
public function shopRecommendGet()
public function shopRecommendGet(): self
{
$this->method = 'taobao.tbk.shop.recommend.get';
return $this;
......@@ -496,9 +490,9 @@ class TbkService extends Service
/**
* 淘宝客-推广者-选品库宝贝信息
* https://open.taobao.com/api.htm?docId=26619&docType=2
* @return array|mixed
* @return $this
*/
public function uaTmFavoritesItemGet()
public function uaTmFavoritesItemGet(): self
{
$this->method = 'taobao.tbk.uatm.favorites.item.get';
return $this;
......@@ -507,9 +501,9 @@ class TbkService extends Service
/**
* 淘宝客-推广者-选品库宝贝列表
* https://open.taobao.com/api.htm?docId=26620&docType=2
* @return array|mixed
* @return $this
*/
public function uaTmFavoritesGet()
public function uaTmFavoritesGet(): self
{
$this->method = 'taobao.tbk.uatm.favorites.get';
return $this;
......@@ -518,9 +512,9 @@ class TbkService extends Service
/**
* 淘宝客-服务商-官方活动转链
* https://open.taobao.com/api.htm?docId=41921&docType=2
* @return array|mixed
* @return $this
*/
public function scActivityLinkToolGet()
public function scActivityLinkToolGet(): self
{
$this->method = 'taobao.tbk.sc.activitylink.toolget';
return $this;
......@@ -563,25 +557,17 @@ class TbkService extends Service
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
return json_decode($this->output, true);
} else {
// 正常
$response = substr(Strings::replace('.', '_', $this->method), 7) . "_response";
if (is_array($this->output)) {
if (isset($this->output["$response"])) {
return $this->output["$response"];
}
return $this->output;
};
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
if (isset($this->output["$response"])) {
return $this->output["$response"];
} else {
return $this->output;
}
}
// 正常
if (is_array($this->output)) {
return $this->output;
};
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
return $this->output;
}
/**
......@@ -604,7 +590,7 @@ class TbkService extends Service
* 网络请求
* @throws DtaException
*/
private function http()
private function http(): void
{
//生成签名
$sign = $this->createSign();
......@@ -627,7 +613,7 @@ class TbkService extends Service
* @return string
* @throws DtaException
*/
private function createSign()
private function createSign(): string
{
if (empty($this->app_secret)) {
$this->getConfig();
......@@ -638,7 +624,7 @@ class TbkService extends Service
$sign = $this->app_secret;
ksort($this->param);
foreach ($this->param as $key => $val) {
if ($key != '' && $val != '') {
if ($key !== '' && $val !== '') {
$sign .= $key . $val;
}
}
......@@ -651,11 +637,11 @@ class TbkService extends Service
* 组参
* @return string
*/
private function createStrParam()
private function createStrParam(): string
{
$strParam = '';
foreach ($this->param as $key => $val) {
if ($key != '' && $val != '') {
if ($key !== '' && $val !== '') {
$strParam .= $key . '=' . urlencode($val) . '&';
}
}
......@@ -666,7 +652,7 @@ class TbkService extends Service
* 获取活动物料
* @return array[]
*/
public function getActivityMaterialIdList()
public function getActivityMaterialIdList(): array
{
return [
[
......@@ -737,7 +723,7 @@ class TbkService extends Service
* https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a
* @return array
*/
public function getMaterialIdList()
public function getMaterialIdList(): array
{
return [
[
......
......@@ -31,27 +31,46 @@ use Qcloud\Cos\Client;
*/
class CosService extends Service
{
/**
* @var
*/
private $secretId, $secretKey, $region, $bucket;
public function secretId(string $secretId)
/**
* @param string $secretId
* @return $this
*/
public function secretId(string $secretId): self
{
$this->secretId = $secretId;
return $this;
}
public function secretKey(string $secretKey)
/**
* @param string $secretKey
* @return $this
*/
public function secretKey(string $secretKey): self
{
$this->secretKey = $secretKey;
return $this;
}
public function region(string $region)
/**
* @param string $region
* @return $this
*/
public function region(string $region): self
{
$this->region = $region;
return $this;
}
public function bucket(string $bucket)
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
......@@ -61,7 +80,7 @@ class CosService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->secretId = config('dtapp.tencent.cos.secret_id');
$this->secretKey = config('dtapp.tencent.cos.secret_key');
......@@ -77,31 +96,28 @@ class CosService extends Service
* @return bool
* @throws Exception
*/
public function upload(string $object, string $filePath)
public function upload(string $object, string $filePath): bool
{
if (empty($this->secretId) || empty($this->secretKey) || empty($this->region)) {
$this->getConfig();
}
$cosClient = new Client(
array(
'region' => $this->region,
'schema' => 'http', //协议头部,默认为http
'credentials' => array(
'secretId' => $this->secretId,
'secretKey' => $this->secretKey
)
)
);
$cosClient = new Client([
'region' => $this->region,
'schema' => 'http', //协议头部,默认为http
'credentials' => [
'secretId' => $this->secretId,
'secretKey' => $this->secretKey
]
]);
$key = $object;
$file = fopen($filePath, "rb");
if ($file && empty($this->bucket)) {
$this->getConfig();
$result = $cosClient->putObject(
array(
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => $file)
);
$cosClient->putObject([
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => $file
]);
}
return config('dtapp.tencent.cos.url', '') . $object;
}
......
......@@ -32,20 +32,35 @@ use Upyun\Upyun;
*/
class UssService extends Service
{
/**
* @var
*/
private $serviceName, $operatorName, $operatorPassword;
/**
* @param string $serviceName
* @return $this
*/
public function serviceName(string $serviceName)
{
$this->serviceName = $serviceName;
return $this;
}
/**
* @param string $operatorName
* @return $this
*/
public function operatorName(string $operatorName)
{
$this->operatorName = $operatorName;
return $this;
}
/**
* @param string $operatorPassword
* @return $this
*/
public function operatorPassword(string $operatorPassword)
{
$this->operatorPassword = $operatorPassword;
......@@ -56,7 +71,7 @@ class UssService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->serviceName = config('dtapp.upyun.uss.service_name');
$this->operatorName = config('dtapp.upyun.uss.operator_name');
......@@ -71,7 +86,7 @@ class UssService extends Service
* @return bool
* @throws Exception
*/
public function upload(string $object, string $filePath)
public function upload(string $object, string $filePath): bool
{
if (empty($this->serviceName) || empty($this->operatorName) || empty($this->operatorPassword)) {
$this->getConfig();
......
......@@ -31,9 +31,13 @@ use think\db\exception\DbException;
*/
class MiniService extends Service
{
private $api_url = "https://api.weixin.qq.com/";
/**
* @var
*/
private $app_id, $app_secret;
/**
* @var string
*/
private $grant_type = "client_credential";
/**
......@@ -67,7 +71,7 @@ class MiniService extends Service
* @param string $cache
* @return $this
*/
public function cache(string $cache)
public function cache(string $cache): self
{
$this->cache = $cache;
return $this;
......@@ -77,7 +81,7 @@ class MiniService extends Service
* 获取配置信息
* @return $this
*/
private function getConfig()
private function getConfig(): self
{
$this->cache = config('dtapp.wechat.mini.cache');
$this->app_id = config('dtapp.wechat.mini.app_id');
......@@ -97,7 +101,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxa/getpaidunionid?access_token={$accessToken['access_token']}&openid={$openid}";
$url = "https://api.weixin.qq.com/wxa/getpaidunionid?access_token={$accessToken['access_token']}&openid={$openid}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -115,7 +119,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/wxaapp/createwxaqrcode?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -135,7 +139,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxa/getwxacode?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -155,7 +159,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxa/getwxacodeunlimit?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -175,7 +179,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxaapi/newtmpl/addtemplate?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -194,7 +198,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxaapi/newtmpl/deltemplate?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token={$accessToken['access_token']}";
$data = [
'priTmplId' => $priTmplId
];
......@@ -215,7 +219,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxaapi/newtmpl/getcategory?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -233,7 +237,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxaapi/newtmpl/getpubtemplatekeywords?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token={$accessToken['access_token']}";
$data = [
'tid' => $tid
];
......@@ -255,7 +259,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxaapi/newtmpl/getpubtemplatetitles?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -273,7 +277,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}wxaapi/newtmpl/gettemplate?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -291,7 +295,7 @@ class MiniService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/message/subscribe/send?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -318,7 +322,7 @@ class MiniService extends Service
throw new DtaException('请检查app_secret参数');
}
$this->grant_type = "authorization_code";
$url = "{$this->api_url}sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code={$js_code}&grant_type={$this->grant_type}";
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code={$js_code}&grant_type={$this->grant_type}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -407,7 +411,7 @@ class MiniService extends Service
throw new DtaException('请检查app_secret参数');
}
$this->grant_type = "client_credential";
if ($this->cache == "file") {
if ($this->cache === "file") {
// 文件名
$file = "{$this->app->getRootPath()}runtime/{$this->app_id}_access_token.json";
// 获取数据
......@@ -421,28 +425,30 @@ class MiniService extends Service
}
if (empty($accessToken['expires_time'])) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
$accessToken = $accessToken_res;
} else if (!isset($accessToken['access_token'])) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
$accessToken = $accessToken_res;
} else if ($accessToken['expires_time'] <= time()) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
$accessToken = $accessToken_res;
}
return $accessToken;
} else if ($this->cache == "mysql") {
}
if ($this->cache === "mysql") {
$access_token = [];
// 文件名
$file = "{$this->app_id}_access_token";
......@@ -452,14 +458,14 @@ class MiniService extends Service
$access_token['access_token'] = $cache_mysql_value;
} else {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
dtacache($file, $accessToken_res['access_token'], 6000);
$access_token['access_token'] = $accessToken_res['access_token'];
}
return $access_token;
} else {
throw new DtaException("驱动方式错误");
}
throw new DtaException("驱动方式错误");
}
}
......@@ -35,15 +35,18 @@ class QyService extends Service
* @var string
*/
private $msgType = 'text';
/**
* @var
*/
private $key;
private $url = 'https://qyapi.weixin.qq.com/';
/**
* 配置Key
* @param string $str
* @return $this
*/
public function key(string $str)
public function key(string $str): self
{
$this->key = $str;
return $this;
......@@ -55,7 +58,7 @@ class QyService extends Service
* @return bool
* @throws DtaException
*/
public function text(string $content = '')
public function text(string $content = ''): bool
{
$this->msgType = 'text';
return $this->sendMsg([
......@@ -87,7 +90,7 @@ class QyService extends Service
* @return bool
* @throws DtaException
*/
private function sendMsg(array $data)
private function sendMsg(array $data): bool
{
if (empty($this->key)) {
throw new DtaException("请检查KEY");
......@@ -96,12 +99,9 @@ class QyService extends Service
$data['msgtype'] = $this->msgType;
}
$result = HttpService::instance()
->url("{$this->url}cgi-bin/webhook/send?key=" . $this->key)
->url("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" . $this->key)
->data($data)
->toArray();
if ($result['errcode'] == 0) {
return true;
}
return false;
return $result['errcode'] === 0;
}
}
......@@ -35,9 +35,6 @@ use think\db\exception\DbException;
*/
class WebAppService extends Service
{
private $open_url = "https://open.weixin.qq.com/";
private $api_url = "https://api.weixin.qq.com/";
/**
* 公众号的唯一标识
* @var
......@@ -61,8 +58,20 @@ class WebAppService extends Service
* @var string
*/
private $response_type = 'code';
/**
* @var string
*/
private $scope = "snsapi_base";
/**
* @var string
*/
private $state = "";
/**
* @var string
*/
private $grant_type = "authorization_code";
/**
......@@ -214,7 +223,7 @@ class WebAppService extends Service
'scope' => $this->scope,
'state' => $this->state
]);
return header("Location:{$this->open_url}connect/oauth2/authorize?$params#wechat_redirect");
return header("Location:https://open.weixin.qq.com/connect/oauth2/authorize?$params#wechat_redirect");
}
/**
......@@ -236,7 +245,7 @@ class WebAppService extends Service
throw new DtaException('请检查app_secret参数');
}
return HttpService::instance()
->url("{$this->api_url}sns/oauth2/access_token?appid={$this->app_id}&secret={$this->app_secret}&code={$code}&grant_type={$this->grant_type}")
->url("https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->app_id}&secret={$this->app_secret}&code={$code}&grant_type={$this->grant_type}")
->toArray($is);
}
......@@ -257,7 +266,7 @@ class WebAppService extends Service
}
$this->grant_type = "refresh_token";
return HttpService::instance()
->url("{$this->api_url}sns/oauth2/refresh_token?appid={$this->app_id}&grant_type={$this->grant_type}&refresh_token={$refreshToken}")
->url("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->app_id}&grant_type={$this->grant_type}&refresh_token={$refreshToken}")
->toArray($is);
}
......@@ -275,7 +284,7 @@ class WebAppService extends Service
$this->getConfig();
}
return HttpService::instance()
->url("{$this->api_url}sns/userinfo?access_token={$accessToken}&openid={$openid}&lang={$lang}")
->url("https://api.weixin.qq.com/sns/userinfo?access_token={$accessToken}&openid={$openid}&lang={$lang}")
->toArray($is);
}
......@@ -292,7 +301,7 @@ class WebAppService extends Service
$this->getConfig();
}
return HttpService::instance()
->url("{$this->api_url}sns/auth?access_token={$accessToken}&openid={$openid}")
->url("https://api.weixin.qq.com/sns/auth?access_token={$accessToken}&openid={$openid}")
->toArray($is);
}
......@@ -302,6 +311,7 @@ class WebAppService extends Service
* @return array
* @throws DbException
* @throws DtaException
* @throws \Exception
*/
public function share($url = '')
{
......@@ -317,7 +327,7 @@ class WebAppService extends Service
throw new DtaException("获取access_token错误," . $accessToken['errmsg']);
}
$res = HttpService::instance()
->url("{$this->api_url}cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi")
->url("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi")
->toArray();
if (!empty($res['errcode'])) {
// 获取数据
......@@ -326,7 +336,7 @@ class WebAppService extends Service
throw new DtaException("获取access_token错误," . $accessToken['errmsg']);
}
$res = HttpService::instance()
->url("{$this->api_url}cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi")
->url("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$accessToken['access_token']}&type=jsapi")
->toArray();
if (!empty($res['errcode'])) {
throw new DtaException('accessToken已过期');
......@@ -358,7 +368,7 @@ class WebAppService extends Service
* @return string
* @throws \Exception
*/
private function createNonceStr($length = 16)
private function createNonceStr($length = 16): string
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
......@@ -380,7 +390,7 @@ class WebAppService extends Service
// 获取数据
$accessToken = $this->getAccessToken();
return HttpService::instance()
->url("{$this->api_url}cgi-bin/qrcode/create?access_token={$accessToken['access_token']}")
->url("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$accessToken['access_token']}")
->data($data)
->post()
->toArray();
......@@ -397,7 +407,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/message/template/send?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -417,7 +427,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/template/api_set_industry?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data($data)
......@@ -435,7 +445,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/shorturl?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->data([
......@@ -457,7 +467,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}bizwifi/finishpage/set?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/bizwifi/finishpage/set?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->post()
......@@ -476,7 +486,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/menu/get?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -494,7 +504,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/menu/addconditional?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->post()
......@@ -514,7 +524,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/menu/delconditional?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->post()
......@@ -534,7 +544,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/menu/trymatch?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->post()
......@@ -553,7 +563,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/menu/delete?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -570,7 +580,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/get_current_selfmenu_info?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->toArray();
......@@ -588,7 +598,7 @@ class WebAppService extends Service
{
// 获取数据
$accessToken = $this->getAccessToken();
$url = "{$this->api_url}cgi-bin/menu/create?access_token={$accessToken['access_token']}";
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$accessToken['access_token']}";
return HttpService::instance()
->url($url)
->post()
......@@ -633,7 +643,7 @@ class WebAppService extends Service
if (empty($accessToken['expires_time'])) {
// 文件不存在
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
......@@ -641,14 +651,14 @@ class WebAppService extends Service
} else if (!isset($accessToken['access_token'])) {
// 内容不存在
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
$accessToken = $accessToken_res;
} else if ($accessToken['expires_time'] <= time()) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
......@@ -656,11 +666,11 @@ class WebAppService extends Service
}
if (isset($accessToken['access_token'])) {
$judge = HttpService::instance()
->url("{$this->api_url}cgi-bin/getcallbackip?access_token={$accessToken['access_token']}")
->url("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token={$accessToken['access_token']}")
->toArray();
if (!isset($judge['ip_list'])) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
......@@ -668,7 +678,7 @@ class WebAppService extends Service
}
} else {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
$accessToken_res['expires_time'] = time() + 6000;
file_put_contents($file, json_encode($accessToken_res, JSON_UNESCAPED_UNICODE));
......@@ -688,7 +698,7 @@ class WebAppService extends Service
} else {
// 获取远程Token
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
// 保存到数据库
dtacache($file, $accessToken_res['access_token'], 6000);
......@@ -696,11 +706,11 @@ class WebAppService extends Service
}
// 判断token是否可以使用
$judge = HttpService::instance()
->url("{$this->api_url}cgi-bin/getcallbackip?access_token={$access_token['access_token']}")
->url("https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token={$access_token['access_token']}")
->toArray();
if (!isset($judge['ip_list'])) {
$accessToken_res = HttpService::instance()
->url("{$this->api_url}cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->url("https://api.weixin.qq.com/cgi-bin/token?grant_type={$this->grant_type}&appid={$this->app_id}&secret={$this->app_secret}")
->toArray();
dtacache($file, $accessToken_res['access_token'], 6000);
$access_token['access_token'] = $accessToken_res['access_token'];
......@@ -750,7 +760,7 @@ class WebAppService extends Service
* @param bool $hmacsha256 是否使用 HMAC-SHA256算法,否则使用MD5
* @return string
*/
private function paySign(array $array, bool $hmacsha256 = true)
private function paySign(array $array, bool $hmacsha256 = true): string
{
// 排序
ksort($array);
......@@ -768,6 +778,10 @@ class WebAppService extends Service
return strtoupper($str);
}
/**
* @param $xml
* @return bool|string
*/
private function postXmlCurl($xml)
{
$ch = curl_init();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册