diff --git a/application/admin/controller/Config.php b/application/admin/controller/Config.php index 7dcf28ff7..2d4022100 100644 --- a/application/admin/controller/Config.php +++ b/application/admin/controller/Config.php @@ -16,6 +16,7 @@ namespace app\admin\controller; use controller\BasicAdmin; use service\LogService; +use service\WechatService; /** * 后台参数配置控制器 diff --git a/application/wechat/controller/Fans.php b/application/wechat/controller/Fans.php index 5c502eab0..2066496f9 100644 --- a/application/wechat/controller/Fans.php +++ b/application/wechat/controller/Fans.php @@ -92,7 +92,7 @@ class Fans extends BasicAdmin { try { $openids = $this->_getActionOpenids(); - WechatService::user()->batchBlackList($openids); + WechatService::WeChatUser()->batchBlackList($openids); Db::name($this->table)->whereIn('openid', $openids)->setField('is_black', '1'); } catch (\Exception $e) { $this->error("设置黑名单失败,请稍候再试!"); @@ -113,7 +113,7 @@ class Fans extends BasicAdmin $fans = Db::name('WechatFans')->where(['id' => $fans_id])->find(); empty($fans) && $this->error('需要操作的数据不存在!'); try { - $wechat = WechatService::tags(); + $wechat = WechatService::WeChatTags(); foreach (explode(',', $fans['tagid_list']) as $tagid) { is_numeric($tagid) && $wechat->batchUntagging([$fans['openid']], $tagid); } @@ -136,7 +136,7 @@ class Fans extends BasicAdmin empty($tagid) && $this->error('没有可能操作的标签ID'); try { $openids = $this->_getActionOpenids(); - WechatService::tags()->batchTagging($openids, $tagid); + WechatService::WeChatTags()->batchTagging($openids, $tagid); } catch (\Exception $e) { $this->error("设置粉丝标签失败, 请稍候再试! " . $e->getMessage()); } @@ -152,7 +152,7 @@ class Fans extends BasicAdmin empty($tagid) && $this->error('没有可能操作的标签ID'); try { $openids = $this->_getActionOpenids(); - WechatService::tags()->batchUntagging($openids, $tagid); + WechatService::WeChatTags()->batchUntagging($openids, $tagid); } catch (\Exception $e) { $this->error("删除粉丝标签失败, 请稍候再试! "); } diff --git a/application/wechat/controller/FansBlock.php b/application/wechat/controller/FansBlock.php index b6c669603..ed2570ded 100644 --- a/application/wechat/controller/FansBlock.php +++ b/application/wechat/controller/FansBlock.php @@ -89,7 +89,7 @@ class FansBlock extends BasicAdmin { $openids = $this->_getActionOpenids(); try { - WechatService::user()->batchUnblackList($openids); + WechatService::WeChatUser()->batchUnblackList($openids); Db::name($this->table)->whereIn('openid', $openids)->setField('is_black', '0'); } catch (\Exception $e) { $this->error("设备黑名单失败,请稍候再试!" . $e->getMessage()); diff --git a/application/wechat/controller/Keys.php b/application/wechat/controller/Keys.php index 7e726fbb0..abea453fe 100644 --- a/application/wechat/controller/Keys.php +++ b/application/wechat/controller/Keys.php @@ -49,7 +49,7 @@ class Keys extends BasicAdmin { // 关键字二维码显示 if ($this->request->get('action') === 'qrc') { - $wechat = WechatService::qrcode(); + $wechat = WechatService::WeChatQrcode(); $result = $wechat->create($this->request->get('keys', '')); $this->redirect($wechat->url($result['ticket'])); } diff --git a/application/wechat/controller/Menu.php b/application/wechat/controller/Menu.php index d8b719f7b..34865d45a 100644 --- a/application/wechat/controller/Menu.php +++ b/application/wechat/controller/Menu.php @@ -91,7 +91,7 @@ class Menu extends BasicAdmin if (empty($post['data'])) { try { Db::name($this->table)->where('1=1')->delete(); - WechatService::menu()->delete(); + WechatService::WeChatMenu()->delete(); } catch (\Exception $e) { $this->error('删除取消微信菜单失败,请稍候再试!' . $e->getMessage()); } @@ -121,7 +121,7 @@ class Menu extends BasicAdmin public function cancel() { try { - WechatService::menu()->delete(); + WechatService::WeChatMenu()->delete(); } catch (\Exception $e) { $this->error('菜单取消失败'); } @@ -174,7 +174,7 @@ class Menu extends BasicAdmin } unset($menu['type']); } - WechatService::menu()->create(['button' => $menus]); + WechatService::WeChatMenu()->create(['button' => $menus]); } } diff --git a/application/wechat/controller/News.php b/application/wechat/controller/News.php index 1d0c1ee23..8eccff790 100644 --- a/application/wechat/controller/News.php +++ b/application/wechat/controller/News.php @@ -14,7 +14,6 @@ namespace app\wechat\controller; -use app\wechat\controller\api\Tools; use app\wechat\service\MediaService; use controller\BasicAdmin; use service\DataService; @@ -258,7 +257,7 @@ class News extends BasicAdmin $data['filter'] = ['is_to_all' => false, 'tag_id' => join(',', $post['fans_tags'])]; $data['mpnews'] = ['media_id' => $newsinfo['media_id']]; } - if (WechatService::custom()->massSendAll($data)) { + if (WechatService::WeChatCustom()->massSendAll($data)) { LogService::write('微信管理', "图文[{$news_id}]推送成功"); $this->success('微信图文推送成功!', ''); } @@ -284,7 +283,7 @@ class News extends BasicAdmin return ""; }, $article['content']); } - $wechat = WechatService::media(); + $wechat = WechatService::WeChatMedia(); // 如果已经上传过,先删除之前的历史记录 !empty($news['media_id']) && $wechat->delMaterial($news['media_id']); // 上传图文到微信服务器 diff --git a/application/wechat/controller/Tags.php b/application/wechat/controller/Tags.php index 52350718f..30468a3a3 100644 --- a/application/wechat/controller/Tags.php +++ b/application/wechat/controller/Tags.php @@ -74,7 +74,7 @@ class Tags extends BasicAdmin if (Db::name($this->table)->where('name', $name)->count() > 0) { $this->error('粉丝标签标签名已经存在, 请使用其它标签名!'); } - $wechat = WechatService::tags(); + $wechat = WechatService::WeChatTags(); if (false === ($result = $wechat->createTags($name)) && isset($result['tag'])) { $this->error("添加粉丝标签失败. "); } @@ -110,7 +110,7 @@ class Tags extends BasicAdmin $this->error('标签已经存在, 使用其它名称再试!'); } try { - WechatService::tags()->updateTags($id, $name); + WechatService::WeChatTags()->updateTags($id, $name); DataService::save($this->table, ['id' => $id, 'name' => $name], 'id'); } catch (\Exception $e) { $this->error('编辑标签失败, 请稍后再试!' . $e->getMessage()); @@ -128,7 +128,7 @@ class Tags extends BasicAdmin */ public function del() { - $wechat = WechatService::tags(); + $wechat = WechatService::WeChatTags(); foreach (explode(',', $this->request->post('id', '')) as $id) { if ($wechat->deleteTags($id)) { Db::name('WechatFansTags')->where(['id' => $id])->delete(); diff --git a/application/wechat/controller/api/Push.php b/application/wechat/controller/api/Push.php index 0ab51cd4e..15b78a97a 100644 --- a/application/wechat/controller/api/Push.php +++ b/application/wechat/controller/api/Push.php @@ -74,7 +74,7 @@ class Push */ public function notify() { - $wechat = WechatService::receive(); + $wechat = WechatService::WeChatReceive(); $this->openid = $wechat->getOpenid(); $this->receive = $wechat->getReceive(); $this->appid = WechatService::getAppid(); @@ -251,7 +251,7 @@ class Push $msgData = ['touser' => $this->openid, 'msgtype' => $type, "{$type}" => $data]; switch (strtolower(sysconf('wechat_type'))) { case 'api': // 参数对接,直接回复XML来实现消息回复 - $wechat = WechatService::receive(); + $wechat = WechatService::WeChatReceive(); switch (strtolower($type)) { case 'text': return $wechat->text($data['content'])->reply([], true); @@ -272,7 +272,7 @@ class Push return 'success'; } case 'thr': // 第三方平台,使用客服消息来实现 - return WechatService::custom()->send($msgData); + return WechatService::WeChatCustom()->send($msgData); default: return 'success'; } @@ -313,7 +313,7 @@ class Push protected function updateFansinfo($subscribe = true) { if ($subscribe) { - $userInfo = WechatService::user()->getUserInfo($this->openid); + $userInfo = WechatService::WeChatUser()->getUserInfo($this->openid); $userInfo['subscribe'] = intval($subscribe); FansService::set($userInfo); } else { diff --git a/application/wechat/controller/api/Tools.php b/application/wechat/controller/api/Tools.php index aeef924d1..8fb1db1c0 100644 --- a/application/wechat/controller/api/Tools.php +++ b/application/wechat/controller/api/Tools.php @@ -28,6 +28,7 @@ class Tools extends BasicAdmin /** * 网页授权测试 * @return string + * @throws \WeChat\Exceptions\InvalidResponseException * @throws \think\Exception * @throws \think\exception\PDOException */ diff --git a/application/wechat/service/FansService.php b/application/wechat/service/FansService.php index 3c3b565b0..e5273cec9 100644 --- a/application/wechat/service/FansService.php +++ b/application/wechat/service/FansService.php @@ -77,7 +77,7 @@ class FansService */ public static function sync($next_openid = '') { - $wechat = WechatService::user(); + $wechat = WechatService::WeChatUser(); $result = $wechat->getUserList($next_openid); if (empty($result['data']['openid'])) { return false; @@ -106,7 +106,7 @@ class FansService */ public static function syncBlack($next_openid = '') { - $wechat = WechatService::user(); + $wechat = WechatService::WeChatUser(); $result = $wechat->getBlackList($next_openid); foreach (array_chunk($result['data']['openid'], 100) as $openids) { $info = $wechat->getBatchUserInfo($openids); diff --git a/application/wechat/service/MediaService.php b/application/wechat/service/MediaService.php index e7a90d075..c662c1fb8 100644 --- a/application/wechat/service/MediaService.php +++ b/application/wechat/service/MediaService.php @@ -67,7 +67,7 @@ class MediaService if (($media_url = Db::name('WechatNewsImage')->where($map)->value('media_url'))) { return $media_url; } - $info = WechatService::media()->uploadImg(self::getServerPath($local_url)); + $info = WechatService::WeChatMedia()->uploadImg(self::getServerPath($local_url)); if (strtolower(sysconf('wechat_type')) === 'thr') { WechatService::wechat()->rmFile($local_url); } @@ -93,7 +93,7 @@ class MediaService if (($media_id = Db::name('WechatNewsMedia')->where($map)->value('media_id'))) { return $media_id; } - $result = WechatService::media()->addMaterial(self::getServerPath($local_url), $type, $video_info); + $result = WechatService::WeChatMedia()->addMaterial(self::getServerPath($local_url), $type, $video_info); if (strtolower(sysconf('wechat_type')) === 'thr') { WechatService::wechat()->rmFile($local_url); } diff --git a/application/wechat/service/TagsService.php b/application/wechat/service/TagsService.php index 327884afe..d2aa784ba 100644 --- a/application/wechat/service/TagsService.php +++ b/application/wechat/service/TagsService.php @@ -36,7 +36,7 @@ class TagsService */ public static function syncTagsByOpenid($openid) { - $tagsid = WechatService::tags()->getUserTagId($openid); + $tagsid = WechatService::WeChatTags()->getUserTagId($openid); if (!is_array($tagsid)) { return false; } @@ -55,7 +55,7 @@ class TagsService public static function sync() { $appid = WechatService::getAppid(); - $result = WechatService::tags()->getTags(); + $result = WechatService::WeChatTags()->getTags(); Db::name('WechatFansTags')->where(['appid' => $appid])->delete(); foreach (array_chunk($result['tags'], 100) as $list) { foreach ($list as &$vo) { diff --git a/extend/service/WechatService.php b/extend/service/WechatService.php index 84df76631..bf3fa3738 100644 --- a/extend/service/WechatService.php +++ b/extend/service/WechatService.php @@ -24,41 +24,57 @@ use think\Exception; * @author Anyon * @date 2017/03/22 15:32 * - * @method \WeChat\Card card() static 卡券管理 - * @method \WeChat\Custom custom() static 客服消息处理 - * @method \WeChat\Limit limit() static 接口调用频次限制 - * @method \WeChat\Media media() static 微信素材管理 - * @method \WeChat\Menu menu() static 微信素材管理 - * @method \WeChat\Oauth oauth() static 微信网页授权 - * @method \WeChat\Pay pay() static 微信支付商户 - * @method \WeChat\Product product() static 商店管理 - * @method \WeChat\Qrcode qrcode() static 二维码管理 - * @method \WeChat\Receive receive() static 公众号推送管理 - * @method \WeChat\Scan scan() static 扫一扫接入管理 - * @method \WeChat\Script script() static 微信前端支持 - * @method \WeChat\Shake shake() static 揺一揺周边 - * @method \WeChat\Tags tags() static 用户标签管理 - * @method \WeChat\Template template() static 模板消息 - * @method \WeChat\User user() static 微信粉丝管理 - * @method \WeChat\Wifi wifi() static 门店WIFI管理 - * --- 小程序SDK加载 开始 --- - * @method \WeMini\Account miniAccount() static 小程序账号管理 - * @method \WeMini\Basic miniBasic() static 小程序基础信息设置 - * @method \WeMini\Code miniCode() static 小程序代码管理 - * @method \WeMini\Domain miniDomain() static 小程序域名管理 - * @method \WeMini\Tester minitester() static 小程序成员管理 - * @method \WeMini\User miniUser() static 小程序帐号管理 - * @method \WeMini\Crypt miniCrypt() static 小程序数据加密处理管理 - * @method \WeMini\Plugs miniPlugs() static 小程序插件管理 - * @method \WeMini\Poi miniPoi() static 小程地址管理 - * @method \WeMini\Qrcode miniQrcode() static 小程二维码管理 - * @method \WeMini\Template miniTemplate() static 小程序模板消息 - * @method \WeMini\Total miniTotal() static 小程序数据接口 - * --- 小程序SDK加载 结束 --- - * @method void wechat() static 第三方微信工具 - * @method void config() static 第三方配置工具 + * ----- WeChat ----- + * @method \WeChat\Card WeChatCard() static 微信卡券管理 + * @method \WeChat\Custom WeChatCustom() static 微信客服消息 + * @method \WeChat\Limit WeChatLimit() static 接口调用频次限制 + * @method \WeChat\Media WeChatMedia() static 微信素材管理 + * @method \WeChat\Menu WeChatMenu() static 微信菜单管理 + * @method \WeChat\Oauth WeChatOauth() static 微信网页授权 + * @method \WeChat\Pay WeChatPay() static 微信支付商户 + * @method \WeChat\Product WeChatProduct() static 微信商店管理 + * @method \WeChat\Qrcode WeChatQrcode() static 微信二维码管理 + * @method \WeChat\Receive WeChatReceive() static 微信推送管理 + * @method \WeChat\Scan WeChatScan() static 微信扫一扫接入管理 + * @method \WeChat\Script WeChatScript() static 微信前端支持 + * @method \WeChat\Shake WeChatShake() static 微信揺一揺周边 + * @method \WeChat\Tags WeChatTags() static 微信用户标签管理 + * @method \WeChat\Template WeChatTemplate() static 微信模板消息 + * @method \WeChat\User WeChatUser() static 微信粉丝管理 + * @method \WeChat\Wifi WeChatWifi() static 微信门店WIFI管理 + * + * ----- WeMini ----- + * @method \WeMini\Account WeMiniAccount() static 小程序账号管理 + * @method \WeMini\Basic WeMiniBasic() static 小程序基础信息设置 + * @method \WeMini\Code WeMiniCode() static 小程序代码管理 + * @method \WeMini\Domain WeMiniDomain() static 小程序域名管理 + * @method \WeMini\Tester WeMinitester() static 小程序成员管理 + * @method \WeMini\User WeMiniUser() static 小程序帐号管理 + * -------------------- + * @method \WeMini\Crypt WeMiniCrypt() static 小程序数据加密处理 + * @method \WeMini\Plugs WeMiniPlugs() static 小程序插件管理 + * @method \WeMini\Poi WeMiniPoi() static 小程序地址管理 + * @method \WeMini\Qrcode WeMiniQrcode() static 小程序二维码管理 + * @method \WeMini\Template WeMiniTemplate() static 小程序模板消息支持 + * @method \WeMini\Total WeMiniTotal() static 小程序数据接口 + * + * ----- WePay ----- + * @method \WePay\Bill WePayBill() static 微信商户账单及评论 + * @method \WePay\Order WePayOrder() static 微信商户订单 + * @method \WePay\Refund WePayRefund() static 微信商户退款 + * @method \WePay\Coupon WePayCoupon() static 微信商户代金券 + * @method \WePay\Redpack WePayRedpack() static 微信红包支持 + * @method \WePay\Transfers WePayTransfers() static 微信商户打款到零钱 + * @method \WePay\TransfersBank WePayTransFresBank() static 微信商户打款到银行卡 + * + * ----- WeOpen ----- * @method \WeOpen\Login login() static 第三方微信登录 * @method \WeOpen\Service service() static 第三方服务 + * + * ----- ThinkService ----- + * @method mixed wechat() static 第三方微信工具 + * @method mixed config() static 第三方配置工具 + * */ class WechatService { @@ -69,22 +85,6 @@ class WechatService */ private static $type = 'WeChat'; - /** - * 切换接口为服务号模式 - */ - public static function setWeChatState() - { - self::$type = 'WeChat'; - } - - /** - * 切换接口为小程序模式 - */ - public static function setWeMiniState() - { - self::$type = 'WeMini'; - } - /** * 获取微信实例ID * @param string $name 实例对象名称 @@ -141,7 +141,7 @@ class WechatService $signUrl = is_null($url) ? app('request')->url(true) : $url; switch (strtolower(sysconf('wechat_type'))) { case 'api': - return WechatService::script()->getJsSign($signUrl); + return WechatService::WeChatScript()->getJsSign($signUrl); case 'thr': return WechatService::wechat()->jsSign($signUrl); default: @@ -155,6 +155,7 @@ class WechatService * @param int $fullMode 授权公众号模式 * @param bool $isRedirect 是否进行跳转 * @return array + * @throws \WeChat\Exceptions\InvalidResponseException * @throws \think\Exception * @throws \think\exception\PDOException */ @@ -168,7 +169,7 @@ class WechatService } switch (strtolower(sysconf('wechat_type'))) { case 'api': - $wechat = self::oauth(); + $wechat = self::WeChatOauth(); if (request()->get('state') !== $appid) { $snsapi = empty($fullMode) ? 'snsapi_base' : 'snsapi_userinfo'; $param = (strpos($url, '?') !== false ? '&' : '?') . 'rcode=' . encode($url); @@ -226,19 +227,23 @@ class WechatService /** * 魔术静态方法实现对象 - * @param string $name - * @param array $arguments + * @param string $name 方法类名 + * @param array $arguments 调用参数 * @return SoapService * @throws \think\Exception * @throws \think\exception\PDOException */ public static function __callStatic($name, $arguments) { - if (substr($name, 0, 4) === 'mini') { - self::setWeMiniState(); - $name = substr($name, 4); - } else { - self::setWeChatState(); + if (substr($name, 0, 6) === 'WeMini') { + self::$type = 'WeMini'; + $name = substr($name, 6); + } elseif (substr($name, 0, 6) === 'WeChat') { + self::$type = 'WeChat'; + $name = substr($name, 6); + } elseif (substr($name, 0, 5) === 'WePay') { + self::$type = 'WePay'; + $name = substr($name, 5); } return self::instance($name); } diff --git a/vendor/autoload.php b/vendor/autoload.php index b55f6870e..0ab2b6a43 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit6588b91efff19d88b158b1c18209b5f4::getLoader(); +return ComposerAutoloaderInit484ec88015be4f45ec888a71837712e4::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 26e797b24..e51b25408 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit6588b91efff19d88b158b1c18209b5f4 +class ComposerAutoloaderInit484ec88015be4f45ec888a71837712e4 { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInit6588b91efff19d88b158b1c18209b5f4 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit6588b91efff19d88b158b1c18209b5f4', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit484ec88015be4f45ec888a71837712e4', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit6588b91efff19d88b158b1c18209b5f4', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit484ec88015be4f45ec888a71837712e4', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit6588b91efff19d88b158b1c18209b5f4::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit484ec88015be4f45ec888a71837712e4::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInit6588b91efff19d88b158b1c18209b5f4 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit6588b91efff19d88b158b1c18209b5f4::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit484ec88015be4f45ec888a71837712e4::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire6588b91efff19d88b158b1c18209b5f4($fileIdentifier, $file); + composerRequire484ec88015be4f45ec888a71837712e4($fileIdentifier, $file); } return $loader; } } -function composerRequire6588b91efff19d88b158b1c18209b5f4($fileIdentifier, $file) +function composerRequire484ec88015be4f45ec888a71837712e4($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index d307742be..50cf29038 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit6588b91efff19d88b158b1c18209b5f4 +class ComposerStaticInit484ec88015be4f45ec888a71837712e4 { public static $files = array ( '1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php', @@ -302,9 +302,9 @@ class ComposerStaticInit6588b91efff19d88b158b1c18209b5f4 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit6588b91efff19d88b158b1c18209b5f4::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit6588b91efff19d88b158b1c18209b5f4::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit6588b91efff19d88b158b1c18209b5f4::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit484ec88015be4f45ec888a71837712e4::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit484ec88015be4f45ec888a71837712e4::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit484ec88015be4f45ec888a71837712e4::$classMap; }, null, ClassLoader::class); }