腾讯云 IM 服务端 SDK for Hyperf
腾讯云 IM.
普通 PHP 请使用 hedeqiang/ten-im 扩展
前提
使用本扩展前需要登录 即时通信 IM 控制台 创建应用,配置管理员、获取 app_id、Key 等关键信息
更多请查看并熟读 即时通信 IM 服务端API
REST API 接口列表
安装
$ composer require hedeqiang/im -vvv
发布配置
php bin/hyperf.php vendor:publish hedeqiang/im
编辑 .env
文件
SDK_APP_ID= IDENTIFIER= SECRET_KEY=
使用
获取用户在线状态
<?php declare(strict_types=1); namespace AppController; use HedeqiangIMExceptionsException; use HedeqiangIMExceptionsHttpException; use HedeqiangIMIM; use HyperfConfigAnnotationValue; class IndexController extends AbstractController { /** * @Value(key="im") */ protected $config; public function index() { $config = $this->config; $im = new IM($config); $params = [ 'To_Account' => ['hedeqiang'] ]; print_r($im->send('openim','querystate',$params)); } }
返回示例
{ "ActionStatus": "OK", "ErrorInfo": "", "ErrorCode": 0, "QueryResult": [{ "To_Account": "hedeqiang", "State": "Offline" }] }
设置资料
$params = [ 'From_Account' => 'hedeqiang', 'ProfileItem' => [ ['Tag' => 'Tag_Profile_IM_Nick', 'Value' => 'hedeqiang'], ['Tag' => 'Tag_Profile_IM_Gender', 'Value' => 'Gender_Type_Male'], ['Tag' => 'Tag_Profile_IM_BirthDay', 'Value' => 19940410], ['Tag' => 'Tag_Profile_IM_SelfSignature', 'Value' => '程序人生的寂静欢喜'], ['Tag' => 'Tag_Profile_IM_Image', 'Value' => 'http://img.58codes.com/202401/c0dwijnvsth1796.png'], ], ]; print_r($im->send('profile','portrait_set',$params));
返回示例:
{ "ActionStatus": "OK", "ErrorCode": 0, "ErrorInfo": "", "ErrorDisplay": "" }
单发单聊消息
$params = [ 'SyncOtherMachine' => 1, // 消息不同步至发送方 'From_Account' => 'hedeqiang', 'To_Account' => 'zhangsan', 'MsgRandom' => 1287657, 'MsgTimeStamp' => 1557387418, 'MsgBody' => [ [ 'MsgType' => 'TIMTextElem', 'MsgContent' => [ 'Text' => '晚上去撸串啊' ] ] ] ]; print_r($im->send('openim','sendmsg',$params));
返回示例:
{ "ActionStatus":"OK", "ErrorInfo":"", "ErrorCode":0, "MsgTime":1573179125, "MsgKey":"748144182_1287657_1573179125" }
其中
send
方法接收三个参数。第一个参数 $servicename : 内部服务名,不同的 servicename 对应不同的服务类型;第二个参数$command
:命令字,与 servicename 组合用来标识具体的业务功能;第三个参数为请求包主体
示例:
v4/im_open_login_svc/account_import
,其中im_open_login_svc
为servicename
;account_import
为command
请求包示例:
{ "From_Account":"id", "ProfileItem": [ { "Tag":"Tag_Profile_IM_Nick", "Value":"MyNickName" } ] }
更多用法请参考 REST API 接口列表
TODO
Contributing
You can contribute in one of three ways:
File bug reports using the issue tracker. Answer questions or fix bugs on the issue tracker. Contribute new features or update the wiki.The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
License
MIT
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。