- 优化错误

v6
Chaim 4 years ago
parent 5a779d460d
commit 48e73532a2

@ -91,7 +91,7 @@ dump(AmApService::instance()
```php
use DtApp\ThinkLibrary\exception\DouYinException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\douyin\WatermarkService;
try {
@ -121,7 +121,7 @@ try {
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray());
// 返回Object数据方法
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toObject());
} catch (DouYinException $e) {
} catch (DtaException $e) {
// 错误提示
dump($e->getMessage());
}

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\cache;
use DtApp\ThinkLibrary\exception\CacheException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Times;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
@ -60,11 +60,11 @@ class Mysql
* 设置
* @param $cache_value
* @return int|string
* @throws CacheException
* @throws DtaException
*/
public function set($cache_value)
{
if (empty($this->cache_name)) throw new CacheException("名称未配置");
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$result = Db::table($this->table)
->insert([
'cache_name' => $this->cache_name,
@ -77,14 +77,14 @@ class Mysql
/**
* 获取
* @return string
* @throws CacheException
* @throws DbException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
*/
public function get()
{
if (empty($this->cache_name)) throw new CacheException("名称未配置");
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$cache = Db::table($this->table)
->where('cache_name', $this->cache_name)
->order('id desc')
@ -96,12 +96,12 @@ class Mysql
/**
* 删除
* @return int
* @throws CacheException
* @throws DbException
* @throws DtaException
*/
public function delete()
{
if (empty($this->cache_name)) throw new CacheException("名称未配置");
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->delete();
@ -112,12 +112,12 @@ class Mysql
* 更新
* @param $cache_value
* @return int
* @throws CacheException
* @throws DbException
* @throws DtaException
*/
public function update($cache_value)
{
if (empty($this->cache_name)) throw new CacheException("名称未配置");
if (empty($this->cache_name)) throw new DtaException("名称未配置");
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
@ -131,8 +131,10 @@ class Mysql
* 自增
* @param int $int
* @return int
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
*/
public function inc(int $int = 1)
{
@ -149,8 +151,10 @@ class Mysql
* 自减
* @param int $int
* @return int
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
*/
public function dec(int $int = 1)
{

@ -15,8 +15,7 @@
// +----------------------------------------------------------------------
use DtApp\ThinkLibrary\cache\Mysql;
use DtApp\ThinkLibrary\exception\CacheException;
use DtApp\ThinkLibrary\exception\IpException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\Ip\QqWryService;
use DtApp\ThinkLibrary\service\SystemService;
use think\db\exception\DataNotFoundException;
@ -29,7 +28,7 @@ if (!function_exists('get_ip_info')) {
* 获取请求IP信息
* @param string $ip
* @return mixed|null
* @throws IpException
* @throws DtaException
*/
function get_ip_info($ip = '')
{
@ -122,9 +121,9 @@ if (!function_exists('dtacache')) {
* @param array $value
* @param int $expire
* @return bool|int|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
*/
function dtacache($name = '', $value = [], $expire = 6000)

@ -0,0 +1,32 @@
<?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
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use Exception;
/**
* 错误处理
* Class DtaException
* @package DtApp\ThinkLibrary\exception
*/
class DtaException extends Exception
{
public function errorMessage()
{
return $this->getMessage();
}
}

@ -39,8 +39,7 @@ class ThinkException extends Handle
* @param Request $request
* @param Throwable $e
* @return Response
* @throws AliException
* @throws IpException|NoticeException
* @throws DtaException
*/
public function render($request, Throwable $e): Response
{
@ -59,9 +58,7 @@ class ThinkException extends Handle
/**
* @param $msg
* @return bool
* @throws AliException
* @throws IpException
* @throws NoticeException
* @throws DtaException
*/
private function show($msg)
{

@ -17,7 +17,7 @@ declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtAppException;
use DtApp\ThinkLibrary\exception\DtaException;
use ZipArchive;
/**
@ -32,11 +32,11 @@ class Files
* 删除文件
* @param string $name 路径
* @return bool
* @throws DtAppException
* @throws DtaException
*/
public function delete(string $name): bool
{
if (empty($name)) throw new DtAppException('请检查需要删除文件夹的名称');
if (empty($name)) throw new DtaException('请检查需要删除文件夹的名称');
if (file_exists($name)) if (unlink($name)) return true;
return false;
}
@ -45,11 +45,11 @@ class Files
* 删除文件夹
* @param string $name 路径
* @return bool
* @throws DtAppException
* @throws DtaException
*/
public function deletes(string $name): bool
{
if (empty($name)) throw new DtAppException('请检查需要删除文件夹的名称');
if (empty($name)) throw new DtaException('请检查需要删除文件夹的名称');
//先删除目录下的文件:
$dh = opendir($name);
while ($file = readdir($dh)) {
@ -71,11 +71,11 @@ class Files
* @param string $suffix_name 需要打包的后缀名,默认.png
* @param string $file_name 文件名,默认全部名
* @return bool
* @throws DtAppException
* @throws DtaException
*/
public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool
{
if (empty($name)) throw new DtAppException('请检查需要打包的路径名称');
if (empty($name)) throw new DtaException('请检查需要打包的路径名称');
try {
// 获取目录下所有某个结尾的文件列表
$list = glob($name . "{$file_name}.{$suffix_name}");

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtAppException;
use DtApp\ThinkLibrary\exception\DtaException;
/**
* XML管理类
@ -30,11 +30,11 @@ class Xmls
* 数组转换为xml
* @param array $values 数组
* @return string
* @throws DtAppException
* @throws DtaException
*/
public function toXml(array $values)
{
if (!is_array($values) || count($values) <= 0) throw new DtAppException('数组数据异常!');
if (!is_array($values) || count($values) <= 0) throw new DtaException('数组数据异常!');
$xml = "<xml>";
foreach ($values as $key => $val) {
if (is_array($val)) {
@ -53,11 +53,11 @@ class Xmls
* 将XML转为array
* @param string $xml
* @return mixed
* @throws DtAppException
* @throws DtaException
*/
public function toArray(string $xml)
{
if (!$xml) throw new DtAppException('xml数据异常');
if (!$xml) throw new DtaException('xml数据异常');
libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
}

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\exception\AliException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\exception\HttpException;
@ -53,7 +53,7 @@ class DingTalkService extends Service
* 发送文本消息
* @param string $content 消息内容
* @return bool 发送结果
* @throws AliException
* @throws DtaException
*/
public function text(string $content)
{
@ -69,11 +69,11 @@ class DingTalkService extends Service
* 组装发送消息
* @param array $data 消息内容数组
* @return bool 发送结果
* @throws AliException
* @throws DtaException
*/
private function sendMsg(array $data)
{
if (empty($this->access_token)) throw new AliException("请检查access_token");
if (empty($this->access_token)) throw new DtaException("请检查access_token");
if (empty($data['msgtype'])) $data['msgtype'] = $this->msg_type;
$result = HttpService::instance()
->url("{$this->oapi_url}robot/send?access_token=" . $this->access_token)

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\IpException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
@ -83,11 +83,11 @@ class MapService extends Service
* https://lbs.qq.com/webservice_v1/guide-ip.html
* @param string $output
* @return array|bool|mixed|string
* @throws IpException
* @throws DtaException
*/
public function qq(string $output = 'JSON')
{
if (empty($this->key)) throw new IpException('开发密钥不能为空');
if (empty($this->key)) throw new DtaException('开发密钥不能为空');
if (empty($this->ip)) $this->ip = get_ip();
$url = "https://apis.map.qq.com/ws/location/v1/ip?key={$this->key}&output={$output}";
if (!empty($this->ip)) $url = "https://apis.map.qq.com/ws/location/v1/ip?key={$this->key}&ip={$this->ip}&output={$output}";
@ -101,11 +101,11 @@ class MapService extends Service
* http://lbsyun.baidu.com/index.php?title=webapi/ip-api
* @param string $coor
* @return array|bool|mixed|string
* @throws IpException
* @throws DtaException
*/
public function baidu(string $coor = 'bd09ll')
{
if (empty($this->ak)) throw new IpException('开发者密钥不能为空');
if (empty($this->ak)) throw new DtaException('开发者密钥不能为空');
if (empty($this->ip)) $this->ip = get_ip();
$url = "https://api.map.baidu.com/location/ip?ak={$this->ak}&coor={$coor}";
if (!empty($this->ip)) $url = "https://api.map.baidu.com/location/ip?ak={$this->ak}&ip={$this->ip}&coor={$coor}";
@ -119,11 +119,11 @@ class MapService extends Service
* https://lbs.amap.com/api/webservice/guide/api/ipconfig
* @param string $output
* @return array|bool|mixed|string
* @throws IpException
* @throws DtaException
*/
public function amap(string $output = 'JSON')
{
if (empty($this->key)) throw new IpException('开发密钥不能为空');
if (empty($this->key)) throw new DtaException('开发密钥不能为空');
if (empty($this->ip)) $this->ip = get_ip();
$url = "https://restapi.amap.com/v3/ip?parameters&key={$this->key}&output={$output}";
if (!empty($this->ip)) $url = "https://restapi.amap.com/v3/ip?key={$this->key}&ip={$this->ip}&output={$output}";

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\IpException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
@ -194,7 +194,7 @@ class OnlineService extends Service
* 阿里云
* @param string $appcode
* @return bool|mixed|string
* @throws IpException
* @throws DtaException
*/
public function aliYun(string $appcode = '')
{
@ -202,7 +202,7 @@ class OnlineService extends Service
$host = "http://iploc.market.alicloudapi.com";
$path = "/v3/ip";
$method = "GET";
if (empty($appcode)) throw new IpException('请检查阿里-阿里云配置信息 appcode');
if (empty($appcode)) throw new DtaException('请检查阿里-阿里云配置信息 appcode');
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "ip={$this->ip}";

@ -16,9 +16,8 @@
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\IpException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use Exception;
use think\App;
/**
@ -89,7 +88,7 @@ class QqWryService extends Service
* 获取省信息
* @param string $ip
* @return mixed
* @throws IpException
* @throws DtaException
*/
public function getProvince(string $ip = '')
{
@ -100,7 +99,7 @@ class QqWryService extends Service
* 获取城市信息
* @param string $ip
* @return mixed
* @throws IpException
* @throws DtaException
*/
public function getCity(string $ip = '')
{
@ -111,7 +110,7 @@ class QqWryService extends Service
* 获取地区信息
* @param string $ip
* @return mixed
* @throws IpException
* @throws DtaException
*/
public function getArea(string $ip = '')
{
@ -122,7 +121,7 @@ class QqWryService extends Service
* 获取运营商信息
* @param string $ip
* @return mixed
* @throws IpException
* @throws DtaException
*/
public function getExtend(string $ip = '')
{
@ -133,7 +132,7 @@ class QqWryService extends Service
* 根据所给 IP 地址或域名返回所在地区信息
* @param string $ip
* @return mixed|null
* @throws IpException
* @throws DtaException
*/
public function getLocation(string $ip = '')
{
@ -144,7 +143,7 @@ class QqWryService extends Service
}
static $locationData = [];
if (!isset($locationData[$ip])) {
if (!$this->fp) throw new IpException('数据库文件不存在!'); // 如果数据文件没有被正确打开,则直接返回错误
if (!$this->fp) throw new DtaException('数据库文件不存在!'); // 如果数据文件没有被正确打开,则直接返回错误
$location['ip'] = $ip; // 将输入的域名转化为IP地址
$ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址
// 不合法的IP地址会被转化为255.255.255.255
@ -397,48 +396,36 @@ class QqWryService extends Service
$district['lng'] = '';
if (!empty($province_name)) {
try {
$json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true);
foreach ($json_province['rows'] as $key => $value) {
if ($value['name'] == $province_name) {
$province['name'] = $value['name'];
$province['adcode'] = $value['adcode'];
$province['lat'] = $value['lat'];
$province['lng'] = $value['lng'];
}
$json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true);
foreach ($json_province['rows'] as $key => $value) {
if ($value['name'] == $province_name) {
$province['name'] = $value['name'];
$province['adcode'] = $value['adcode'];
$province['lat'] = $value['lat'];
$province['lng'] = $value['lng'];
}
} catch (Exception $e) {
}
}
if (!empty($city_name)) {
try {
$json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true);
foreach ($json_city['rows'] as $key => $value) {
if ($value['name'] == $city_name) {
$city['name'] = $value['name'];
$city['adcode'] = $value['adcode'];
$city['lat'] = $value['lat'];
$city['lng'] = $value['lng'];
}
$json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true);
foreach ($json_city['rows'] as $key => $value) {
if ($value['name'] == $city_name) {
$city['name'] = $value['name'];
$city['adcode'] = $value['adcode'];
$city['lat'] = $value['lat'];
$city['lng'] = $value['lng'];
}
} catch (Exception $e) {
}
}
if (!empty($district_name)) {
try {
$json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true);
foreach ($json_district['rows'] as $key => $value) {
if ($value['name'] == $district_name) {
$district['name'] = $value['name'];
$district['adcode'] = $value['adcode'];
$district['lat'] = $value['lat'];
$district['lng'] = $value['lng'];
}
$json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true);
foreach ($json_district['rows'] as $key => $value) {
if ($value['name'] == $district_name) {
$district['name'] = $value['name'];
$district['adcode'] = $value['adcode'];
$district['lat'] = $value['lat'];
$district['lng'] = $value['lng'];
}
} catch (Exception $e) {
}
}
return [

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\amap;
use DtApp\ThinkLibrary\exception\AliException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
@ -56,12 +56,12 @@ class AmApService extends Service
* @param string $city
* @param string $extensions
* @return array|bool|mixed|string
* @throws AliException
* @throws DtaException
*/
public function weather($city = "110101", $extensions = "base")
{
if (empty($this->key)) $this->getConfig();
if (empty($this->key)) throw new AliException('请检查key参数');
if (empty($this->key)) throw new DtaException('请检查key参数');
$data = http_build_query([
"city" => $city,
"extensions" => $extensions,

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\baidu;
use DtApp\ThinkLibrary\exception\BaiduException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
@ -53,16 +53,16 @@ class LbsYunService extends Service
/**
* 国内天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather
* @param $district_id
* @param int $district_id
* @param string $coordtype
* @param string $location
* @return array|bool|mixed|string
* @throws BaiduException
* @throws DtaException
*/
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "")
{
if (empty($this->ak)) $this->getConfig();
if (empty($this->ak)) throw new BaiduException('请检查ak参数');
if (empty($this->ak)) throw new DtaException('请检查ak参数');
$data = http_build_query([
"district_id" => $district_id,
"coordtype" => $coordtype,
@ -84,12 +84,12 @@ class LbsYunService extends Service
* @param string $location
* @param string $language
* @return array|bool|mixed|string
* @throws BaiduException
* @throws DtaException
*/
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn")
{
if (empty($this->ak)) $this->getConfig();
if (empty($this->ak)) throw new BaiduException('请检查ak参数');
if (empty($this->ak)) throw new DtaException('请检查ak参数');
$data = http_build_query([
"district_id" => $district_id,
"coordtype" => $coordtype,

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\bt;
use DtApp\ThinkLibrary\exception\BtException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\BtService;
@ -328,7 +328,7 @@ class ApiService extends Service
/**
* 发起网络请求
* @return $this
* @throws BtException
* @throws DtaException
*/
private function getHttp()
{
@ -340,7 +340,7 @@ class ApiService extends Service
/**
* 返回Array
* @return array|mixed
* @throws BtException
* @throws DtaException
*/
public function toArray()
{
@ -376,12 +376,12 @@ class ApiService extends Service
* @param array $data 数据
* @param bool $is_json 是否返回Json格式
* @return bool|mixed|string
* @throws BtException
* @throws DtaException
*/
protected function HttpPostCookie(string $url, array $data = [], bool $is_json = true)
{
if (empty($this->panel)) $this->getConfig();
if (empty($this->panel)) throw new BtException('请检查panel参数');
if (empty($this->panel)) throw new DtaException('请检查panel参数');
//定义cookie保存位置
$file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/';
$cookie_file = $file . md5($this->panel) . '.cookie';
@ -391,7 +391,7 @@ class ApiService extends Service
fclose($fp);
}
if (empty($this->key)) $this->getConfig();
if (empty($this->key)) throw new BtException('请检查key参数');
if (empty($this->key)) throw new DtaException('请检查key参数');
return BtService::instance()
->panel($this->panel)
->key($this->key)

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\douyin;
use DtApp\ThinkLibrary\exception\DouYinException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Pregs;
use DtApp\ThinkLibrary\Service;
use stdClass;
@ -39,18 +39,18 @@ class WatermarkService extends Service
* 配置网址
* @param $str
* @return $this
* @throws DouYinException
* @throws DtaException
*/
public function url($str)
{
if (Pregs::isLink($str)) {
$url = $this->judgeUrl($str);
if (empty($url)) throw new DouYinException('配置网址内容不正确');
if (empty($url)) throw new DtaException('配置网址内容不正确');
$this->url = $url;
} else {
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $str, $match);
$url = $this->judgeUrl($match[0][0]);
if (empty($url)) throw new DouYinException('配置网址内容不正确');
if (empty($url)) throw new DtaException('配置网址内容不正确');
$this->url = $url;
}
$content = $this->getContents($this->url);
@ -239,14 +239,14 @@ class WatermarkService extends Service
* 正则匹配 mid
* @param $content
* @return mixed
* @throws DouYinException
* @throws DtaException
*/
private function getItemId($content)
{
preg_match('/"(?<=itemId:\s\")\d+"/', $content, $matches);
if (!isset($matches[0])) throw new DouYinException('视频不存在');
if (!isset($matches[0])) throw new DtaException('视频不存在');
preg_match("~\"(.*?)\"~", $matches[0], $matches2);
if (!isset($matches2[1])) throw new DouYinException('视频不存在');
if (!isset($matches2[1])) throw new DtaException('视频不存在');
return $matches2[1];
}
@ -254,15 +254,15 @@ class WatermarkService extends Service
* 正则匹配 dytk
* @param $content
* @return mixed
* @throws DouYinException
* @throws DtaException
*/
private function getDyTk($content)
{
preg_match("~dytk(.*?)}~", $content, $matches);
if (!isset($matches[1])) throw new DouYinException('视频不存在');
if (!isset($matches[1])) throw new DtaException('视频不存在');
$Dytk = $matches[1];
preg_match("~\"(.*?)\"~", $Dytk, $matches2);
if (!isset($matches2[1])) throw new DouYinException('视频不存在');
if (!isset($matches2[1])) throw new DtaException('视频不存在');
return $matches2[1];
}

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\jd;
use DtApp\ThinkLibrary\exception\JdException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Strings;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
@ -136,7 +136,7 @@ class UnionService extends Service
/**
* 网络请求
* @throws JdException
* @throws DtaException
*/
private function http()
{
@ -321,15 +321,15 @@ class UnionService extends Service
/**
* 返回数组数据
* @return array|mixed
* @throws JdException
* @throws DtaException
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) throw new HttpException(404, '请开启curl模块');
if (empty($this->app_key)) $this->getConfig();
if (empty($this->app_key)) throw new JdException('请检查app_key参数');
if (empty($this->method)) throw new JdException('请检查method参数');
if (empty($this->app_key)) throw new DtaException('请检查app_key参数');
if (empty($this->method)) throw new DtaException('请检查method参数');
$this->params['method'] = $this->method;
$this->params['app_key'] = $this->app_key;
$this->params['timestamp'] = date('Y-m-d H:i:s');
@ -353,12 +353,12 @@ class UnionService extends Service
/**
* 签名
* @return string
* @throws JdException
* @throws DtaException
*/
private function createSign()
{
if (empty($this->secret_key)) $this->getConfig();
if (empty($this->secret_key)) throw new JdException('请检查secret_key参数');
if (empty($this->secret_key)) throw new DtaException('请检查secret_key参数');
$sign = $this->secret_key;
ksort($this->params);

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\pinduoduo;
use DtApp\ThinkLibrary\exception\PinDouDouException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
@ -126,7 +126,8 @@ class JinBaoService extends Service
/**
* 网络请求
* @throws PinDouDouException
* @return JinBaoService
* @throws DtaException
*/
private function http()
{
@ -433,14 +434,14 @@ class JinBaoService extends Service
/**
* 返回数组数据
* @return array|mixed
* @throws PinDouDouException
* @throws DtaException
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) throw new HttpException(404, '请开启curl模块');
if (empty($this->client_id)) $this->getConfig();
if (empty($this->client_id)) throw new PinDouDouException('请检查client_id参数');
if (empty($this->client_id)) throw new DtaException('请检查client_id参数');
$this->param['type'] = $this->type;
$this->param['client_id'] = $this->client_id;
$this->param['timestamp'] = time();
@ -484,12 +485,12 @@ class JinBaoService extends Service
/**
* 签名
* @return string
* @throws PinDouDouException
* @throws DtaException
*/
private function createSign()
{
if (empty($this->client_secret)) $this->getConfig();
if (empty($this->client_secret)) throw new PinDouDouException('请检查client_secret参数');
if (empty($this->client_secret)) throw new DtaException('请检查client_secret参数');
$sign = $this->client_secret;
ksort($this->param);

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\taobao;
use DtApp\ThinkLibrary\exception\TaoBaoException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Strings;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
@ -241,11 +241,11 @@ class TbkService extends Service
* 淘口令 - 淘宝客-公用-淘口令生成
* https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=31127&docType=2
* @return array|mixed
* @throws TaoBaoException
* @throws DtaException
*/
public function tpWdCreate()
{
if (isset($this->param['text'])) if (strlen($this->param['text']) < 5) throw new TaoBaoException('text');
if (isset($this->param['text'])) if (strlen($this->param['text']) < 5) throw new DtaException('text');
$this->method = 'taobao.tbk.tpwd.create';
return $this;
}
@ -463,7 +463,7 @@ class TbkService extends Service
/**
* 返回Array
* @return array|mixed
* @throws TaoBaoException
* @throws DtaException
*/
public function toArray()
{
@ -471,8 +471,8 @@ class TbkService extends Service
if (!extension_loaded("curl")) throw new HttpException(404, '请开启curl模块');
$this->format = "json";
if (empty($this->app_key)) $this->getConfig();
if (empty($this->app_key)) throw new TaoBaoException('请检查app_key参数');
if (empty($this->method)) throw new TaoBaoException('请检查method参数');
if (empty($this->app_key)) throw new DtaException('请检查app_key参数');
if (empty($this->method)) throw new DtaException('请检查method参数');
$this->param['app_key'] = $this->app_key;
$this->param['method'] = $this->method;
$this->param['format'] = $this->format;
@ -502,7 +502,7 @@ class TbkService extends Service
/**
* 返回Xml
* @return mixed
* @throws TaoBaoException
* @throws DtaException
*/
public function toXml()
{
@ -515,7 +515,7 @@ class TbkService extends Service
/**
* 网络请求
* @throws TaoBaoException
* @throws DtaException
*/
private function http()
{
@ -535,12 +535,12 @@ class TbkService extends Service
/**
* 签名
* @return string
* @throws TaoBaoException
* @throws DtaException
*/
private function createSign()
{
if (empty($this->app_secret)) $this->getConfig();
if (empty($this->app_secret)) throw new TaoBaoException('请检查app_secret参数');
if (empty($this->app_secret)) throw new DtaException('请检查app_secret参数');
$sign = $this->app_secret;
ksort($this->param);

@ -16,8 +16,7 @@
namespace DtApp\ThinkLibrary\service\wechat;
use DtApp\ThinkLibrary\exception\CacheException;
use DtApp\ThinkLibrary\exception\WeChatException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\db\exception\DataNotFoundException;
@ -91,11 +90,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.getPaidUnionId.html
* @param string $openid
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getPaidUnionId(string $openid)
{
@ -112,11 +110,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function createWxaQrCode(array $data = [])
{
@ -135,11 +132,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.get.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getWxaCode(array $data = [])
{
@ -158,11 +154,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.getUnlimited.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getWxaCodeUnLimit(array $data = [])
{
@ -181,11 +176,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.addTemplate.html
* @param array $data
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function addTemplate(array $data = [])
{
@ -203,11 +197,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.deleteTemplate.html
* @param string $priTmplId 要删除的模板id
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function deleteTemplate(string $priTmplId)
{
@ -227,11 +220,10 @@ class MiniService extends Service
* 获取小程序账号的类目
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getCategory.html
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getCategory()
{
@ -248,11 +240,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getPubTemplateKeyWordsById.html
* @param string $tid 模板标题 id
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getPubTemplateKeyWordsById(string $tid)
{
@ -273,11 +264,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getPubTemplateTitleList.html
* @param array $data
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getPubTemplateTitleList(array $data = [])
{
@ -294,11 +284,10 @@ class MiniService extends Service
* 获取当前帐号下的个人模板列表
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getTemplateList()
{
@ -315,11 +304,10 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
* @param array $data
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function subscribeMessageSend(array $data = [])
{
@ -338,14 +326,14 @@ class MiniService extends Service
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
* @param string $js_code
* @return bool|mixed|string
* @throws WeChatException
* @throws DtaException
*/
public function code2Session(string $js_code)
{
if (empty($this->app_id)) $this->getConfig();
if (empty($this->app_secret)) $this->getConfig();
if (empty($this->app_id)) throw new WeChatException('请检查app_id参数');
if (empty($this->app_secret)) throw new WeChatException('请检查app_secret参数');
if (empty($this->app_id)) throw new DtaException('请检查app_id参数');
if (empty($this->app_secret)) 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}";
return HttpService::instance()
@ -359,7 +347,7 @@ class MiniService extends Service
* @param string $encrypted_data
* @param string $iv
* @return bool|mixed
* @throws WeChatException
* @throws DtaException
*/
public function userInfo(string $js_code, string $encrypted_data, string $iv)
{
@ -375,7 +363,7 @@ class MiniService extends Service
* @param string $encrypted_data
* @param string $iv
* @return mixed
* @throws WeChatException
* @throws DtaException
*/
public function userPhone(string $js_code, string $encrypted_data, string $iv)
{
@ -389,11 +377,10 @@ class MiniService extends Service
* 获取小程序全局唯一后台接口调用凭据access_token
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function accessToken()
{
@ -404,10 +391,9 @@ class MiniService extends Service
/**
* 获取access_token信息
* @return array|bool|mixed|string|string[]
* @throws CacheException
* @throws WeChatException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
*/
private function getAccessToken()
@ -415,9 +401,9 @@ class MiniService extends Service
if (empty($this->cache)) $this->getConfig();
if (empty($this->app_id)) $this->getConfig();
if (empty($this->app_secret)) $this->getConfig();
if (empty($this->cache)) throw new WeChatException('请检查cache参数');
if (empty($this->app_id)) throw new WeChatException('请检查app_id参数');
if (empty($this->app_secret)) throw new WeChatException('请检查app_secret参数');
if (empty($this->cache)) throw new DtaException('请检查cache参数');
if (empty($this->app_id)) throw new DtaException('请检查app_id参数');
if (empty($this->app_secret)) throw new DtaException('请检查app_secret参数');
$this->grant_type = "client_credential";
if ($this->cache == "file") {
// 文件名
@ -468,6 +454,6 @@ class MiniService extends Service
$access_token['access_token'] = $accessToken_res['access_token'];
}
return $access_token;
} else throw new WeChatException("驱动方式错误");
} else throw new DtaException("驱动方式错误");
}
}

@ -16,7 +16,7 @@
namespace DtApp\ThinkLibrary\service\wechat;
use DtApp\ThinkLibrary\exception\NoticeException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
@ -50,7 +50,7 @@ class QyService extends Service
* 发送文本消息
* @param string $content 消息内容
* @return bool
* @throws NoticeException
* @throws DtaException
*/
public function text(string $content = '')
{
@ -66,7 +66,7 @@ class QyService extends Service
* 发送markdown消息
* @param string $content 消息内容
* @return bool
* @throws NoticeException
* @throws DtaException
*/
public function markdown(string $content = '')
{
@ -82,11 +82,11 @@ class QyService extends Service
* 组装发送消息
* @param array $data 消息内容数组
* @return bool
* @throws NoticeException
* @throws DtaException
*/
private function sendMsg(array $data)
{
if (empty($this->key)) throw new NoticeException("请检查KEY");
if (empty($this->key)) throw new DtaException("请检查KEY");
if (empty($data['msgtype'])) $data['msgtype'] = $this->msgType;
$result = HttpService::instance()
->url("{$this->url}cgi-bin/webhook/send?key=" . $this->key)

@ -16,8 +16,7 @@
namespace DtApp\ThinkLibrary\service\wechat;
use DtApp\ThinkLibrary\exception\CacheException;
use DtApp\ThinkLibrary\exception\WeChatException;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Pregs;
use DtApp\ThinkLibrary\facade\Randoms;
use DtApp\ThinkLibrary\facade\Urls;
@ -141,11 +140,11 @@ class WebAppService extends Service
* 授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
* @param string $redirectUri
* @return $this
* @throws WeChatException
* @throws DtaException
*/
public function redirectUri(string $redirectUri)
{
if (empty(Pregs::isLink($redirectUri))) throw new WeChatException("请检查redirectUri是否正确");
if (empty(Pregs::isLink($redirectUri))) throw new DtaException("请检查redirectUri是否正确");
$this->redirect_uri = Urls::lenCode($redirectUri);
return $this;
}
@ -154,13 +153,13 @@ class WebAppService extends Service
* 应用授权作用域snsapi_base 不弹出授权页面直接跳转只能获取用户openidsnsapi_userinfo 弹出授权页面可通过openid拿到昵称、性别、所在地。并且 即使在未关注的情况下,只要用户授权,也能获取其信息
* @param string $scope
* @return $this
* @throws WeChatException
* @throws DtaException
*/
public function scope(string $scope)
{
if ($scope === "snsapi_base") $this->scope = $scope;
elseif ($scope === "snsapi_userinfo") $this->scope = $scope;
else throw new WeChatException("请检查scope参数");
else throw new DtaException("请检查scope参数");
return $this;
}
@ -189,11 +188,12 @@ class WebAppService extends Service
/**
* 网页授权
* https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#0
* @throws WeChatException
* @return void
* @throws DtaException
*/
public function oauth2()
{
if (strlen($this->state) > 128) throw new WeChatException("请检查state参数最多128字节");
if (strlen($this->state) > 128) throw new DtaException("请检查state参数最多128字节");
$params = Urls::toParams([
'appid' => $this->app_id,
'redirect_uri' => $this->redirect_uri,
@ -209,14 +209,14 @@ class WebAppService extends Service
* @param string $code
* @param bool $is
* @return array|bool|mixed|string
* @throws WeChatException
* @throws DtaException
*/
public function accessToken(string $code, bool $is = true)
{
if (empty($this->app_id)) $this->getConfig();
if (empty($this->app_secret)) $this->getConfig();
if (empty($this->app_id)) throw new WeChatException('请检查app_id参数');
if (empty($this->app_secret)) throw new WeChatException('请检查app_secret参数');
if (empty($this->app_id)) throw new DtaException('请检查app_id参数');
if (empty($this->app_secret)) 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}")
->toArray($is);
@ -227,12 +227,12 @@ class WebAppService extends Service
* @param string $refreshToken
* @param bool $is
* @return array|bool|mixed|string
* @throws WeChatException
* @throws DtaException
*/
public function refreshToken(string $refreshToken, bool $is = true)
{
if (empty($this->app_id)) $this->getConfig();
if (empty($this->app_id)) throw new WeChatException('请检查app_id参数');
if (empty($this->app_id)) throw new DtaException('请检查app_id参数');
$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}")
@ -271,30 +271,29 @@ class WebAppService extends Service
/**
* 分享
* @return array
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function share()
{
if (empty($this->app_id)) $this->getConfig();
if (empty($this->app_id)) throw new WeChatException('请检查app_id参数');
if (empty($this->app_id)) throw new DtaException('请检查app_id参数');
// 获取数据
$accessToken = $this->getAccessToken();
if (!isset($accessToken['access_token'])) throw new WeChatException("获取access_token错误" . $accessToken['errmsg']);
if (!isset($accessToken['access_token'])) 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")
->toArray();
if (!empty($res['errcode'])) {
// 获取数据
$accessToken = $this->getAccessToken();
if (!isset($accessToken['access_token'])) throw new WeChatException("获取access_token错误" . $accessToken['errmsg']);
if (!isset($accessToken['access_token'])) 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")
->toArray();
if (!empty($res['errcode'])) throw new WeChatException('accessToken已过期');
if (!empty($res['errcode'])) throw new DtaException('accessToken已过期');
}
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
@ -327,11 +326,10 @@ class WebAppService extends Service
* 生成二维码
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function qrCode(array $data)
{
@ -348,11 +346,10 @@ class WebAppService extends Service
* 发送模板消息
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function messageTemplateSend(array $data = [])
{
@ -371,11 +368,10 @@ class WebAppService extends Service
* @param string $access_token
* @param array $data
* @return bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function setIndustry(string $access_token, array $data = [])
{
@ -392,11 +388,10 @@ class WebAppService extends Service
* 将一条长链接转成短链接
* @param string $long_url
* @return bool
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function shortUrl(string $long_url)
{
@ -417,11 +412,10 @@ class WebAppService extends Service
* https://developers.weixin.qq.com/doc/offiaccount/WiFi_via_WeChat/WiFi_mini_programs.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function fiNihPageSet(array $data = [])
{
@ -439,11 +433,10 @@ class WebAppService extends Service
* 自定义菜单 获取自定义菜单配置
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Getting_Custom_Menu_Configurations.html
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function menuGet()
{
@ -460,11 +453,10 @@ class WebAppService extends Service
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Personalized_menu_interface.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function menuAddConditional(array $data = [])
{
@ -483,11 +475,10 @@ class WebAppService extends Service
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Personalized_menu_interface.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function menuDelConditional(array $data = [])
{
@ -506,11 +497,10 @@ class WebAppService extends Service
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Personalized_menu_interface.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function menuTryMatch(array $data = [])
{
@ -528,11 +518,10 @@ class WebAppService extends Service
* 自定义菜单 删除接口
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Deleting_Custom-Defined_Menu.html
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function menuDelete()
{
@ -548,11 +537,10 @@ class WebAppService extends Service
* 自定义菜单 查询接口
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function getCurrentSelfmenuInfo()
{
@ -569,11 +557,10 @@ class WebAppService extends Service
* https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html
* @param array $data
* @return array|bool|mixed|string
* @throws CacheException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
* @throws WeChatException
*/
public function menuCreate(array $data = [])
{
@ -590,10 +577,9 @@ class WebAppService extends Service
/**
* 获取access_token信息
* @return array|bool|mixed|string|string[]
* @throws CacheException
* @throws WeChatException
* @throws DataNotFoundException
* @throws DbException
* @throws DtaException
* @throws ModelNotFoundException
*/
private function getAccessToken()
@ -601,9 +587,9 @@ class WebAppService extends Service
if (empty($this->cache)) $this->getConfig();
if (empty($this->app_id)) $this->getConfig();
if (empty($this->app_secret)) $this->getConfig();
if (empty($this->cache)) throw new WeChatException('请检查cache参数');
if (empty($this->app_id)) throw new WeChatException('请检查app_id参数');
if (empty($this->app_secret)) throw new WeChatException('请检查app_secret参数');
if (empty($this->cache)) throw new DtaException('请检查cache参数');
if (empty($this->app_id)) throw new DtaException('请检查app_id参数');
if (empty($this->app_secret)) throw new DtaException('请检查app_secret参数');
$this->grant_type = "client_credential";
if ($this->cache == "file") {
@ -678,7 +664,7 @@ class WebAppService extends Service
$access_token['access_token'] = $accessToken_res['access_token'];
}
return $access_token;
} else throw new WeChatException("驱动方式错误");
} else throw new DtaException("驱动方式错误");
}
/**

Loading…
Cancel
Save