TimApi.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. require_once(APP_ROOT_PATH.'system/tim/TimRestApi.php');
  3. /**
  4. * sdkappid 是app的sdkappid
  5. * identifier 是用户帐号
  6. * private_pem_path 为私钥在本地位置
  7. * server_name 是服务类型
  8. * command 是具体命令
  9. */
  10. function createTimAPI(){
  11. $m_config = load_auto_cache("m_config");//参数
  12. $sdkappid = $m_config['tim_sdkappid'];
  13. $identifier = $m_config['tim_identifier'];
  14. $ret = load_auto_cache("usersig", array("id"=>$identifier));
  15. if ($ret['status'] == 1){
  16. $private_pem_path = APP_ROOT_PATH."system/tim/ec_key.pem";
  17. if (!file_exists($private_pem_path)&&function_exists('log_err_file')) {
  18. log_err_file(array(__FILE__,__LINE__,__METHOD__,'system/tim/ec_key.pem,不存在'));
  19. }
  20. $api = createRestAPI();
  21. $api->init($sdkappid, $identifier);
  22. $api->set_user_sig($ret['usersig']);
  23. return $api;
  24. }else{
  25. //print_r($ret);
  26. //exit;
  27. return $ret;
  28. }
  29. /*
  30. $private_pem_path = APP_ROOT_PATH."system/tim/ec_key.pem";
  31. $api = createRestAPI();
  32. $api->init($sdkappid, $identifier);
  33. //echo 'private_pem_path:'.$private_pem_path;exit;
  34. if($private_pem_path != "")
  35. {
  36. //独立模式
  37. if(!file_exists($private_pem_path))
  38. {
  39. echo "私钥文件不存在, 请确保TimRestApiConfig.json配置字段private_pem_path正确\n";
  40. return;
  41. }
  42. $signature = get_signature();
  43. //echo $signature."<br>";
  44. $ret = $api->generate_user_sig($identifier, '36000', $private_pem_path, $signature);
  45. if($ret == null || strstr($ret[0], "failed")){
  46. echo "获取usrsig失败, 请确保TimRestApiConfig.json配置信息正确.\n";
  47. return -1;
  48. }
  49. }else{
  50. echo "请填写TimRestApiConfig.json中private_pem_path(独立模式)或者user_sig(托管模式)字段\n";
  51. return -1;
  52. }
  53. return $api;
  54. */
  55. }
  56. /*
  57. * signature为获取私钥脚本,详情请见 账号登录集成 http://avc.qcloud.com/wiki2.0/im/
  58. */
  59. function get_signature(){
  60. if(is_64bit()){
  61. if(PATH_SEPARATOR==':'){
  62. $signature = "signature/linux-signature64";
  63. }else{
  64. $signature = "signature\\windows-signature64.exe";
  65. }
  66. }else{
  67. if(PATH_SEPARATOR==':')
  68. {
  69. $signature = "signature/linux-signature32";
  70. }else{
  71. $signature = "signature\\windows-signature32.exe";
  72. }
  73. }
  74. return APP_ROOT_PATH."system/tim/".$signature;
  75. }
  76. ?>