尊龙凯时人生就是搏

ÔõÑùÔÚThinkPHP6ÖÐʹÓÃÌÚѶÔÆIM¾ÙÐÐʵʱͨѶ²Ù×÷£¿

Ëæ×Å»¥ÁªÍøºÍÒƶ¯»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬ÊµÊ±Í¨Ñ¶ÊÖÒÕÒѾ­³ÉΪÁËÐí¶àÓ¦ÓÃÖв»¿É»òȱµÄÒ»»·¡£¶øÌÚѶÔÆim£¨¼´¼´Ê±Í¨Ñ¶im£©×÷Ϊº£ÄÚÁìÏȵÄʵʱͨѶƽ̨֮һ£¬Æ书ЧºÍÐÔÄÜÒ²»ñµÃÁËÆÕ±éµÄÈÏ¿É¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp6¿ò¼ÜÖÐʹÓÃÌÚѶÔÆim¾ÙÐÐʵʱͨѶ²Ù×÷¡£

Ò»¡¢ÉêÇëÌÚѶÔÆIMÕ˺Å

Ê×ÏÈ£¬ÐèÒªµ½ÌÚѶÔƹÙÍø£¨https://cloud.tencent.com/product/im£©¾ÙÐÐ×¢²áºÍÉêÇëIMЧÀÍ¡£×¢²áÍê³Éºó£¬µ½¿ØÖÆ̨Öн¨ÉèÓ¦Óò¢»ñÈ¡¶ÔÓ¦µÄSDKAppID¡¢IdentifierºÍSecretKey£¬ÕâЩÐÅÏ¢½«ÔÚºóÐøÉèÖÃÖÐÓõ½¡£

¶þ¡¢×°Öùٷ½IM SDK

ÌÚѶÔÆÌṩÁ˶àÖÖÓïÑÔµÄIM SDK¹©¿ª·¢ÕßʹÓ㬱¾ÎÄÖ÷ÒªÏÈÈݵÄÊÇPHP°æ±¾µÄIM SDK¡£½øÈë¹Ù·½GitHub¿â£¨https://github.com/tencentyun/TIMServer/tree/master/examples/php£©ÏÂÔØ×îеÄphp-sdk-v4¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

ÔÚThinkPHP6Ó¦ÓÃĿ¼Ï£¬Í¨¹ýcomposer×°ÖÃImSDK°ü£¬Ö´ÐÐÏÂÁcomposer require tencentyun/php-sdk-v4:latest£¬ÒÔ´ËʵÏÖIM SDKµÄ×Ô¶¯ÔØÈë¡£

Èý¡¢ÉèÖÃIM SDK

ÔÚThinkPHP6µÄÏîÄ¿ÉèÖÃÎļþ£¨Ä¬ÒÔΪconfig/app.php£©ÖУ¬Ìí¼ÓÈçÏÂÉèÖÃÏ

'imsdk' => [
    'sdk_app_id'   => 'SDKAppID',   // Ó¦ÓÃID
    'identifier'   => 'Identifier', // Óû§±êʶ
    'exp_time'     => 86400,        // Éí·Ýƾ֤ÓÐÓÃʱ¼ä£¨µ¥Î»£ºÃ룩
    'private_key'  => 'SecretKey',  // Ó¦ÓÃÃÜÔ¿
    'public_key'   => 'PublicKey',  // ¹«Ô¿£¬·Ç±ØÌîÏî
    'http_scheme'  => 'https',      // HTTPSЭÒé
    'account_type' => '1',          // Õ˺ÅÀàÐÍ£¬·Ç±ØÌîÏî
],

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬sdk_app_idΪÉêÇëIMЧÀÍʱ»ñµÃµÄÓ¦ÓÃID£¬identifierΪÓû§ÔÚÓ¦ÓÃÖеıêʶ£¬exp_timeΪÉí·Ýƾ֤µÄÓÐÓÃʱ¼ä£¬private_keyΪÉêÇëIMЧÀÍʱ»ñµÃµÄÓ¦ÓÃÃÜÔ¿£¬http_schemeΪͨѶЭÒ飬account_typeΪÕ˺ÅÀàÐÍ£¨Ä¬ÒÔΪ1£©¡£

ËÄ¡¢¼¯³ÉIM SDK

ÔÚThinkPHP6ÖпÉÒÔʹÓÃЧÀÍÈÝÆ÷À´¼¯³ÉIM SDK£¬Ê×ÏÈÐèÒªÔÚÏîÄ¿¸ùĿ¼Ï½¨ÉèÒ»¸öServiceĿ¼£¬ÔÚ¸ÃĿ¼ÏÂн¨Ò»¸öIMServiceÀà¡£¸ÃÀàµÄ´úÂëÈçÏ£º

<?php
namespace appservice;

use IlluminateSupportFacadesLog;
use TencentyunTIMTIMSdk;

class IMService
{
    private $sdk;

    public function __construct()
    {
        $sdk = new TIMSdk(config('imsdk.sdk_app_id'), config('imsdk.identifier'));
        $sdk->setPrivateKey(config('imsdk.private_key'));
        $sdk->setPublickey(config('imsdk.public_key', ''));
        $sdk->setExpire(config('imsdk.exp_time'));
        $sdk->setAccountType(config('imsdk.account_type', '1'));
        $sdk->setHttpScheme(config('imsdk.http_scheme', 'https'));
        $this->sdk = $sdk;
    }

    public function createGroup($name)
    {
        $group = $this->sdk->getGroup();
        $data = [
            'Type' => 'Public',   // Ⱥ×éÀàÐÍ£¨Public£º¹ûÕæȺ£©
            'Name' => $name,      // Ⱥ×éÃû³Æ
        ];
        return $group->create($data);
    }
}

µÇ¼ºó¸´ÖÆ

Õâ¸öÀàÖ÷ҪʵÏÖÁ˽¨ÉèÒ»¸öIMЧÀÍʵÀý£¬²¢·â×°ÁËһЩIM²Ù×÷£¬ÀýÈ罨ÉèȺ×é¡£

½ÓÏÂÀ´£¬ÔÚconfig/Ŀ¼Ï½¨ÉèÒ»¸öim.phpÎļþ£¬ÓÃÓÚÉèÖÃЧÀÍÈÝÆ÷µÄ°ó¶¨£¬´úÂëÈçÏ£º

<?php
use appserviceIMService;
return [
    'im' => IMService::class,
];

µÇ¼ºó¸´ÖÆ

Õâ¶Î´úÂ뽫IMServiceÀàÓëЧÀÍÈÝÆ÷ÖеÄÃû³Æim¾ÙÐа󶨡£

×îºó£¬ÔÚÐèҪʹÓÃIMЧÀ͵ĵط½£¬ÀýÈç¿ØÖÆÆ÷ÖУ¬¿ÉÒÔͨ¹ýÒÀÀµ×¢ÈëʹÓÃÒѰ󶨵ÄЧÀÍ£¬ÈçÏ£º

<?php
namespace appcontroller;

use appserviceIMService;
use thinkacadeRequest;

class Index
{
    public function index(IMService $im)
    {
        $groupName = Request::param('groupName');
        $result = $im->createGroup($groupName);
        if ($result['ErrorCode'] > 0) {
            return json([
                'code' => 0,
                'msg'  => $result['ErrorInfo'],
            ]);
        }
        return json([
            'code' => 1,
            'msg'  => '½¨ÉèȺ×éÀÖ³É',
            'data' => [
                'groupId' => $result['GroupId'],
            ],
        ]);
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëͨ¹ýÒÀÀµ×¢ÈëIMServiceЧÀÍ£¬ÔÚ¿ØÖÆÆ÷ÖÐʹÓøÃЧÀͽ¨ÉèÁËÒ»¸öÌÚѶÔÆIMµÄȺ×飬·µ»ØÁËȺ×éID¡£¿ÉÒÔƾ֤ÐèÒª¾ÙÐÐÆäËûIM²Ù×÷¡£

Îå¡¢½áÓï

±¾ÎÄÏÈÈÝÁËÔõÑùÔÚThinkPHP6ÖÐʹÓÃÌÚѶÔÆIM¾ÙÐÐʵʱͨѶ²Ù×÷¡£Í¨¹ýÉèÖᢼ¯³ÉºÍÒÀÀµ×¢È룬¿ÉÒÔÇáËɵØʹÓÃÌÚѶÔÆIM¾ÙÐÐÖÖÖÖʵʱͨѶ²Ù×÷£¬ÀýÈ罨ÉèȺ×é¡¢·¢ËÍÐÂÎŵÈ¡£±ðµÄ£¬»¹¿ÉÒÔƾ֤ÏêϸÐèÒª¾ÙÐиü¶àµÄIM¹¦Ð§¿ª·¢£¬ÀýÈçʵÏÖ¼´Ê±Í¨Ñ¶¡¢ÊÓƵͨ»°µÈ¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃÌÚѶÔÆIM¾ÙÐÐʵʱͨѶ²Ù×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ