AghApiService.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: guanxl
  5. * Date: 2018/5/23
  6. * Time: 18:13
  7. */
  8. namespace App\Services;
  9. use App\Common\Curl;
  10. use App\Common\Singleton;
  11. class AghApiService
  12. {
  13. use Singleton;
  14. protected $configs;
  15. public function __construct($configs=[])
  16. {
  17. if(empty($configs)){
  18. $configs = config('agh');
  19. }
  20. $this->configs = $configs;
  21. }
  22. /**
  23. * 获得签名信息
  24. * @param $name
  25. * @param $gets
  26. * @param array $posts
  27. * @return string
  28. */
  29. protected function getSignUri($name,$gets,$posts=[]){
  30. $gets["partnerId"] = $this->configs["api_partner_id"];
  31. $gets["name"] = $name;
  32. $gets["version"] = $this->configs["api_version"];
  33. $gets["expires"] = time()+3600;
  34. $gets["nonce"] = uniqid();
  35. $array=array_merge($gets,$posts);
  36. ksort($array);
  37. $str = "";
  38. foreach ($array as $key=>$value){
  39. $str = $str . $key . '=' . $value . '&';
  40. }
  41. $str = substr($str, 0,strlen($str)-1);
  42. $signature = hash_hmac('SHA256',$str, $this->configs["api_key"]);
  43. $getUri="";
  44. foreach ($gets as $key=>$value){
  45. $getUri = $getUri . $key . '=' . $value . '&';
  46. }
  47. return $getUri."signature=".$signature;
  48. }
  49. /**
  50. * 获得用户信息
  51. * @param $gCorpId
  52. * @param $guid
  53. * @return mixed
  54. */
  55. public function getUserDetail($gCorpId,$guid){
  56. $name="b.getUserDetail";
  57. $posts = [
  58. "corpId" => $gCorpId,
  59. "guid" => $guid
  60. ];
  61. $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
  62. $curl = new Curl($uri);
  63. $ret = json_decode($curl->httpPost($posts),true);
  64. return $ret;
  65. }
  66. /**
  67. * 获得企业列表
  68. * @param $page8
  69. * @param $pageSize
  70. * @return mixed
  71. */
  72. public function getCorpList($page,$pageSize){
  73. $name="b.getCorpList";
  74. $posts = [
  75. "page" => $page,
  76. "pageSize" => $pageSize
  77. ];
  78. $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
  79. $curl = new Curl($uri);
  80. $ret = json_decode($curl->httpPost($posts),true);
  81. return $ret;
  82. }
  83. /**
  84. * 获得企业信息
  85. * @param $gCorpId
  86. * @return mixed
  87. */
  88. public function getCorpInfo($gCorpId){
  89. $name="b.getCorpInfo";
  90. $posts = [
  91. "enterpriseId" => $gCorpId
  92. ];
  93. $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
  94. $curl = new Curl($uri);
  95. $ret = json_decode($curl->httpPost($posts),true);
  96. return $ret;
  97. }
  98. /**
  99. * 获取微信access_token
  100. * @param $appId
  101. * @param $gCorpId
  102. * @return mixed
  103. */
  104. public function getWechatToken($gCorpId,$appId){
  105. $name="b.wechat.getToken";
  106. $posts = [
  107. "appId" => $appId,
  108. "corpId" => $gCorpId
  109. ];
  110. $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
  111. $curl = new Curl($uri);
  112. $ret = json_decode($curl->httpPost($posts),true);
  113. return $ret;
  114. }
  115. /**
  116. * 获取企业微信access_token
  117. * @param $qyCorpId
  118. * @param $suiteId
  119. * @return mixed
  120. */
  121. public function getWesuitToken($qyCorpId,$suiteId){
  122. $name="b.wesuit.getToken";
  123. $posts = [
  124. "qy_corpid" => $qyCorpId,
  125. "suiteId" => $suiteId,
  126. ];
  127. $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
  128. $curl = new Curl($uri);
  129. $ret = json_decode($curl->httpPost($posts),true);
  130. return $ret;
  131. }
  132. /**
  133. * 获得爱关怀的SSO URL地址
  134. * @param $gCorpId
  135. * @param $redirectUrl
  136. * @return string
  137. */
  138. public function getSsoUrl($gCorpId,$redirectUrl){
  139. return $this->configs["api_url"]."/".$this->configs["api_version"]."/huanan/sso/url?gcorpId={$gCorpId}&forward=1&redirectUrl=".urlencode($redirectUrl);
  140. }
  141. }