|
@@ -15,9 +15,18 @@ use App\Repositories\Models\Base\Log;
|
|
|
use App\Repositories\Models\Wechat\Account;
|
|
|
use EasyWeChat\Factory;
|
|
|
use EasyWeChat\Kernel\Messages\Image;
|
|
|
+use Symfony\Component\Cache\Adapter\RedisAdapter;
|
|
|
|
|
|
trait WeChat
|
|
|
{
|
|
|
+ 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)) {
|
|
@@ -37,8 +46,9 @@ trait WeChat
|
|
|
*/
|
|
|
public static function tags($account_name)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+// $account = self::getAccount($account_name);
|
|
|
+// $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
|
|
|
$tag = $app->user_tag->list();
|
|
|
return $tag;
|
|
@@ -54,8 +64,7 @@ trait WeChat
|
|
|
*/
|
|
|
public static function addTag($account_name, $tag_name)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
|
|
|
$tag = $app->user_tag->create($tag_name);
|
|
|
return $tag['tag'];
|
|
@@ -72,8 +81,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function editTag($account_name, $wechat_id, $tag_name)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$tag = $app->user_tag->update($wechat_id, $tag_name);
|
|
|
return $tag;
|
|
@@ -89,8 +98,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function delTag($account_name, $wechat_id)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$tag = $app->user_tag->delete($wechat_id);
|
|
|
return $tag;
|
|
@@ -107,8 +116,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function userAddTag($account_name, $open_id, $tag)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$re = $app->user_tag->tagUsers([$open_id], $tag);
|
|
|
return $re;
|
|
@@ -116,8 +125,8 @@ trait WeChat
|
|
|
|
|
|
public static function usersAddTag($account_name, $open_ids, $tag)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$total = count($open_ids);
|
|
|
$total_page = ceil($total / 50);
|
|
@@ -141,8 +150,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function userDelTag($account_name, $open_id, $tag)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$re = $app->user_tag->untagUsers([$open_id], $tag);
|
|
|
return $re;
|
|
@@ -159,8 +168,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function users($account_name, $nextOpenId = null)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$users = $app->user->list($nextOpenId);
|
|
|
return $users;
|
|
@@ -174,8 +183,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function menus($account_name)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$list = $app->menu->list();
|
|
|
return $list;
|
|
@@ -190,8 +199,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function delAllMenus($account_name)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
$list = $app->menu->delete();
|
|
|
return $list;
|
|
@@ -208,8 +217,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function setMenus($account_name, $menus, $matchRule = false)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
|
|
|
if (!$matchRule) {
|
|
|
$list = $app->menu->create($menus);
|
|
@@ -233,8 +242,8 @@ trait WeChat
|
|
|
*/
|
|
|
public static function uploadRes($account_name, $type = 'image', $path)
|
|
|
{
|
|
|
- $account = self::getAccount($account_name);
|
|
|
- $app = Factory::officialAccount($account['settings']);
|
|
|
+ $app = self::getApp($account_name);
|
|
|
+
|
|
|
$result = false;
|
|
|
switch ($type) {
|
|
|
case 'image':
|