ServiceCorpTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php /*
  2. * Copyright (C) 2017 All rights reserved.
  3. *
  4. * @File ServiceCorpTest.php
  5. * @Brief
  6. * @Author abelzhu, abelzhu@tencent.com
  7. * @Version 1.0
  8. * @Date 2017-12-26
  9. *
  10. */
  11. include_once("../src/CorpAPI.class.php");
  12. include_once("../src/ServiceCorpAPI.class.php");
  13. include_once("../src/ServiceProviderAPI.class.php");
  14. try {
  15. $authCorpId = "AUTH_CORPID";
  16. $authAgentId = 1000040;
  17. // 下面是第三方应用接口的使用
  18. //
  19. $ServiceCorpAPI = new ServiceCorpAPI(
  20. "SUITE_ID",
  21. "SUITE_SECRET",
  22. "SUITE_TICKET"
  23. );
  24. $pre_auth_code = $ServiceCorpAPI->GetPreAuthCode();
  25. echo $pre_auth_code . "\n";
  26. //
  27. $SetSessionInfoReq = new SetSessionInfoReq();
  28. {
  29. $SetSessionInfoReq->pre_auth_code = $pre_auth_code;
  30. $session_info = new SessionInfo();
  31. {
  32. $session_info->appid = array(1, 2, 3, 4, 5, 6, 7);
  33. $session_info->auth_type = 0;
  34. }
  35. $SetSessionInfoReq->session_info = $session_info;
  36. }
  37. $ServiceCorpAPI->SetSessionInfo($SetSessionInfoReq);
  38. //
  39. $GetAdminListRsp = $ServiceCorpAPI->GetAdminList($authCorpId, $authAgentId);
  40. var_dump($GetAdminListRsp);
  41. // permanentCode 的获取方法
  42. //
  43. $temp_auth_code = "TEMP_AUTH_CODE";
  44. $GetPermanentCodeRsp = $ServiceCorpAPI->GetPermanentCode($temp_auth_code);
  45. var_dump($GetPermanentCodeRsp);
  46. $permanentCode = $GetPermanentCodeRsp->permanent_code;
  47. $GetAuthInfoRsp = $ServiceCorpAPI->GetAuthInfo($authCorpId, $permanentCode);
  48. var_dump($GetAuthInfoRsp);
  49. //
  50. $code = "xxxxxxxxxx";
  51. $GetUserinfoBy3rdRsp = $ServiceCorpAPI->GetUserinfoBy3rd($code);
  52. var_dump($GetUserinfoBy3rdRsp);
  53. //
  54. $user_ticket = $GetUserInfoByCode->user_ticket;
  55. if ( ! is_null($user_ticket)) {
  56. $GetUserDetailBy3rdRsp = $ServiceCorpAPI->GetUserDetailBy3rd($user_ticket);
  57. var_dump($GetUserDetailBy3rdRsp);
  58. }
  59. } catch (Exception $e) {
  60. echo $e->getMessage() . "\n";
  61. }
  62. try { // 第三方服务商使用永久授权码调用企业接口
  63. $authCorpId = "AUTH_CORPID";
  64. $permanentCode = "PERMANENT_CODE";
  65. $authAgentId = 1000040;
  66. $ServiceCorpAPI = new ServiceCorpAPI(
  67. "SUITE_ID",
  68. "SUITE_SECRET",
  69. "SUITE_TICKET", // suite_ticket
  70. $authCorpId,
  71. $permanentCode
  72. );
  73. $message = new Message();
  74. {
  75. $message->sendToAll = false;
  76. $message->touser = array("abelzhu", "ShengbenZhu");
  77. $message->toparty = array(1, 2, 1111, 3333);
  78. $message->totag= array(3, 4, 22233332, 33334444);
  79. $message->agentid = $authAgentId;
  80. $message->safe = 0;
  81. $message->messageContent = new NewsMessageContent(
  82. array(
  83. new NewsArticle("title_1", "description", "url", "picurl", "btntxt"),
  84. new NewsArticle("title_2", "description", "url", "picurl", "btntxt")
  85. )
  86. );
  87. }
  88. $ServiceCorpAPI->MessageSend($message, $invalidUserIdList, $invalidPartyIdList, $invalidTagIdList);
  89. } catch (Exception $e) {
  90. echo $e->getMessage() . "\n";
  91. }