TimRestApiGear.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php
  2. error_reporting(E_ALL^E_NOTICE^E_WARNING);
  3. header("Content-Type:text/html; charset=utf-8");
  4. require_once("TimRestApi.php");
  5. //开始时间
  6. $begin_time = microtime(true);
  7. /**
  8. * sdkappid 是app的sdkappid
  9. * identifier 是用户帐号
  10. * private_pem_path 为私钥在本地位置
  11. * server_name 是服务类型
  12. * command 是具体命令
  13. */
  14. $param = $GLOBALS['argv'];
  15. if(count($param) < 3){
  16. printf("默认从配置文件TimRestApiConfig.json读取配置信息,其中:\nidentifier 为APP管理员账户\n");
  17. printf('private_pem_path 为独立模式下私钥本地路径,托管模式请填""');
  18. printf("\n");
  19. printf('user_sig 为托管模式用户下载到的用户凭证,独立模式请填""');
  20. printf("\nusage:\n");
  21. printf(" php TimRestApiGear.php (server_name) (command) args...\neg:\n");
  22. printf(" php TimRestApiGear.php openim sendmsg (account_id) (receiver) (text_content)\n 单发消息\n");
  23. printf(" php TimRestApiGear.php openim sendmsg_pic (account_id) (receiver) (pic_path)\n 单发图片(图片不超过5M)\n");
  24. printf(" php TimRestApiGear.php openim batchsendmsg (account_id1,account_id2,...) (text_content)\n 批量发消息(接收者id组以逗号分隔)\n\n");
  25. printf(" php TimRestApiGear.php openim batchsendmsg_pic (account_id1,account_id2,...) (pic_path)\n 批量发图片(接收者id组以逗号分隔,图片不超过5M)\n\n");
  26. printf(" php TimRestApiGear.php im_open_login_svc account_import (identifier) (nick) (face_url)\n 独立模式同步帐号\n");
  27. printf(" php TimRestApiGear.php registration_service register_account (identifier) (identifierType) (password)\n 托管模式存量帐号导入\n");
  28. printf(" php TimRestApiGear.php profile portrait_get (account_id)\n 获取用户资料\n");
  29. printf(" php TimRestApiGear.php profile portrait_set (account_id) (new_name)\n 修改用户名称\n\n");
  30. printf(" php TimRestApiGear.php sns friend_import (account_id) (receiver)\n 建立好友关系\n");
  31. printf(" php TimRestApiGear.php sns friend_delete (account_id) (frd_id)\n 双向解除好友关系\n");
  32. printf(" php TimRestApiGear.php sns friend_delete_all (account_id)\n 解除用户所有好友关系\n");
  33. printf(" php TimRestApiGear.php sns friend_check (account_id) (to_account)\n 验证好友关系(默认双向验证)\n");
  34. printf(" php TimRestApiGear.php sns friend_get_all (account_id)\n 获取用户所有好友\n");
  35. printf(" php TimRestApiGear.php sns friend_get_list (account_id) (frd_id)\n 获取用户指定好友\n\n");
  36. printf(" php TimRestApiGear.php group_open_http_svc get_appid_group_list\n 获取APP中所有群组信息(默认获取50个)\n");
  37. printf(" php TimRestApiGear.php group_open_http_svc create_group (group_type) (group_name) (owner_id)\n 创建群组(max_member_num默认为500)\n");
  38. printf(" php TimRestApiGear.php group_open_http_svc change_group_owner (group_id) (new_owner)\n 转让群组\n");
  39. printf("Public类型群组验证方式默认为需要验证,Private类型默认为禁止申请,ChatRoom类型默认为自由加入)\n");
  40. printf(" php TimRestApiGear.php group_open_http_svc get_group_info (group_id)\n 获取指定群组信息\n");
  41. printf(" php TimRestApiGear.php group_open_http_svc get_group_member_info (group_id) (limit) (offset)\n 获取群组成员信息\n");
  42. printf(" php TimRestApiGear.php group_open_http_svc modify_group_base_info (group_id) (group_name)\n 修改群组名称\n");
  43. printf(" php TimRestApiGear.php group_open_http_svc add_group_member (group_id) (member_id) (silence)\n 添加群组成员\n");
  44. printf(" php TimRestApiGear.php group_open_http_svc delete_group_member (group_id) (member_id) (silence)\n 删除群组成员\n");
  45. printf(" php TimRestApiGear.php group_open_http_svc modify_group_member_info (group_id) (account_id) (role)\n 修改群组某成员身份\n");
  46. printf(" php TimRestApiGear.php group_open_http_svc destroy_group (group_id)\n 解散群组\n");
  47. printf(" php TimRestApiGear.php group_open_http_svc get_joined_group_list (account_id)\n 获取用户所加入的所有群组\n");
  48. printf(" php TimRestApiGear.php group_open_http_svc get_role_in_group (group_id) (member_id)\n 获取用户在群组中身份\n");
  49. printf(" php TimRestApiGear.php group_open_http_svc forbid_send_msg (group_id) (member_id) (second)\n 在群组中禁言用户\n");
  50. printf(" php TimRestApiGear.php group_open_http_svc send_group_msg (account_id) (group_id) (text_content)\n 群组中发送普通消息\n");
  51. printf(" php TimRestApiGear.php group_open_http_svc send_group_msg_pic (account_id) (group_id) (pic_path)\n 群组中发送图片(图片不超过5M)\n");
  52. printf(" php TimRestApiGear.php group_open_http_svc send_group_system_notification (group_id) (text_content) (receive_id)\n 群组中发送系统消息\n");
  53. printf(" php TimRestApiGear.php group_open_http_svc import_group_member (group_id) (member_id) (role)\n 导入群组成员(Role不填为Member,唯一可填值为Admin)\n");
  54. printf(" php TimRestApiGear.php group_open_http_svc import_group_msg (group_id) (from_account) (text)\n 导入群消息\n");
  55. printf(" php TimRestApiGear.php group_open_http_svc set_unread_msg_num (group_id) (member_account) (unread_msg_num)\n 设置成员未读计数\n");
  56. return;
  57. }
  58. #读取app配置文件
  59. $filename = "./TimRestApiConfig.json";
  60. $json_config = file_get_contents($filename);
  61. $app_config = json_decode($json_config, true);
  62. $sdkappid = $app_config["sdkappid"];
  63. $identifier = $app_config["identifier"];
  64. $private_pem_path = $app_config["private_pem_path"];
  65. $user_sig = $app_config["user_sig"];
  66. //print_r($app_config);exit;
  67. $api = createRestAPI();
  68. $api->init($sdkappid, $identifier);
  69. //echo 'private_pem_path:'.$private_pem_path;exit;
  70. if($private_pem_path != "")
  71. {
  72. //独立模式
  73. if(!file_exists($private_pem_path))
  74. {
  75. echo "私钥文件不存在, 请确保TimRestApiConfig.json配置字段private_pem_path正确\n";
  76. return;
  77. }
  78. /**
  79. * 获取usersig
  80. * 36000为usersig的保活期
  81. * signature为获取私钥脚本,详情请见 账号登录集成 http://avc.qcloud.com/wiki2.0/im/
  82. */
  83. if(is_64bit()){
  84. if(PATH_SEPARATOR==':'){
  85. $signature = "signature/linux-signature64";
  86. }else{
  87. $signature = "signature\\windows-signature64.exe";
  88. }
  89. }else{
  90. if(PATH_SEPARATOR==':')
  91. {
  92. $signature = "signature/linux-signature32";
  93. }else{
  94. $signature = "signature\\windows-signature32.exe";
  95. }
  96. }
  97. $ret = $api->generate_user_sig($identifier, '36000', $private_pem_path, $signature);
  98. if($ret == null || strstr($ret[0], "failed")){
  99. echo "获取usrsig失败, 请确保TimRestApiConfig.json配置信息正确\n";
  100. return -1;
  101. }
  102. }else if($user_sig != ""){
  103. //托管模式
  104. $ret = $api->set_user_sig($user_sig);
  105. if($ret == false){
  106. echo "设置usrsig失败, 请确保TimRestApiConfig.json配置信息正确\n";
  107. return -1;
  108. }
  109. }else{
  110. echo "请填写TimRestApiConfig.json中private_pem_path(独立模式)或者user_sig(托管模式)字段\n";
  111. return -1;
  112. }
  113. #构造命令字典
  114. $command_dic = array(
  115. "openim.sendmsg" => 'send_msg',
  116. "openim.sendmsg_pic" => 'send_msg_pic',
  117. "openim.batchsendmsg" => 'batch_sendmsg',
  118. "openim.batchsendmsg_pic" => 'batch_sendmsg_pic',
  119. "im_open_login_svc.account_import" => 'account_import',
  120. "registration_service.register_account" => 'register_account',
  121. "profile.portrait_get" => 'portrait_get',
  122. "profile.portrait_set" => 'portrait_set',
  123. "sns.friend_import" => 'friend_import',
  124. "sns.friend_delete" => 'friend_delete',
  125. "sns.friend_delete_all" => 'friend_delete_all',
  126. "sns.friend_check" => 'friend_check',
  127. "sns.friend_get_all" => 'friend_get_all',
  128. "sns.friend_get_list" => 'friend_get_list',
  129. "group_open_http_svc.get_appid_group_list" => 'get_appid_group_list',
  130. "group_open_http_svc.create_group" => 'create_group',
  131. "group_open_http_svc.change_group_owner" => 'change_group_owner',
  132. "group_open_http_svc.get_group_info" => 'get_group_info',
  133. "group_open_http_svc.get_group_member_info" => 'get_group_member_info',
  134. "group_open_http_svc.modify_group_base_info" => 'modify_group_base_info',
  135. "group_open_http_svc.add_group_member" => 'add_group_member',
  136. "group_open_http_svc.delete_group_member" => 'delete_group_member',
  137. "group_open_http_svc.modify_group_member_info" => 'modify_group_member_info',
  138. "group_open_http_svc.destroy_group" => 'destroy_group',
  139. "group_open_http_svc.get_joined_group_list" => 'get_joined_group_list',
  140. "group_open_http_svc.get_role_in_group" => 'get_role_in_group',
  141. "group_open_http_svc.forbid_send_msg" => 'forbid_send_msg',
  142. "group_open_http_svc.send_group_msg" => 'send_group_msg',
  143. "group_open_http_svc.send_group_msg_pic" => 'send_group_msg_pic',
  144. "group_open_http_svc.send_group_system_notification" => 'send_group_system_notification',
  145. "group_open_http_svc.import_group_member" => 'import_group_member',
  146. "group_open_http_svc.import_group_msg" => 'import_group_msg',
  147. "group_open_http_svc.set_unread_msg_num" => 'set_unread_msg_num'
  148. );
  149. #分发命令
  150. list($server_name, $command) = array($param[1], $param[2]);
  151. $command_key = $server_name . '.' . $command;
  152. $command_value = $command_dic[$command_key];
  153. $data_list = array();
  154. for ($i = 3; $i < $argc; $i++){
  155. array_push($data_list, $param[$i]);
  156. }
  157. //访问接口
  158. $ret = $command_value($api, $data_list);
  159. if(gettype($ret) == "string"){
  160. if(strstr($ret, "not enough")){
  161. return -1;
  162. }
  163. }
  164. //结果格式化为json,并打印
  165. echo "Response Body:\n";
  166. echo json_format($ret);
  167. echo "\n";
  168. $end_time = microtime(true);
  169. echo "Cost Time: ".(round($end_time-$begin_time,3)*1000)."毫秒\n";
  170. /**
  171. * 单发信息
  172. **/
  173. function send_msg($api, $data_list)
  174. {
  175. if(count($data_list) < 3){
  176. printf("openim.sendmsg 需要三个参数: account_id, receiver, text_content\n");
  177. return "Fail: not enough paragram for openim.sendmsg";
  178. }
  179. list($account_id, $receiver, $text_content) = $data_list;
  180. $ret = $api->openim_send_msg($account_id, $receiver, $text_content);
  181. return $ret;
  182. }
  183. /**
  184. * 单发图片
  185. **/
  186. function send_msg_pic($api, $data_list)
  187. {
  188. if(count($data_list) < 3){
  189. printf("openim.sendmsg_pic 需要三个参数: account_id, receiver, pic_path\n");
  190. return "Fail: not enough paragram for openim.sendmsg_pic";
  191. }
  192. list($account_id, $receiver, $pic_path) = $data_list;
  193. $ret = $api->openim_send_msg_pic($account_id, $receiver, $pic_path);
  194. return $ret;
  195. }
  196. /**
  197. * 批量发信息
  198. **/
  199. function batch_sendmsg($api, $data_list)
  200. {
  201. if(count($data_list) < 2){
  202. printf("openim.batchsendmsg 需要两个参数: account_id, text_content\n");
  203. return "Fail: not enough paragram for openim.batchsendmsg";
  204. }
  205. list($account_id_set, $text_content) = $data_list;
  206. $account_list = explode(",", $account_id_set);
  207. $ret = $api->openim_batch_sendmsg($account_list, $text_content);
  208. return $ret;
  209. }
  210. /**
  211. * 批量发图片
  212. **/
  213. function batch_sendmsg_pic($api, $data_list)
  214. {
  215. if(count($data_list) < 2){
  216. printf("openim.batchsendmsg 需要两个参数: account_id, text_content\n");
  217. return "Fail: not enough paragram for openim.batchsendmsg";
  218. }
  219. list($account_id_set, $pic_path) = $data_list;
  220. $account_list = explode(",", $account_id_set);
  221. $ret = $api->openim_batch_sendmsg_pic($account_list, $pic_path);
  222. return $ret;
  223. }
  224. /**
  225. * 独立模式帐号同步
  226. **/
  227. function account_import($api, $data_list)
  228. {
  229. if(count($data_list) < 3){
  230. printf("profile.portrait_get 需要三个参数: 帐号id, 用户昵称, 头像url\n");
  231. return "Fail: not enough paragram for im_open_login_svc.account_import";
  232. }
  233. list($identifier, $nick, $face_url) = $data_list;
  234. $ret = $api->account_import($identifier, $nick, $face_url);
  235. return $ret;
  236. }
  237. /**
  238. * 托管模式存量帐号导入
  239. **/
  240. function register_account($api, $data_list)
  241. {
  242. if(count($data_list) < 3){
  243. printf("profile.portrait_get 需要三个参数: 帐号id, 帐号类型, 帐号密码\n");
  244. return "Fail: not enough paragram for registration_service.register_account";
  245. }
  246. list($identifier, $identifier_type, $password) = $data_list;
  247. $ret = $api->register_account($identifier, $identifier_type, $password);
  248. return $ret;
  249. }
  250. /**
  251. * 获取用户信息
  252. * account_list 为要拉取的用户id集合
  253. * tag_list 为选项字段,指明要拉取的信息,比如昵称
  254. **/
  255. function portrait_get($api, $data_list)
  256. {
  257. if(count($data_list) < 1){
  258. printf("profile.portrait_get 需要一个参数: 帐号id\n");
  259. return "Fail: not enough paragram for profile.portrait_get";
  260. }
  261. list($account_id) = $data_list;
  262. $ret = $api->profile_portrait_get($account_id);
  263. return $ret;
  264. }
  265. /**
  266. * 设置用户信息
  267. **/
  268. function portrait_set($api, $data_list)
  269. {
  270. if(count($data_list) < 1){
  271. printf("profile.portrait_set 需要两个参数: 帐号id, 新昵称\n");
  272. return "Fail: not enough paragram for profile.portrait_set";
  273. }
  274. list($account_id, $new_name) = $data_list;
  275. $ret = $api->profile_portrait_set($account_id, $new_name);
  276. return $ret;
  277. }
  278. /**
  279. * 建立好友关系
  280. **/
  281. function friend_import($api, $data_list)
  282. {
  283. if(count($data_list) < 2){
  284. printf("sns.friend_import 需要两个参数: 帐号id, 需要添加的好友id\n");
  285. return "Fail: not enough paragram for sns.friend_import";
  286. }
  287. list($account_id, $receiver) = $data_list;
  288. $ret = $api->sns_friend_import($account_id, $receiver);
  289. return $ret;
  290. }
  291. /**
  292. * 解除好友关系
  293. **/
  294. function friend_delete($api, $data_list)
  295. {
  296. if(count($data_list) < 2){
  297. printf("sns.friend_delete 需要两个参数: 帐号id, 需要删除的好友id\n");
  298. return "Fail: not enough paragram for sns.friend_delete";
  299. }
  300. list($account_id, $frd_id) = $data_list;
  301. $ret = $api->sns_friend_delete($account_id, $frd_id);
  302. return $ret;
  303. }
  304. /**
  305. * 解除用户所有好友关系
  306. **/
  307. function friend_delete_all($api, $data_list)
  308. {
  309. if(count($data_list) < 1){
  310. printf("sns.friend_delete_all 需要一个参数: 帐号id\n");
  311. return "Fail: not enough paragram for sns.friend_delete_all";
  312. }
  313. list($account_id) = $data_list;
  314. $ret = $api->sns_friend_delete_all($account_id);
  315. return $ret;
  316. }
  317. /**
  318. * 校验好友关系
  319. **/
  320. function friend_check($api, $data_list)
  321. {
  322. if(count($data_list) < 2){
  323. printf("sns.friend_check 需要两个参数: 帐号id, 校验对象id\n");
  324. return "Fail: not enough paragram for sns.friend_check";
  325. }
  326. list($account_id, $to_account) = $data_list;
  327. $ret = $api->sns_friend_check($account_id, $to_account);
  328. return $ret;
  329. }
  330. /**
  331. * 获取用户全部好友
  332. **/
  333. function friend_get_all($api, $data_list)
  334. {
  335. if(count($data_list) < 2){
  336. printf("sns.friend_get_all 需要一个参数: 帐号id\n");
  337. return "Fail: not enough paragram for sns.friend_get_all";
  338. }
  339. list($account_id) = $data_list;
  340. $ret = $api->sns_friend_get_all($account_id);
  341. return $ret;
  342. }
  343. /**
  344. * 获取用户指定好友
  345. **/
  346. function friend_get_list($api, $data_list)
  347. {
  348. if(count($data_list) < 2){
  349. printf("sns.friend_get_list 需要两个参数: 帐号id, 需要被拉取的好友id\n");
  350. return "Fail: not enough paragram for sns.friend_get_list";
  351. }
  352. list($account_id, $frd_id) = $data_list;
  353. $ret = $api->sns_friend_get_list($account_id, $frd_id);
  354. return $ret;
  355. }
  356. /**
  357. * 获取app中所有群组(高级接口)a
  358. **/
  359. function get_appid_group_list($api, $data_list)
  360. {
  361. $ret = $api->group_get_appid_group_list();
  362. return $ret;
  363. }
  364. /**
  365. * 创建群
  366. **/
  367. function create_group($api, $data_list)
  368. {
  369. if(count($data_list) < 2){
  370. printf("group_open_http_svc.create_group 至少需要2个参数: 群类型,群名称\n");
  371. return "Fail: not enough paragram for group_open_http_svc.create_group";
  372. }
  373. list($group_type, $group_name, $owner_id) = $data_list;
  374. $ret = $api->group_create_group($group_type, $group_name, $owner_id);
  375. return $ret;
  376. }
  377. /**
  378. * 转让群
  379. **/
  380. function change_group_owner($api, $data_list)
  381. {
  382. if(count($data_list) < 2){
  383. printf("group_open_http_svc.create_group 至少需要2个参数: 群id,新群主id\n");
  384. return "Fail: not enough paragram for group_open_http_svc.change_group_owner?";
  385. }
  386. list($group_type, $group_name, $owner_id) = $data_list;
  387. $ret = $api->group_change_group_owner($group_type, $group_name, $owner_id);
  388. return $ret;
  389. }
  390. /**
  391. * 获取群组详细信息
  392. **/
  393. function get_group_info($api, $data_list)
  394. {
  395. if(count($data_list) < 1){
  396. printf("group_open_http_svc.get_group_info 需要至少一个参数: 群id\n");
  397. return "Fail: not enough paragram for group_open_http_svc.get_group_info";
  398. }
  399. list($group_id) = $data_list;
  400. $ret = $api->group_get_group_info($group_id);
  401. return $ret;
  402. }
  403. /**
  404. * 获取群组成员详细资料
  405. * limit, offset字段分别表示最大数量和偏移量
  406. **/
  407. function get_group_member_info($api, $data_list)
  408. {
  409. if(count($data_list) < 1){
  410. printf("group_open_http_svc.get_group_member_info 需要至少一个参数: 群id\n");
  411. return "Fail: not enough paragram for group_open_http_svc.get_group_member_info";
  412. }else{
  413. list($group_id, $limit, $offset) = $data_list;
  414. $ret = $api->group_get_group_member_info($group_id, $limit, $offset);
  415. }
  416. return $ret;
  417. }
  418. /**
  419. * 修改群组资料
  420. * 这里只修改群组名字
  421. **/
  422. function modify_group_base_info($api, $data_list)
  423. {
  424. if(count($data_list) < 1){
  425. printf("group_open_http_svc.modify_group_base_info 需要至少一个参数: 群id\n");
  426. return "Fail: not enough paragram for group_open_http_svc.modify_group_base_info";
  427. }
  428. list($group_id, $group_name) = $data_list;
  429. $ret = $api->group_modify_group_base_info($group_id, $group_name);
  430. return $ret;
  431. }
  432. /*
  433. * 增加群组成员
  434. **/
  435. function add_group_member($api, $data_list)
  436. {
  437. if(count($data_list) < 2){
  438. printf("group_open_http_svc.add_group_member 需要至少两个参数: 群id, 用户id\n");
  439. return "Fail: not enough paragram for group_open_http_svc.add_group_member";
  440. }
  441. list($group_id, $member_id, $silence) = $data_list;
  442. $ret = $api->group_add_group_member($group_id, $member_id, $silence);
  443. return $ret;
  444. }
  445. /*
  446. * 删除群组成员
  447. * mem_list为增加用户列表,这里只有一个用户
  448. **/
  449. function delete_group_member($api, $data_list)
  450. {
  451. if(count($data_list) < 2){
  452. printf("group_open_http_svc.delete_group_member 需要至少两个参数: 群id, 用户id\n");
  453. return "Fail: not enough paragram for group_open_http_svc.delete_group_member";
  454. }else{
  455. list($group_id, $member_id, $silence) = $data_list;
  456. $ret = $api->group_delete_group_member($group_id, $member_id, $silence);
  457. }
  458. return $ret;
  459. }
  460. /*
  461. * 修改群组成员身份
  462. **/
  463. function modify_group_member_info($api, $data_list)
  464. {
  465. if(count($data_list) < 3){
  466. printf("group_open_http_svc.modify_group_member_info 需要至少两个参数: 群id, 用户id, 身份标识\n");
  467. return "Fail: not enough paragram for group_open_http_svc.modify_group_member_info";
  468. }else{
  469. list($group_id, $account_id, $role) = $data_list;
  470. $ret = $api->group_modify_group_member_info($group_id, $account_id, $role);
  471. }
  472. return $ret;
  473. }
  474. /*
  475. * 解散群组
  476. **/
  477. function destroy_group($api, $data_list)
  478. {
  479. if(count($data_list) < 1){
  480. printf("group_open_http_svc.destroy_group 需要至少一个参数: 群id\n");
  481. return "Fail: not enough paragram for group_open_http_svc.destroy_group";
  482. }else{
  483. list($group_id) = $data_list;
  484. $ret = $api->group_destroy_group($group_id);
  485. }
  486. return $ret;
  487. }
  488. /*
  489. * 获取某用户加入的群组
  490. **/
  491. function get_joined_group_list($api, $data_list)
  492. {
  493. if(count($data_list) < 1){
  494. printf("group_open_http_svc.get_joined_group_list 需要至少一个参数: 用户id\n");
  495. return "Fail: not enough paragram for group_open_http_svc.get_joined_group_list";
  496. }
  497. list($account_id) = $data_list;
  498. $ret = $api->group_get_joined_group_list($account_id);
  499. return $ret;
  500. }
  501. /*
  502. * 查询用户在某个群中身份
  503. **/
  504. function get_role_in_group($api, $data_list)
  505. {
  506. if(count($data_list) < 2){
  507. printf("group_open_http_svc.get_role_in_group 需要至少两个参数: 群id, 用户id\n");
  508. return "Fail: not enough paragram for group_open_http_svc.get_role_in_group";
  509. }else{
  510. list($group_id, $member_id) = $data_list;
  511. $ret = $api->group_get_role_in_group($group_id, $member_id);
  512. }
  513. return $ret;
  514. }
  515. /*
  516. * 批量禁言/取消禁言
  517. **/
  518. function forbid_send_msg($api, $data_list)
  519. {
  520. if(count($data_list) < 3){
  521. printf("group_open_http_svc.forbid_send_msg 需要至少两个参数: 群id, 用户id, 禁言时间(秒)\n");
  522. return "Fail: not enough paragram for group_open_http_svc.forbid_send_msg";
  523. }
  524. list($group_id, $member_id, $second) = $data_list;
  525. $ret = $api->group_forbid_send_msg($group_id, $member_id, $second);
  526. return $ret;
  527. }
  528. /**
  529. * 在某一群组里发普通消息
  530. **/
  531. function send_group_msg($api, $data_list)
  532. {
  533. if(count($data_list) < 2){
  534. printf("group_open_http_svc.open_send_group_msg 需要至少两个参数: 群组id, 文本内容\n");
  535. return "Fail: not enough paragram for group_open_http_svc.open_send_group_msg";
  536. }
  537. list($account_id, $group_id, $text_content) = $data_list;
  538. $ret = $api->group_send_group_msg($account_id, $group_id, $text_content);
  539. return $ret;
  540. }
  541. /**
  542. * 在某一群组里发送图片
  543. **/
  544. function send_group_msg_pic($api, $data_list)
  545. {
  546. if(count($data_list) < 3){
  547. printf("group_open_http_svc.open_send_group_msg_pic 需要至少三个参数: 发送者id, 群组id, 图片本地路径\n");
  548. return "Fail: not enough paragram for group_open_http_svc.open_send_group_msg_pic";
  549. }
  550. list($account_id, $group_id, $pic_path) = $data_list;
  551. $ret = $api->group_send_group_msg_pic($account_id, $group_id, $pic_path);
  552. return $ret;
  553. }
  554. /**
  555. * 在某一群组里发系统消息
  556. **/
  557. function send_group_system_notification($api, $data_list)
  558. {
  559. if(count($data_list) < 2){
  560. printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 文本内容\n");
  561. return "Fail: not enough paragram for group_open_http_svc.send_group_system_notification";
  562. }
  563. list($group_id, $text_content, $receiver_id) = $data_list;
  564. //默认为空,发送全员
  565. $ret = $api->group_send_group_system_notification($group_id, $text_content, $receiver_id);
  566. return $ret;
  567. }
  568. /**
  569. * 导入群成员
  570. **/
  571. function import_group_member($api, $data_list)
  572. {
  573. if(count($data_list) < 2){
  574. printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 成员id\n");
  575. return "Fail: not enough paragram for group_open_http_svc.import_group_member";
  576. }
  577. if(count($data_list) == 2)
  578. {
  579. list($group_id, $member_id) = $data_list;
  580. }else
  581. {
  582. list($group_id, $member_id, $role) = $data_list;
  583. }
  584. $role = null;
  585. $ret = $api->group_import_group_member($group_id, $member_id, $role);
  586. return $ret;
  587. }
  588. /**
  589. * 导入群消息
  590. **/
  591. function import_group_msg($api, $data_list)
  592. {
  593. if(count($data_list) < 3){
  594. printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 消息发送者, 文本内容\n");
  595. return "Fail: not enough paragram for group_open_http_svc.import_group_msg";
  596. }
  597. list($group_id, $from_account, $text) = $data_list;
  598. $ret = $api->group_import_group_msg($group_id, $from_account, $text);
  599. return $ret;
  600. }
  601. /**
  602. * 导入群消息
  603. **/
  604. function set_unread_msg_num($api, $data_list)
  605. {
  606. if(count($data_list) < 3){
  607. printf("group_open_http_svc.send_group_system_notification 需要至少两个参数: 群组id, 成员id, 群内身份\n");
  608. return "Fail: not enough paragram for group_open_http_svc.set_unread_msg_num";
  609. }
  610. list($group_id, $member_account, $unread_msg_num) = $data_list;
  611. //默认为空,发送全员
  612. $ret = $api->group_set_unread_msg_num($group_id, $member_account, $unread_msg_num);
  613. return $ret;
  614. }
  615. ?>