2020-06-07 14:22:41 +08:00
|
|
|
<?php
|
2020-11-29 09:29:14 +08:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-07 14:22:41 +08:00
|
|
|
/**
|
|
|
|
* @filename WeChat.php
|
|
|
|
* @date 2020/6/7
|
|
|
|
* @project https://github.com/yanwenwu/catch-admin
|
|
|
|
* @document http://doc.catchadmin.com
|
|
|
|
* @author JaguarJack <njphper@gmail.com>
|
|
|
|
* @copyright By CatchAdmin
|
|
|
|
* @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt
|
2020-06-07 14:23:07 +08:00
|
|
|
*/
|
|
|
|
namespace catcher\library;
|
|
|
|
|
2020-06-21 13:23:22 +08:00
|
|
|
use catcher\exceptions\WechatResponseException;
|
|
|
|
use catcher\library\Errors;
|
2020-06-07 14:23:07 +08:00
|
|
|
use EasyWeChat\Factory;
|
|
|
|
use think\helper\Str;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @method static officialAccount()
|
|
|
|
* @method static miniProgram()
|
|
|
|
* @method static openPlatform()
|
|
|
|
* @method static work()
|
|
|
|
* @method static openWork()
|
|
|
|
* @method static payment()
|
|
|
|
*
|
|
|
|
* Class WeChat
|
|
|
|
* @package catcher\library
|
|
|
|
*/
|
|
|
|
class WeChat
|
|
|
|
{
|
2020-06-19 19:28:56 +08:00
|
|
|
/**
|
|
|
|
* 静态调用
|
|
|
|
*
|
|
|
|
* @time 2020年06月19日
|
|
|
|
* @param $name
|
|
|
|
* @param $arguments
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-06-07 14:23:07 +08:00
|
|
|
public static function __callStatic($name, $arguments)
|
2020-06-21 13:23:22 +08:00
|
|
|
{// TODO: Implement __callStatic() method.
|
2020-06-07 14:23:07 +08:00
|
|
|
return Factory::{$name}(\config('wechat.'. Str::snake($name)));
|
|
|
|
}
|
2020-06-19 19:28:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 动态调用
|
|
|
|
*
|
|
|
|
* @time 2020年06月19日
|
|
|
|
* @param $name
|
|
|
|
* @param $arguments
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __call($name, $arguments)
|
|
|
|
{
|
|
|
|
// TODO: Implement __call() method.
|
|
|
|
return Factory::{$name}(\config('wechat.'. Str::snake($name)));
|
|
|
|
}
|
2020-06-21 13:23:22 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* throw error
|
|
|
|
*
|
|
|
|
* @time 2020年06月21日
|
|
|
|
* @param $response
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function throw($response)
|
|
|
|
{
|
|
|
|
if (isset($response['errcode']) && $response['errcode']) {
|
2020-06-21 16:20:02 +08:00
|
|
|
$message = Errors::WECHAT[$response['errcode']] ?? $response['errcode'];
|
|
|
|
throw new WechatResponseException($message, $response['errcode']);
|
2020-06-21 13:23:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2020-06-07 14:23:07 +08:00
|
|
|
}
|