mead 4 月之前
父节点
当前提交
74bd46081f
共有 1 个文件被更改,包括 57 次插入1 次删除
  1. 57 1
      storage/WatchController.php

+ 57 - 1
storage/WatchController.php

@@ -17,7 +17,7 @@ use Symfony\Component\Cache\Adapter\RedisAdapter;
  */
 class WatchController extends Controller
 {
-    use WeChat;
+//    use WeChat;
 
     /**
      * 处理微信消息
@@ -172,6 +172,62 @@ class WatchController extends Controller
     }
 
 
+    /**
+     * 编辑标签
+     * @param $account_name
+     * @param $tag_name
+     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public static function userAddTag($account_name, $open_id, $tag)
+    {
+        $app = self::getApp($account_name);
+
+
+        $re = $app->user_tag->tagUsers([$open_id], $tag);
+        return $re;
+    }
+
+    /**
+     * 移除标签
+     * @param $account_name
+     * @param $open_id
+     * @param $tag
+     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
+     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public static function userDelTag($account_name, $open_id, $tag)
+    {
+        $app = self::getApp($account_name);
+
+
+        $re = $app->user_tag->untagUsers([$open_id], $tag);
+        return $re;
+    }
+
+    /**
+     * @param $account_name
+     * @return \EasyWeChat\OfficialAccount\Application
+     */
+    public static function getApp($account_name){
+        $account = self::getAccount($account_name);
+        $app = Factory::officialAccount($account['settings']);
+//        $cache = new RedisAdapter(app('redis')->connection()->client());
+//        $app->rebind('cache', $cache);
+        return $app;
+    }
+
+    public static function getAccount($val)
+    {
+        if (is_numeric($val)) {
+            return Account::byIdGetModel($val);
+        }
+        return Account::byNameGetModel($val);
+    }
+
+
 
     /**
      * 处理微信消息【自动】