123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- /**
- * Created by PhpStorm.
- * User: guanxl
- * Date: 2018/5/23
- * Time: 18:13
- */
-
- namespace App\Services;
- use App\Common\Curl;
- use App\Common\Singleton;
-
-
- class AghApiService
- {
- use Singleton;
-
- protected $configs;
-
- public function __construct($configs=[])
- {
- if(empty($configs)){
- $configs = config('agh');
- }
- $this->configs = $configs;
- }
-
- /**
- * 获得签名信息
- * @param $name
- * @param $gets
- * @param array $posts
- * @return string
- */
-
- protected function getSignUri($name,$gets,$posts=[]){
- $gets["partnerId"] = $this->configs["api_partner_id"];
- $gets["name"] = $name;
- $gets["version"] = $this->configs["api_version"];
- $gets["expires"] = time()+3600;
- $gets["nonce"] = uniqid();
- $array=array_merge($gets,$posts);
- ksort($array);
- $str = "";
- foreach ($array as $key=>$value){
- $str = $str . $key . '=' . $value . '&';
- }
- $str = substr($str, 0,strlen($str)-1);
-
- $signature = hash_hmac('SHA256',$str, $this->configs["api_key"]);
-
- $getUri="";
- foreach ($gets as $key=>$value){
- $getUri = $getUri . $key . '=' . $value . '&';
- }
-
- return $getUri."signature=".$signature;
- }
-
- /**
- * 获得用户信息
- * @param $gCorpId
- * @param $guid
- * @return mixed
- */
- public function getUserDetail($gCorpId,$guid){
- $name="b.getUserDetail";
- $posts = [
- "corpId" => $gCorpId,
- "guid" => $guid
- ];
- $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
- $curl = new Curl($uri);
- $ret = json_decode($curl->httpPost($posts),true);
- return $ret;
- }
-
- /**
- * 获得企业列表
- * @param $page8
- * @param $pageSize
- * @return mixed
- */
- public function getCorpList($page,$pageSize){
- $name="b.getCorpList";
- $posts = [
- "page" => $page,
- "pageSize" => $pageSize
- ];
- $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
- $curl = new Curl($uri);
- $ret = json_decode($curl->httpPost($posts),true);
- return $ret;
- }
-
- /**
- * 获得企业信息
- * @param $gCorpId
- * @return mixed
- */
- public function getCorpInfo($gCorpId){
- $name="b.getCorpInfo";
- $posts = [
- "enterpriseId" => $gCorpId
- ];
- $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
- $curl = new Curl($uri);
- $ret = json_decode($curl->httpPost($posts),true);
-
- return $ret;
- }
-
- /**
- * 获取微信access_token
- * @param $appId
- * @param $gCorpId
- * @return mixed
- */
- public function getWechatToken($gCorpId,$appId){
- $name="b.wechat.getToken";
- $posts = [
- "appId" => $appId,
- "corpId" => $gCorpId
- ];
- $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
- $curl = new Curl($uri);
-
- $ret = json_decode($curl->httpPost($posts),true);
-
- return $ret;
- }
-
- /**
- * 获取企业微信access_token
- * @param $qyCorpId
- * @param $suiteId
- * @return mixed
- */
- public function getWesuitToken($qyCorpId,$suiteId){
- $name="b.wesuit.getToken";
- $posts = [
- "qy_corpid" => $qyCorpId,
- "suiteId" => $suiteId,
- ];
- $uri = $this->configs["api_url"]."/fe/private/?".$this->getSignUri($name,[],$posts);
- $curl = new Curl($uri);
-
- $ret = json_decode($curl->httpPost($posts),true);
-
- return $ret;
- }
-
- /**
- * 获得爱关怀的SSO URL地址
- * @param $gCorpId
- * @param $redirectUrl
- * @return string
- */
- public function getSsoUrl($gCorpId,$redirectUrl){
- return $this->configs["api_url"]."/".$this->configs["api_version"]."/huanan/sso/url?gcorpId={$gCorpId}&forward=1&redirectUrl=".urlencode($redirectUrl);
- }
- }
|