From 88d4e1c40960f9baf6e0187f7837c2ace5d3914c Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 9 Dec 2019 16:32:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BE=AE=E4=BF=A1=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/controller/Fans.php | 92 -------- app/service/controller/Wechat.php | 71 ------ app/service/controller/api/Client.php | 78 ------- app/service/controller/api/Push.php | 214 ------------------ app/service/handle/PublishHandle.php | 61 ----- app/service/handle/ReceiveHandle.php | 65 ------ app/service/service/ClientService.php | 58 ----- app/service/service/ConfigService.php | 135 ----------- app/service/service/WechatService.php | 184 --------------- app/service/view/config/form.html | 44 ---- app/service/view/config/index.html | 98 -------- app/service/view/not-auth.html | 1 - app/service/view/wechat/index.html | 85 ------- app/service/view/wechat/index_search.html | 76 ------- .../Config.php => wechat/controller/Fans.php} | 36 +-- app/wechat/service/WechatService.php | 150 ++++++++++++ 16 files changed, 160 insertions(+), 1288 deletions(-) delete mode 100644 app/service/controller/Fans.php delete mode 100644 app/service/controller/Wechat.php delete mode 100644 app/service/controller/api/Client.php delete mode 100644 app/service/controller/api/Push.php delete mode 100644 app/service/handle/PublishHandle.php delete mode 100644 app/service/handle/ReceiveHandle.php delete mode 100644 app/service/service/ClientService.php delete mode 100644 app/service/service/ConfigService.php delete mode 100644 app/service/service/WechatService.php delete mode 100644 app/service/view/config/form.html delete mode 100644 app/service/view/config/index.html delete mode 100644 app/service/view/not-auth.html delete mode 100644 app/service/view/wechat/index.html delete mode 100644 app/service/view/wechat/index_search.html rename app/{service/controller/Config.php => wechat/controller/Fans.php} (62%) create mode 100644 app/wechat/service/WechatService.php diff --git a/app/service/controller/Fans.php b/app/service/controller/Fans.php deleted file mode 100644 index b816b51c7..000000000 --- a/app/service/controller/Fans.php +++ /dev/null @@ -1,92 +0,0 @@ -appid = input('appid', $this->app->session->get('current_appid')); - if (empty($this->appid)) { - $this->where = ['status' => '1', 'service_type' => '2', 'is_deleted' => '0', 'verify_type' => '0']; - $this->appid = $this->app->db->name('WechatServiceConfig')->where($this->where)->value('authorizer_appid'); - } - if (empty($this->appid)) { - $this->fetch('/not-auth'); - } else { - $this->app->session->set('current_appid', $this->appid); - } - if ($this->request->isGet()) { - $this->where = ['status' => '1', 'service_type' => '2', 'is_deleted' => '0', 'verify_type' => '0']; - $this->wechats = $this->app->db->name('WechatServiceConfig')->where($this->where)->order('id desc')->column('authorizer_appid,nick_name'); - } - } - - /** - * 微信粉丝管理 - * @auth true - * @menu true - */ - public function index() - { - $this->title = '微信粉丝管理'; - $query = $this->_query($this->table)->like('nickname')->equal('subscribe,is_black'); - $query->dateBetween('subscribe_at')->where(['appid' => $this->appid])->order('subscribe_time desc')->page(); - } - - /** - * 列表数据处理 - * @param array $data - */ - protected function _index_page_filter(array &$data) - { - $tags = $this->app->db->name('WechatFansTags')->column('id,name'); - foreach ($data as &$user) { - $user['tags'] = []; - foreach (explode(',', $user['tagid_list']) as $tagid) { - if (isset($tags[$tagid])) $user['tags'][] = $tags[$tagid]; - } - } - } - - /** - * 删除粉丝信息 - * @auth true - * @throws \think\db\exception\DbException - */ - public function remove() - { - $this->_applyFormToken(); - $this->_delete($this->table); - } - -} \ No newline at end of file diff --git a/app/service/controller/Wechat.php b/app/service/controller/Wechat.php deleted file mode 100644 index a0fc60cf2..000000000 --- a/app/service/controller/Wechat.php +++ /dev/null @@ -1,71 +0,0 @@ -title = '公众号授权管理'; - $query = $this->_query($this->table)->like('authorizer_appid,nick_name,principal_name'); - $query = $query->equal('service_type,status')->dateBetween('create_at'); - $query->where(['is_deleted' => '0'])->order('id desc')->page(); - } - - /** - * 修改公众号状态 - * @auth true - * @throws \think\db\exception\DbException - */ - public function state() - { - $this->_applyFormToken(); - $this->_save($this->table, ['status' => input('status')]); - } - - /** - * 删除公众号授权 - * @auth true - * @throws \think\db\exception\DbException - */ - public function remove() - { - $this->_applyFormToken(); - $this->_delete($this->table); - } - -} \ No newline at end of file diff --git a/app/service/controller/api/Client.php b/app/service/controller/api/Client.php deleted file mode 100644 index 123ffcb3e..000000000 --- a/app/service/controller/api/Client.php +++ /dev/null @@ -1,78 +0,0 @@ -instance()); - $service->handle(); - } catch (\Exception $exception) { - return $exception->getMessage(); - } - } - - /** - * SOAP 接口标准对接 - * @return string - */ - public function soap() - { - try { - $service = new \SoapServer(null, ['uri' => 'thinkadmin']); - $service->setObject($this->instance()); - $service->handle(); - } catch (\Exception $exception) { - return $exception->getMessage(); - } - } - - /** - * 远程获取实例对象 - * @return mixed|\Exception - */ - private function instance() - { - try { - $data = json_decode(debase64url(input('token', '')), true); - list($class, $appid, $time, $nostr, $sign) = [$data['class'], $data['appid'], $data['time'], $data['nostr'], $data['sign']]; - $wechat = $this->app->db->name('WechatServiceConfig')->where(['authorizer_appid' => $appid])->find(); - if (empty($wechat)) throw new Exception("抱歉,该公众号{$appid}未授权!"); - if (abs(time() - $data['time']) > 10) throw new Exception('抱歉,接口调用时差过大!'); - if (md5("{$class}#{$appid}#{$wechat['appkey']}#{$time}#{$nostr}") !== $sign) { - throw new Exception("抱歉,该公众号{$appid}签名异常!"); - } - return WechatService::__callStatic($class, [$appid]); - } catch (\Exception $exception) { - return new \Exception($exception->getMessage(), 404); - } - } -} diff --git a/app/service/controller/api/Push.php b/app/service/controller/api/Push.php deleted file mode 100644 index 3cfb2a806..000000000 --- a/app/service/controller/api/Push.php +++ /dev/null @@ -1,214 +0,0 @@ -handler($appid); - } else { - # 常归接口正常服务 - return ReceiveHandle::instance()->handler($appid); - } - } - - /** - * 一、处理服务推送Ticket - * 二、处理取消公众号授权 - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function ticket() - { - try { - $server = WechatService::WeOpenService(); - if (!($data = $server->getComonentTicket())) { - return "Ticket event handling failed."; - } - } catch (\Exception $e) { - return "Ticket event handling failed, {$e->getMessage()}"; - } - if (!empty($data['AuthorizerAppid']) && isset($data['InfoType'])) { - # 授权成功通知 - if ($data['InfoType'] === 'authorized') { - $this->app->db->name('WechatServiceConfig')->where(['authorizer_appid' => $data['AuthorizerAppid']])->update(['is_deleted' => '0']); - } - # 接收取消授权服务事件 - if ($data['InfoType'] === 'unauthorized') { - $this->app->db->name('WechatServiceConfig')->where(['authorizer_appid' => $data['AuthorizerAppid']])->update(['is_deleted' => '1']); - } - # 授权更新通知 - if ($data['InfoType'] === 'updateauthorized') { - $_GET['auth_code'] = $data['PreAuthCode']; - $this->applyAuth($server); - } - } - return 'success'; - } - - /** - * 微信代网页授权 - * @throws \think\Exception - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - public function oauth() - { - list($mode, $appid, $enurl, $sessid) = [ - $this->request->get('mode'), $this->request->get('state'), - $this->request->get('enurl'), $this->request->get('sessid'), - ]; - $result = WechatService::WeOpenService()->getOauthAccessToken($appid); - if (empty($result['openid'])) throw new \think\Exception('网页授权失败, 无法进一步操作!'); - $this->app->cache->set("{$appid}_{$sessid}_openid", $result['openid'], 3600); - if (!empty($mode)) { - $fans = WechatService::WeChatOauth($appid)->getUserInfo($result['access_token'], $result['openid']); - if (empty($fans)) throw new \think\Exception('网页授权信息获取失败, 无法进一步操作!'); - $this->app->cache->set("{$appid}_{$sessid}_fans", $fans, 3600); - } - $this->redirect(debase64url($enurl)); - } - - /** - * 跳转到微信服务授权页面 - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function auth() - { - $this->source = input('source'); - if (empty($this->source)) { - return '请传入回跳 source 参数 ( 请使用 enbase64url 加密 )'; - } - $this->sourceUrl = debase64url($this->source); - if (empty($this->sourceUrl)) { - return '请传入回跳 source 参数 ( 请使用 enbase64url 加密 )'; - } - # 预授权码不为空,则表示可以进行授权处理 - $service = WechatService::WeOpenService(); - if (($auth_code = $this->request->get('auth_code'))) { - return $this->applyAuth($service, $this->sourceUrl); - } - # 生成微信授权链接,使用刷新跳转到授权网页 - $redirect = url("@service/api.push/auth", [], true, true) . "?source={$this->source}"; - if (($redirect = $service->getAuthRedirect($redirect))) { - ob_clean(); - header("Refresh:0;url={$redirect}"); - return "跳转中..."; - } - # 生成微信授权链接失败 - return "

Failed to create authorization. Please return to try again.

"; - } - - /** - * 公众号授权绑定数据处理 - * @param Service $service 平台服务对象 - * @param string $redirect 授权成功回跳地址 - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - private function applyAuth(Service $service, $redirect = null) - { - // 通过授权code换取公众号信息 - $result = $service->getQueryAuthorizerInfo(); - if (empty($result['authorizer_appid'])) { - return "接收微信第三方平台授权失败! "; - } - // 重新通过接口查询公众号参数 - if (!($update = array_merge($result, $service->getAuthorizerInfo($result['authorizer_appid'])))) { - return '获取授权数据失败, 请稍候再试! '; - } - // 生成公众号授权参数 - $update = array_merge($this->buildAuthData($update), [ - 'status' => '1', 'is_deleted' => '0', 'expires_in' => time() + 7000, 'create_at' => date('y-m-d H:i:s'), - ]); - // 微信接口APPKEY处理与更新 - $config = $this->app->db->name('WechatServiceConfig')->where(['authorizer_appid' => $result['authorizer_appid']])->find(); - $update['appkey'] = empty($config['appkey']) ? md5(uniqid('', true)) : $config['appkey']; - SystemService::instance()->save('WechatServiceConfig', $update, 'authorizer_appid'); - if (!empty($redirect)) { // 带上appid与appkey跳转到应用 - $split = stripos($redirect, '?') > 0 ? '&' : '?'; - $realurl = preg_replace(['/appid=\w+/i', '/appkey=\w+/i', '/(\?\&)$/i'], ['', '', ''], $redirect); - return redirect("{$realurl}{$split}appid={$update['authorizer_appid']}&appkey={$update['appkey']}"); - } - } - - /** - * 生成公众号授权信息 - * @param array $info - * @return array - */ - private function buildAuthData(array $info) - { - $info = array_change_key_case($info, CASE_LOWER); - if (isset($info['func_info']) && is_array($info['func_info'])) { - $info['func_info'] = join(',', array_map(function ($tmp) { - return isset($tmp['funcscope_category']['id']) ? $tmp['funcscope_category']['id'] : 0; - }, $info['func_info'])); - } - $info['business_info'] = serialize($info['business_info']); - $info['verify_type_info'] = join(',', $info['verify_type_info']); - $info['service_type_info'] = join(',', $info['service_type_info']); - // 微信类型: 0 代表订阅号, 2 代表服务号, 3 代表小程序 - $info['service_type'] = intval($info['service_type_info']) === 2 ? 2 : 0; - if (!empty($info['miniprograminfo'])) { - $info['service_type'] = 3; - $info['miniprograminfo'] = serialize($info['miniprograminfo']); - } - // 微信认证: -1 代表未认证, 0 代表微信认证 - $info['verify_type'] = intval($info['verify_type_info']) !== 0 ? -1 : 0; - return $info; - } -} \ No newline at end of file diff --git a/app/service/handle/PublishHandle.php b/app/service/handle/PublishHandle.php deleted file mode 100644 index f0e7b4223..000000000 --- a/app/service/handle/PublishHandle.php +++ /dev/null @@ -1,61 +0,0 @@ -getMessage()}"; - } - /* 分别执行对应类型的操作 */ - switch (strtolower($wechat->getMsgType())) { - case 'text': - $receive = $wechat->getReceive(); - if ($receive['Content'] === 'TESTCOMPONENT_MSG_TYPE_TEXT') { - return $wechat->text('TESTCOMPONENT_MSG_TYPE_TEXT_callback')->reply([], true); - } else { - $key = str_replace("QUERY_AUTH_CODE:", '', $receive['Content']); - WechatService::WeOpenService()->getQueryAuthorizerInfo($key); - return $wechat->text("{$key}_from_api")->reply([], true); - } - case 'event': - $receive = $wechat->getReceive(); - return $wechat->text("{$receive['Event']}from_callback")->reply([], true); - default: - return 'success'; - } - } -} \ No newline at end of file diff --git a/app/service/handle/ReceiveHandle.php b/app/service/handle/ReceiveHandle.php deleted file mode 100644 index 086111a71..000000000 --- a/app/service/handle/ReceiveHandle.php +++ /dev/null @@ -1,65 +0,0 @@ -getMessage()}"; - } - // 验证微信配置信息 - $config = $this->app->db->name('WechatServiceConfig')->where(['authorizer_appid' => $appid])->find(); - if (empty($config) || empty($config['appuri'])) { - sysoplog('微信接口', $message = "微信{$appid}授权配置验证无效"); - return $message; - } - try { - list($data, $openid) = [$wechat->getReceive(), $wechat->getOpenid()]; - if (isset($data['EventKey']) && is_object($data['EventKey'])) $data['EventKey'] = (array)$data['EventKey']; - $input = ['openid' => $openid, 'appid' => $appid, 'receive' => serialize($data), 'encrypt' => intval($wechat->isEncrypt())]; - if (is_string($result = http_post($config['appuri'], $input, ['timeout' => 30]))) { - if (is_array($json = json_decode($result, true))) { - return $wechat->reply($json, true, $wechat->isEncrypt()); - } else { - return $result; - } - } - } catch (\Exception $exception) { - sysoplog('微信接口', "微信{$appid}接口调用异常,{$exception->getMessage()}"); - } - return 'success'; - } -} \ No newline at end of file diff --git a/app/service/service/ClientService.php b/app/service/service/ClientService.php deleted file mode 100644 index c68479bbc..000000000 --- a/app/service/service/ClientService.php +++ /dev/null @@ -1,58 +0,0 @@ - $name, 'appid' => $appid, 'time' => time(), 'nostr' => uniqid()]; - $data['sign'] = md5("{$data['class']}#{$appid}#{$appkey}#{$data['time']}#{$data['nostr']}"); - $token = enbase64url(json_encode($data, JSON_UNESCAPED_UNICODE)); - if (class_exists('Yar_Client')) { - $url = "{$serviceUri}/service/api.client/yar?not_init_session=1&token={$token}"; - $client = new \Yar_Client($url); - } else { - $url = "{$serviceUri}/service/api.client/soap?not_init_session=1&token={$token}"; - $client = new \SoapClient(null, ['location' => $url, 'uri' => "thinkadmin"]); - } - try { - $exception = new \think\Exception($client->getMessage(), $client->getCode()); - } catch (\Exception $exception) { - $exception = null; - } - if ($exception instanceof \Exception) throw $exception; - return $client; - } - -} \ No newline at end of file diff --git a/app/service/service/ConfigService.php b/app/service/service/ConfigService.php deleted file mode 100644 index 18631cce2..000000000 --- a/app/service/service/ConfigService.php +++ /dev/null @@ -1,135 +0,0 @@ -appid = $appid; - $this->config = $this->app->db->name('wechatServiceConfig')->where(['authorizer_appid' => $appid])->find(); - if (empty($this->config)) { - throw new \think\Exception("公众号{$appid}还没有授权!"); - } - return $this; - } - - /** - * 获取当前公众号配置 - * @return array - */ - public function getConfig() - { - return $this->config; - } - - /** - * 设置微信接口通知URL地址 - * @param string $notifyUri 接口通知URL地址 - * @return boolean - * @throws \think\Exception - * @throws \think\db\exception\DbException - */ - public function setApiNotifyUri($notifyUri) - { - if (empty($notifyUri)) throw new \think\Exception('请传入微信通知URL'); - list($where, $data) = [['authorizer_appid' => $this->appid], ['appuri' => $notifyUri]]; - return $this->app->db->name('WechatServiceConfig')->where($where)->update($data) !== false; - } - - /** - * 更新接口Appkey(成功返回新的Appkey) - * @return bool|string - * @throws \think\db\exception\DbException - */ - public function updateApiAppkey() - { - $data = ['appkey' => md5(uniqid())]; - $this->app->db->name('WechatServiceConfig')->where(['authorizer_appid' => $this->appid])->update($data); - return $data['appkey']; - } - - /** - * 获取公众号的配置参数 - * @param string $name 参数名称 - * @return array|string - */ - public function config($name = null) - { - return WechatService::WeChatScript($this->appid)->config->get($name); - } - - /** - * 微信网页授权 - * @param string $sessid 当前会话id(可用session_id()获取) - * @param string $source 当前会话URL地址(需包含域名的完整URL地址) - * @param integer $type 网页授权模式(0静默模式,1高级授权) - * @return array|boolean - */ - public function oauth($sessid, $source, $type = 0) - { - $fans = $this->app->cache->get("{$this->appid}_{$sessid}_fans"); - $openid = $this->app->cache->get("{$this->appid}_{$sessid}_openid"); - if (!empty($openid) && (empty($type) || !empty($fans))) { - return ['openid' => $openid, 'fans' => $fans, 'url' => '']; - } - $mode = empty($type) ? 'snsapi_base' : 'snsapi_userinfo'; - $url = url('@service/api.push/oauth', [], true, true); - $params = ['mode' => $type, 'sessid' => $sessid, 'enurl' => enbase64url($source)]; - $authurl = WechatService::WeOpenService()->getOauthRedirect($this->appid, $url . '?' . http_build_query($params), $mode); - return ['openid' => $openid, 'fans' => $fans, 'url' => $authurl]; - } - - /** - * 微信网页JS签名 - * @param string $url 当前会话URL地址(需包含域名的完整URL地址) - * @return array|boolean - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - public function jsSign($url) - { - return WechatService::WeChatScript($this->appid)->getJsSign($url); - } -} \ No newline at end of file diff --git a/app/service/service/WechatService.php b/app/service/service/WechatService.php deleted file mode 100644 index 54b260ab9..000000000 --- a/app/service/service/WechatService.php +++ /dev/null @@ -1,184 +0,0 @@ -getWechatConfig($arguments[0])); - } elseif ($type === 'ThinkAdmin' && $class === 'Config') { - return ConfigService::instance()->initialize($arguments[0]); - } elseif ($type === 'WeOpen') { - return new $classname(self::instance()->getServiceConfig()); - } else { - throw new \think\Exception("class {$classname} not defined."); - } - } - - /** - * 获取公众号配置参数 - * @param string $authorizerAppid - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function getWechatConfig($authorizerAppid) - { - $conifg = [ - 'appid' => $authorizerAppid, - 'token' => sysconf('service.component_token'), - 'appsecret' => sysconf('service.component_appsecret'), - 'encodingaeskey' => sysconf('service.component_encodingaeskey'), - 'cache_path' => $this->getCachePath(), - ]; - $conifg['GetAccessTokenCallback'] = function ($authorizerAppid) { - $map = ['authorizer_appid' => $authorizerAppid]; - $refreshToken = $this->app->db->name('WechatServiceConfig')->where($map)->value('authorizer_refresh_token'); - if (empty($refreshToken)) throw new \think\Exception('The WeChat information is not configured.', '404'); - // 刷新公众号原授权 AccessToken - $result = WechatService::WeOpenService()->refreshAccessToken($authorizerAppid, $refreshToken); - if (empty($result['authorizer_access_token']) || empty($result['authorizer_refresh_token'])) { - throw new \think\Exception($result['errmsg']); - } - // 更新公众号授权信息 - $this->app->db->name('WechatServiceConfig')->where($map)->update([ - 'authorizer_access_token' => $result['authorizer_access_token'], - 'authorizer_refresh_token' => $result['authorizer_refresh_token'], - ]); - return $result['authorizer_access_token']; - }; - return $conifg; - } - - /** - * 获取服务平台配置参数 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - */ - public function getServiceConfig() - { - return [ - 'cache_path' => $this->getCachePath(), - 'component_appid' => sysconf('service.component_appid'), - 'component_token' => sysconf('service.component_token'), - 'component_appsecret' => sysconf('service.component_appsecret'), - 'component_encodingaeskey' => sysconf('service.component_encodingaeskey'), - ]; - } - - /** - * 获取缓存目录 - * @return string - */ - private function getCachePath() - { - return $this->app->getRuntimePath() . 'wechat'; - } -} \ No newline at end of file diff --git a/app/service/view/config/form.html b/app/service/view/config/form.html deleted file mode 100644 index c30d197d7..000000000 --- a/app/service/view/config/form.html +++ /dev/null @@ -1,44 +0,0 @@ -
- -
- -
- -

开放平台服务 AppID,需要在微信开放平台获取

-
- -
- -

开放平台服务 AppSecret,需要在微信开放平台获取

-
- -
- -

开发者在代替微信接收到消息时,用此 Token 来校验消息

-
- -
- -

在代替微信收发消息时使用,必须是长度为43位字母和数字组合的字符串

-
- -
- -
- -
- -
-
\ No newline at end of file diff --git a/app/service/view/config/index.html b/app/service/view/config/index.html deleted file mode 100644 index 931c4eeb7..000000000 --- a/app/service/view/config/index.html +++ /dev/null @@ -1,98 +0,0 @@ -{extend name='../../admin/view/main'} - -{block name="button"} - -{if auth("edit")} - -{/if} - -{/block} - -{block name="content"} -
- -
- 强烈建议安装 YAR 扩展来实现接口通信,SOAP 不能正常显示接口的异常信息 -
- -
-
-
-
- 开放平台服务 - AppID - -

开放平台服务 AppID,需要在微信开放平台获取

-
-
- 开放平台服务 - AppSecret - -

开放平台服务 AppSecret,需要在微信开放平台获取

-
-
- 开放平台消息校验 - Token - -

开发者在代替微信接收到消息时,用此 Token 来校验消息

-
-
- 开放平台消息加解密 - AesKey - -

在代替微信收发消息时使用,必须是长度为43位字母和数字组合的字符串

-
-
- -
-
-

授权发起页域名

- -

从本域名跳转到登录授权页才可以完成登录授权,无需填写域名协议前缀

-
-
- 授权事件接收地址 - -

用于接收取消授权通知、授权成功通知、授权更新通知、接收 TICKET 凭据

-
-
- 微信消息与事件接收 - -

通过该 URL 接收微信消息和事件推送,$APPID$ 将被替换为微信 AppId

-
-
-

客户端系统 Yar 模块接口

- -

客户端 Yar 接口,TOKEN 包含 class appid time nostr sign 的加密内容

-
-
-

客户端系统 Soap 模块接口

- -

客户端 Soap 接口,TOKEN 包含 class appid time nostr sign 的加密内容

-
-
-
-
-
-{/block} \ No newline at end of file diff --git a/app/service/view/not-auth.html b/app/service/view/not-auth.html deleted file mode 100644 index cdbc2ac76..000000000 --- a/app/service/view/not-auth.html +++ /dev/null @@ -1 +0,0 @@ -还没有授权,请授权公众号 \ No newline at end of file diff --git a/app/service/view/wechat/index.html b/app/service/view/wechat/index.html deleted file mode 100644 index 29762d4ec..000000000 --- a/app/service/view/wechat/index.html +++ /dev/null @@ -1,85 +0,0 @@ -{extend name='../../admin/view/main'} - -{block name="button"} - -{if auth("syncall")} - -{/if} - -{/block} - -{block name="content"} -
- {include file='wechat/index_search'} - - {notempty name='list'} - - - - - - - - - {/notempty} - - {foreach $list as $key=>$vo} - - - - - - - {/foreach} - -
接口信息服务号信息
-
- -
-
- 公众号APPID:{$vo.authorizer_appid}    调用次数:{$vo.total}
- 接口授权密钥:{$vo.appkey|default='未生成接口服务密码, 请稍候授权绑定'|raw}
- 消息推送接口:{$vo.appuri|default='未配置消息推送接口'|raw} -
-
-
- -
-
- 昵称:{$vo.nick_name|default='未获取到公众号昵称'|raw}
- 公司:{$vo.principal_name|default='未获取到公司名字'|raw}
- 状态:{if $vo.service_type eq 2}服务号{elseif $vo.service_type eq 3}小程序{else}订阅号{/if} / - {$vo.verify_type == -1 ? '未认证' : '已认证'} / - {if $vo.status eq 0}已禁用{elseif $vo.status eq 1}使用中{/if} -
-
- 账号:{$vo.user_name|default='--'}
- 日期:{$vo.create_at|format_datetime|str_replace=' ','
时间:',###|raw} -
- - {if $vo.status eq 1 and auth("state")} - 禁 用 - {elseif auth("state")} - 启 用 - {/if} - - - {if auth("remove")} - 删 除 - {/if} - - {if auth("sync")} - 同 步 - {/if} - - {if auth("clearquota")} - 清 零 - {/if} - -
- - {empty name='list'}没有记录哦{else}{$pagehtml|raw|default=''}{/empty} - -
- -{/block} \ No newline at end of file diff --git a/app/service/view/wechat/index_search.html b/app/service/view/wechat/index_search.html deleted file mode 100644 index e8ee1ace8..000000000 --- a/app/service/view/wechat/index_search.html +++ /dev/null @@ -1,76 +0,0 @@ -
- - 条件搜索 - - - -
- - \ No newline at end of file diff --git a/app/service/controller/Config.php b/app/wechat/controller/Fans.php similarity index 62% rename from app/service/controller/Config.php rename to app/wechat/controller/Fans.php index 77f5a2c5f..dd4b244b6 100644 --- a/app/service/controller/Config.php +++ b/app/wechat/controller/Fans.php @@ -13,51 +13,35 @@ // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin // +---------------------------------------------------------------------- -namespace app\service\controller; +namespace app\wechat\controller; use think\admin\Controller; /** - * 开放平台参数配置 - * Class Config - * @package app\service\controller + * 微信粉丝管理 + * Class Fans + * @package app\wechat\controller */ -class Config extends Controller +class Fans extends Controller { /** * 绑定数据表 * @var string */ - protected $table = 'WechatServiceConfig'; + protected $table = 'wechatFans'; /** - * 开放平台配置 + * 微信粉丝管理 * @auth true * @menu true - */ - public function index() - { - $this->title = '开放平台参数配置'; - $this->fetch(); - } - - /** - * 修改开放平台参数 - * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function edit() + public function index() { - $this->_applyFormToken(); - if ($this->request->isGet()) { - $this->fetch('form'); - } else { - $post = $this->request->post(); - foreach ($post as $k => $v) sysconf($k, $v); - $this->success('参数修改成功!'); - } + $this->title = '微信粉丝管理'; + $this->_query($this->table)->order('id desc')->page(); } } \ No newline at end of file diff --git a/app/wechat/service/WechatService.php b/app/wechat/service/WechatService.php new file mode 100644 index 000000000..299901df8 --- /dev/null +++ b/app/wechat/service/WechatService.php @@ -0,0 +1,150 @@ +getConfig()); + } else { + list($appid, $appkey) = [sysconf('wechat.appid'), sysconf('wechat.appkey')]; + $data = ['class' => $name, 'appid' => $appid, 'time' => time(), 'nostr' => uniqid()]; + $data['sign'] = md5("{$data['class']}#{$appid}#{$appkey}#{$data['time']}#{$data['nostr']}"); + $token = enbase64url(json_encode($data, JSON_UNESCAPED_UNICODE)); + if (class_exists('Yar_Client')) { + $url = "http://open.cuci.cc/service/api.client/yar?not_init_session=1&token={$token}"; + $client = new \Yar_Client($url); + } else { + $url = "http://open.cuci.cc/service/api.client/soap?not_init_session=1&token={$token}"; + $client = new \SoapClient(null, ['location' => $url, 'uri' => "thinkadmin"]); + } + try { + $exception = new \think\Exception($client->getMessage(), $client->getCode()); + } catch (\Exception $exception) { + $exception = null; + } + if ($exception instanceof \Exception) { + throw $exception; + } + return $client; + } + } + + /** + * 获取公众号配置参数 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getConfig() + { + return [ + 'token' => sysconf('wechat.token'), + 'appid' => sysconf('wechat.appid'), + 'appsecret' => sysconf('service.appsecret'), + 'encodingaeskey' => sysconf('service.encodingaeskey'), + 'cache_path' => $this->app->getRuntimePath() . 'wechat', + ]; + } +} \ No newline at end of file