<commit_before><?php

namespace App\Models;

use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ImUser extends Model
{
    use SoftDeletes;

    /**
     * 定义表名.
     *
     * @var string
     */
    protected $table = 'im_users';

    /**
     * 定义允许更新的字段.
     *
     * @var array
     */
    protected $fillable = ['username', 'im_password', 'is_disabled'];

    /**
     * 定义隐藏的字段.
     *
     * @var array
     */
    protected $hidden = ['is_disabled', 'deleted_at', 'username'];

    /**
     * 将字段调整为日期属性.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    /**
     * 定义im服务器的相关请求链接.
     *
     * @var array
     */
    protected $service_urls = [
        'base_url' => 'http://192.168.2.222:9900',
        'apis'     => [
            'users'        => '/users',
            'conversation' => '/conversations',
            'member'       => '/conversations/member',
            'limited'      => '/conversations/{cid}/limited-members',
            'message'      => '/conversations/{cid}/messages',
        ],
    ];

    /**
     * 对密码进行加密.
     *
     * @author martinsun <<EMAIL>>
     * @datetime 2017-01-09T09:53:25+080
     *
     * @version  1.0
     *
     * @param string $password 初始密码
     */
    public function setImPasswordAttribute($password = '')
    {
        $this->attributes['im_password'] = <PASSWORD>($password);
    }

    /**
     * 初始化IM用户.
     *
     * @author martinsun <<EMAIL>>
     * @datetime 2017-01-09T09:52:07+080
     *
     * @version  1.0
     *
     * @param int $user_id 本地用户id
     *
     * @return array IM用户信息
     */
    public function initImUser(int $user_id)
    {
        $client = new Client(['base_uri' => $this->service_urls['base_url']]);
        // $res = $client->request('post', $this->service_urls['apis']['users'], [
        //     'form_params' => [
        //         'uid' => 1002,
        //         'name' => '测试账号1002',
        //     ],
        //     'auth' => [
        //         'admin', '<PASSWORD>',
        //     ],
        // ]);
        // $body = $res->getBody();
        // $data = $body->getContents();

        $res = $client->request('post', $this->service_urls['apis']['conversation'], [
            'form_params' => [
                'type' => 0,
                'name' => '测试私有的对话',
                'pwd'  => '',
                'uids' => [1001, 1002],
            ],
            'auth' => [
                'admin', '<PASSWORD>',
            ],
        ]);
        $body = $res->getBody();
        $data = $body->getContents();
        return $data;
        $res = $client->request('post', $this->service_urls['apis']['conversation'], [
            'form_params' => [

            ],
            'auth' => [
                'admin', '<PASSWORD>',
            ],
        ]);
        return $res;
    }

    /**
     * 根据用户ID获取IM用户信息.
     *
     * @author martinsun <<EMAIL>>
     * @datetime 2017-01-09T13:46:40+080
     *
     * @version  1.0
     *
     * @param int $user_id 用户id
     *
     * @return array IM用户信息数组
     */
    public function getImUserByUserId(int $user_id)
    {<commit_msg>Apply fixes from StyleCI<commit_after><?php

namespace App\Models;

use GuzzleHttp\Client;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ImUser extends Model
{
    use SoftDeletes;

    /**
     * 定义表名.
     *
     * @var string
     */
    protected $table = 'im_users';

    /**
     * 定义允许更新的字段.
     *
     * @var array
     */
    protected $fillable = ['username', 'im_password', 'is_disabled'];

    /**
     * 定义隐藏的字段.
     *
     * @var array
     */
    protected $hidden = ['is_disabled', 'deleted_at', 'username'];

    /**
     * 将字段调整为日期属性.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    /**
     * 定义im服务器的相关请求链接.
     *
     * @var array
     */
    protected $service_urls = [
        'base_url' => 'http://192.168.2.222:9900',
        'apis'     => [
            'users'        => '/users',
            'conversation' => '/conversations',
            'member'       => '/conversations/member',
            'limited'      => '/conversations/{cid}/limited-members',
            'message'      => '/conversations/{cid}/messages',
        ],
    ];

    /**
     * 对密码进行加密.
     *
     * @author martinsun <<EMAIL>>
     * @datetime 2017-01-09T09:53:25+080
     *
     * @version  1.0
     *
     * @param string $password <PASSWORD>
     */
    public function setImPasswordAttribute($password = '')
    {
        $this->attributes['im_password'] = <PASSWORD>($password);
    }

    /**
     * 初始化IM用户.
     *
     * @author martinsun <<EMAIL>>
     * @datetime 2017-01-09T09:52:07+080
     *
     * @version  1.0
     *
     * @param int $user_id 本地用户id
     *
     * @return array IM用户信息
     */
    public function initImUser(int $user_id)
    {
        $client = new Client(['base_uri' => $this->service_urls['base_url']]);
        // $res = $client->request('post', $this->service_urls['apis']['users'], [
        //     'form_params' => [
        //         'uid' => 1002,
        //         'name' => '测试账号1002',
        //     ],
        //     'auth' => [
        //         'admin', '<PASSWORD>',
        //     ],
        // ]);
        // $body = $res->getBody();
        // $data = $body->getContents();

        $res = $client->request('post', $this->service_urls['apis']['conversation'], [
            'form_params' => [
                'type' => 0,
                'name' => '测试私有的对话',
                'pwd'  => '',
                'uids' => [1001, 1002],
            ],
            'auth' => [
                'admin', '<PASSWORD>',
            ],
        ]);
        $body = $res->getBody();
        $data = $body->getContents();

        return $data;
        $res = $client->request('post', $this->service_urls['apis']['conversation'], [
            'form_params' => [

            ],
            'auth' => [
                'admin', '<PASSWORD>',
            ],
        ]);

        return $res;
    }

    /**
     * 根据用户ID获取IM用户信息.
     *
     * @author martinsun <<EMAIL>>
     * @datetime 2017-01-09T13:46:40+080
     *
     * @version  1.0
     *
     * @param int $user_id 用户id
     *
     * @return array IM用户信息数组
     */
    public function getImUserByUserId(int $user_id)
    {
{'fraction_non_alphanumeric': 0.17683022417306787, 'fraction_numerical': 0.02759053143125882, 'mean_word_length': 1.5157728706624605, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6572847', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2258, 'n_words': 333}