PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > Laravel教程 > 正文

    Laravel整合腾讯云云通信PHP Server SDK

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:项目中使用了腾讯云的云通信做聊天功能,后台服务器需要维护一些数据,PHP Server SDK将一些常用的REST API封装成了函数,并以接口类的...
    项目中使用了腾讯云的云通信做聊天功能,后台服务器需要维护一些数据,PHP Server SDK将一些常用的REST API封装成了函数,并以接口类的方式暴露给开发者,这样就能更好的去维护聊天里的一些功能。

     查看地址 https://cloud.tencent.com/document/product/269/1538  

    下面讲讲如何调用

    1.把下载好的php server sdk 放到 laravel vendor 目录下

    2.新建一个类文件 代码如下:

    1. <?php 
    2. /** 
    3.  * Created by PhpStorm. 
    4.  * User: www.bcty365.com 
    5.  * Date: 2017/10/23 
    6.  * Time: 17:55 
    7.  */ 
    8. namespace App\ThinkClass; 
    9. require_once base_path('vendor/PhpServerSdk/TimRestApi.php'); 
    10. use TimRestAPI; 
    11. class TencentImClass extends TimRestAPI 
    12.     protected $api
    13.     protected $sdkappid
    14.     protected $identifier
    15.     protected $private_key_path
    16.     protected $signature
    17.     protected $usersig=''
    18.     public function __construct() 
    19.     { 
    20.         $this->sdkappid = 1400046248; 
    21.         $this->identifier = "admin"
    22.         $this->private_key_path = base_path('vendor/PhpServerSdk/private_key'); 
    23.         $this->signature = base_path('vendor/PhpServerSdk/signature/linux-signature64'); 
    24.         $this->api=new \TimRestAPI(); 
    25.         $this->usersig=env('TENCENT_SIG');//user_sig 如果不懂看看官方文档
    26.         $this->api->init($this->sdkappid,$this->identifier); 
    27.  
    28.     } 
    29.  
    30.     /** 
    31.      * 获取云通信IM sig 
    32.      * @return string 
    33.      */ 
    34.     public function userSig(){ 
    35.         $sig = $this->api->generate_user_sig($this->identifier, '',$this->private_key_path, $this->signature); 
    36.         return $sig
    37.     } 
    38.  
    39.  
    40.  

    3.使用如下,可以看到腾讯云云通信所有接口都可以使用了

    Laravel整合腾讯云云通信PHP Server SDK

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-153-6051-1.html
    相关热词搜索: Laravel 腾讯云云通信