From dfaafae0762b67e42eb29f7e8174cc103f99418d Mon Sep 17 00:00:00 2001 From: Anyon Date: Thu, 15 Mar 2018 20:53:20 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E7=A7=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=B1=BB=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/service/FansService.php | 123 --------------------- application/admin/service/MediaService.php | 101 ----------------- application/admin/service/TagsService.php | 69 ------------ 3 files changed, 293 deletions(-) delete mode 100644 application/admin/service/FansService.php delete mode 100644 application/admin/service/MediaService.php delete mode 100644 application/admin/service/TagsService.php diff --git a/application/admin/service/FansService.php b/application/admin/service/FansService.php deleted file mode 100644 index d7732cbb7..000000000 --- a/application/admin/service/FansService.php +++ /dev/null @@ -1,123 +0,0 @@ - $openid, 'appid' => sysconf('wechat_appid')]; - $user = Db::name('WechatFans')->where($map)->find(); - foreach (['country', 'province', 'city', 'nickname', 'remark'] as $k) { - isset($user[$k]) && $user[$k] = ToolsService::emojiDecode($user[$k]); - } - return $user; - } - - /** - * 同步所有粉丝记录 - * @param string $next_openid - * @return bool - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public static function sync($next_openid = '') - { - $wechat = WechatService::user(); - $result = $wechat->getUserList($next_openid); - if (empty($result['data']['openid'])) { - return false; - } - foreach (array_chunk($result['data']['openid'], 100) as $openids) { - foreach ($wechat->getBatchUserInfo($openids)['user_info_list'] as $user) { - if (false === self::set($user)) { - return false; - } - if ($result['next_openid'] === $user['openid']) { - unset($result['next_openid']); - } - } - } - return empty($result['next_openid']) ? true : self::sync($result['next_openid']); - } - - /** - * 同步获取黑名单信息 - * @param string $next_openid - * @return bool - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public static function syncBlack($next_openid = '') - { - $wechat = WechatService::user(); - $result = $wechat->getBlackList($next_openid); - foreach (array_chunk($result['data']['openid'], 100) as $openids) { - $info = $wechat->getBatchUserInfo($openids); - foreach ($info as $user) { - $user['is_black'] = '1'; - if (self::set($user) && $result['next_openid'] === $user['openid']) { - unset($result['next_openid']); - } - } - } - return empty($result['next_openid']) ? true : self::syncBlack($result['next_openid']); - } - -} \ No newline at end of file diff --git a/application/admin/service/MediaService.php b/application/admin/service/MediaService.php deleted file mode 100644 index 342c0dbf7..000000000 --- a/application/admin/service/MediaService.php +++ /dev/null @@ -1,101 +0,0 @@ -where(['id' => $id])->where($where)->find(); - $article_ids = explode(',', $data['article_id']); - $articles = Db::name('WechatNewsArticle')->whereIn('id', $article_ids)->select(); - $data['articles'] = []; - foreach ($article_ids as $article_id) { - foreach ($articles as $article) { - if (intval($article['id']) === intval($article_id)) { - unset($article['create_by'], $article['create_at']); - $article['content'] = htmlspecialchars_decode($article['content']); - $data['articles'][] = $article; - } - } - } - return $data; - } - - /** - * 上传图片到微信服务器 - * @param string $local_url 图文地址 - * @return string - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - */ - public static function uploadImage($local_url) - { - $media_url = Db::name('WechatNewsImage')->where(['md5' => md5($local_url)])->value('media_url'); - if (!empty($media_url)) { - return $media_url; - } - $result = WechatService::wechat()->upFile(base64_encode(file_get_contents($local_url)), $local_url); - $info = WechatService::media()->uploadImg($result['file']); - WechatService::wechat()->rmFile($local_url); - $data = ['local_url' => $local_url, 'media_url' => $info['url'], 'md5' => md5($local_url)]; - Db::name('WechatNewsImage')->insert($data); - return $info['url']; - } - - /** - * 上传图片永久素材,返回素材media_id - * @param string $local_url 文件URL地址 - * @param string $type 文件类型 - * @param array $video_info 视频信息 - * @return string|null - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public static function uploadForeverMedia($local_url, $type = 'image', $video_info = []) - { - $map = ['md5' => md5($local_url), 'appid' => sysconf('wechat_appid')]; - if (($media_id = Db::name('WechatNewsMedia')->where($map)->value('media_id'))) { - return $media_id; - } - $result = WechatService::wechat()->upFile(base64_encode(file_get_contents($local_url)), $local_url); - $result = WechatService::media()->addMaterial($result['file'], $type, $video_info); - WechatService::wechat()->rmFile($local_url); - $data = ['md5' => $map['md5'], 'type' => $type, 'appid' => $map['appid'], 'media_id' => $result['media_id'], 'local_url' => $local_url]; - isset($result['url']) && $data['media_url'] = $result['url']; - Db::name('WechatNewsMedia')->insert($data); - return $data['media_id']; - } - -} \ No newline at end of file diff --git a/application/admin/service/TagsService.php b/application/admin/service/TagsService.php deleted file mode 100644 index 52ec49ffc..000000000 --- a/application/admin/service/TagsService.php +++ /dev/null @@ -1,69 +0,0 @@ -getUserTagId($openid); - if (!is_array($tagsid)) { - return false; - } - $data = ['openid' => $openid, 'tagid_list' => join(',', $tagsid)]; - return DataService::save('WechatFans', $data, 'openid', ['appid' => sysconf('wechat_appid')]); - } - - /** - * 从微信服务器获取所有标签 - * @return bool - * @throws \WeChat\Exceptions\InvalidResponseException - * @throws \WeChat\Exceptions\LocalCacheException - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public static function sync() - { - $appid = sysconf('wechat_appid'); - $result = WechatService::tags()->getTags(); - Db::name('WechatFansTags')->where(['appid' => $appid])->delete(); - foreach (array_chunk($result['tags'], 100) as $list) { - foreach ($list as &$vo) { - $vo['appid'] = $appid; - } - Db::name('WechatFansTags')->insertAll($list); - } - return true; - } - -} \ No newline at end of file