导读:项目中使用了腾讯云的云通信做聊天功能,后台服务器需要维护一些数据,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.新建一个类文件 代码如下:
- <?php
-
-
-
-
-
-
- namespace App\ThinkClass;
- require_once base_path('vendor/PhpServerSdk/TimRestApi.php');
- use TimRestAPI;
- class TencentImClass extends TimRestAPI
- {
- protected $api;
- protected $sdkappid;
- protected $identifier;
- protected $private_key_path;
- protected $signature;
- protected $usersig='';
- public function __construct()
- {
- $this->sdkappid = 1400046248;
- $this->identifier = "admin";
- $this->private_key_path = base_path('vendor/PhpServerSdk/private_key');
- $this->signature = base_path('vendor/PhpServerSdk/signature/linux-signature64');
- $this->api=new \TimRestAPI();
- $this->usersig=env('TENCENT_SIG');//user_sig 如果不懂看看官方文档
- $this->api->init($this->sdkappid,$this->identifier);
-
- }
-
-
-
-
-
- public function userSig(){
- $sig = $this->api->generate_user_sig($this->identifier, '',$this->private_key_path, $this->signature);
- return $sig;
- }
-
-
-
- }
3.使用如下,可以看到腾讯云云通信所有接口都可以使用了