修改客服帐号
@param array $account
@return bool
@throws \yii\web\HttpException
429326
public function updateAccount(array $account)
    {
        $result = $this->wechat->httpRaw(self::WECHAT_ACCOUNT_UPDATE_PREFIX, $account, [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
91597
public function transferCustomerService($account = '')
    {
        $this->message = [
            'CreateTime'   => time(),
            'ToUserName'   => $this->getOpenid(),
            'FromUserName' => $this->getToOpenid(),
            'MsgType'      => 'transfer_customer_service',
        ];
        empty($account) || $this->message['TransInfo'] = ['KfAccount' => $account];
        return $this;
    }
1045390
public function setService($account = null) {
        if (!empty($account)) {
            $this->setData('TransInfo', [
                'KfAccount' => [
                    '@cdata' => $account
                ]
            ]);
        }
        return $this->setType(MessageEnum::Service);
    }
31325
protected function processRule($role) {
        if ($role === '*') {
            return true;
        }
        // 添加命令行过滤
        if ($role === 'cli') {
            return app('request')->isCli() ?:
                $this->redirectWithMessage('/',
                    __('The page need cli！')
                    , 4,'400');
        }
        if ($role === '?') {
            return auth()->guest() ?: $this->redirect('/');
        }
        if ($role === '@') {
            return $this->checkUser() ?: $this->redirectWithAuth();
        }
        if ($role === 'p' || $role === 'post') {
            return app('request')->isPost() ?: $this->redirectWithMessage('/',
                __('The page need post！')
                , 4,'400');
        }
        if ($role === '!') {
            return $this->redirectWithMessage('/',
                __('The page not found！')
                , 4, '413');
        }
        return $this->processCustomRule($role);
    }
1264174
public function create(AccountType $accountType): bool
    {
        // at least one of these fields is required
        $requirementsMet = !empty($accountType->password)
            || !empty($accountType->isStaff)
            || !empty($accountType->isActive);

        if (!$requirementsMet) {
            return false;
        }

        $uri = sprintf(
            '%s/accounts/' . $accountType->email . '/',
            $this->clipUri($this->client->getConfig('base_uri'))
        );

        $response = $this->client->put(
            $uri,
            [
                'headers'   => ['Accept' => 'application/json; charset=utf-8'],
                'multipart' => $accountType->toArray(Type::ARRAY_MULTI_PART),
            ]
        );

        return $response->getStatusCode() === 201;
    }
166404
public function login(array $identity = array())
    {
        if ($this->instance instanceof \Phavour\Session\Storage) {
            if ($this->instance->isLocked()) {
                $this->instance->unlock();
            }
            $this->instance->set('identity', $identity);
            $this->instance->set('roles', array());
            $this->instance->lock();
            return true;
        }

        return false;
    }
284994
public function getBalanceByAccount($account)
    {
        $args = [
            (string)$account,
            $this->minconf
        ];
        return $this->rpc->query("getBalance", $args);
    }
773231
public function updateAccounts(Models\Accounts $accounts)
    {
        $resource = 'accounts';
        $response = $this->sendPutRequest($resource, $accounts->toArray());
        $accountsResponse = new Models\UpdateAccountResponse($response);
        return $accountsResponse->getAccounts();
    }
130988
public function getAccountList()
    {
        $result = $this->wechat->httpGet(self::WECHAT_ACCOUNT_LIST_GET_PREFIX, [
            'access_token' => $this->wechat->getAccessToken()
        ]);
        return isset($result['kf_list']) ? $result['kf_list'] : false;
    }
239468
public function get_kf_session_list($kf_account)
    {
        $url = self::API_DOMAIN . 'customservice/kfsession/getsessionlist?access_token=' . $this->get_access_token() . '&kf_account=' . $kf_account;
        $res = HttpCurl::get($url, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }
        // 判断是否调用成功
        if (isset($res->sessionlist)) {
            return array(null, $res->sessionlist);
        } else {            
            return array($res, null);
        }
    }
173798
public function setAccountAvatar($accountName, $avatarPath)
    {
        $result = $this->wechat->httpPost(self::WECHAT_ACCOUNT_AVATAR_SET_PREFIX, [
            'media' => $this->wechat->uploadFile($avatarPath)
        ], [
            'access_token' => $this->wechat->getAccessToken(),
            'kf_account' => $accountName
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
266279
public function checkPassword($account, array $input)
    {
        $password = isset($input['password']) ? $input['password'] : false;

        return app('hash')->check($password, $account->password);
    }
575896
public function getRawChangeAddress($account)
    {
        $args = [
            (string)$account
        ];
        return $this->rpc->query(__FUNCTION__, $args);
    }
376327
public function findOneHavingAccount(Account $account)
    {
        $query = $this->createQuery();

        return $query->matching($query->contains('accounts', $account))->execute()->getFirst();
    }
304155
protected static function fetchUser(Social $account)
    {
        $user = User::findByEmail($account->email);

        if (null !== $user) {
            return $user;
        }

        /** @var \yuncms\user\models\User $user */
        $user = Yii::createObject([
            'class' => User::className(),
            'scenario' => 'connect',
            'username' => $account->username,
            'email' => $account->email
        ]);

        if (!$user->validate(['email'])) {
            $account->email = null;
        }

        if (!$user->validate(['name'])) {
            $account->username = null;
        }

        return $user->create() ? $user : false;
    }
953396
public function update(array $account)
    {
        if(!isset($account['account_id'])) {
            throw new MonetivoException('$account["account_id"] is required');
        }

        $id = $account['account_id'];
        unset($account['account_id']);
        $account['id'] = $id;

        return $this->merchantApi->call('put', 'accounts/' . $id, [
            'form_params' => $account
        ])->toArray();
    }
1203366
final public function insert(array $arr = [])
    {
        if (!$this->pdo) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_UNCONNECT_DATABASE);
        }
        $keys = [];
        if (count($arr) === 0) {
            return false;
        }
        $temp = $arr;
        $ele = array_pop($temp);
        if (is_array($ele)) {
            $keys = array_keys($ele);
        } else {
            $keys = array_keys($arr);
            $arr = [$arr];
        }
        //整理keys
        $params = array_map(function ($item) {
            return ':' . $item;
        }, $keys);
        $keys = array_map(function ($item) {
            return $this->formatColumn($item);
        }, $keys);

        $sql = "insert into " . $this->getTable() . " (" . implode(',', $keys) . ") values (" . implode(',', $params) . ")";
        $this->sql = $sql;
        /**
         * 只获取sql
         */
        if ($this->justSql) {
            return true;
        }
        $sth = $this->pdo->prepare($sql);
        $lastid = null;
        !$this->_begintransaction && count($arr) > 1 && $this->pdo->beginTransaction();
        foreach ($arr as $val) {
            $sth->execute($val);
            $lastid = $this->pdo->lastInsertId();
        }
        !$this->_begintransaction && count($arr) > 1 && $this->pdo->commit();
        $this->lastQueryAt = time();
        $this->resetCon();
        return $lastid;
    }