123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * @title:中平台授权
- * @user: zwq
- * @date: 2025-01-09 15:01
- */
- namespace daorui\platform;
- use app\common\model\base\dic\Dic;
- use daorui\DaoRuiBase;
- class platformAuth extends DaoRuiBase
- {
- //应用id
- protected $app_id = "250227093116888";
- //应用key
- protected $app_key = "cc83cc5c4b832d65c86120c965b12939";
- /**
- * @var string 请求地址
- */
- private $baseURL = "http://jdf.app2.hbdrwh.cn/index.php";
- /**
- * @var string 接口地址
- */
- private $ApiUrl = [
- //token获取用户信息
- 'getUserToken' => ['url' => '/interfaces/authorize/getUserToken', 'method' => 'POST'],
- //获取外部内置角色类型列表
- 'getRoleType' => ['url' => '/interfaces/org/getRoleType', 'method' => 'POST'],
- //登录中台账号
- 'accountLogin' => ['url' => '/interfaces/authorize/accountLogin', 'method' => 'POST'],
- //获取openid
- 'socialLogin' => ['url' => '/admin/base.user.user/socialLogin', 'method' => 'POST'],
- //获取用户角色码
- 'getUserRole' => ['url' => '/interfaces/authorize/getUserRole', 'method' => 'POST'],
- //获取组织类型列表
- 'getOrgType' => ['url' => '/interfaces/org/getOrgType', 'method' => 'POST'],
- //发送短信验证码
- 'sendSmsCode' => ['url' => '/interfaces/user/sendSmsCode', 'method' => 'POST'],
- //验证短信验证码
- 'checkSmsCode' => ['url' => '/interfaces/user/checkSmsCode', 'method' => 'POST'],
- //公众号消息推送
- 'sendWeChatMsg' => ['url' => '/interfaces/user/sendWeChatMsg', 'method' => 'POST'],
- //创建账户
- 'createAccount' => ['url' => '/interfaces/user/createAccount', 'method' => 'POST'],
- // 企业微信消息推送
- 'sendWeComMsg' => ['url' => '/interfaces/user/sendWeComMsg', 'method' => 'POST'],
- // 获取应用签名
- 'getSignInfo' => ['url' => '/interfaces/sign', 'method' => 'POST'],
- // 获取以前就读学校
- "getPreviousSchool" => ['url' => '/interfaces/school/getPreviousSchool', 'method' => 'POST'],
- //获取组织架构
- "getOrg" => ['url' => '/interfaces/org/getOrg', 'method' => 'POST'],
- //获取全国地区信息
- "getArea" => ['url' => '/interfaces/school/getArea', 'method' => 'POST'],
- //获取学校类型
- 'getSchoolCode' => ['url' => '/interfaces/school/getSchoolCode', 'method' => 'GET'],
- //获取学校列表
- 'getSchool' => ['url' => '/interfaces/school/getSchool', 'method' => 'POST'],
- ];
- /**
- * 构造方法
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * @title :[公共接口请求]
- * @param string $url
- * @param array|string $data
- * @param array $header
- * @return array|json|{*}
- * @Author : byl
- * @Date :2025/1/9 9:49
- */
- public function interfaceRequest($scene, $data, $header = [])
- {
- $url = $this->baseURL . $this->ApiUrl[$scene]['url'] ?? null;
- if (!$url) return Result(false, 490005);
- $method = $this->ApiUrl[$scene]['method'] ?? 'POST';
- $resToken = $this->getSign();
- $header['authorization'] = $resToken;
- if ($resToken) {
- $res = $this->SendCurl($url, $data, $header, $method);
- WLog("apiResult", ['url' => $url, 'data' => $data, 'res' => $res['code'] ?? "", 'method' => $method, 'resToken' => $resToken, 'header' => $header]);
- if ($res['code'] != 200 && $res['code'] != 1) {
- return Result(false, $res['message'] ?? $res['msg']);
- } else {
- return Result(true, '', $res['data']);
- }
- } else {
- return Result(false, '请求失败');
- }
- }
- /**
- * Desc :获取应用签名
- * User : zwq
- * Date : 2025-01-09 15:33
- * @throws \Exception
- */
- public function getSign()
- {
- $access_token = $this->getCache('daorui_access_token');
- if (!empty($access_token) && is_array($access_token)) {
- $access_token = $access_token['access_token'];
- }
- if (empty($access_token)) {
- $url = $this->baseURL . $this->ApiUrl['getSignInfo']['url'];
- $data['app_id'] = $this->app_id;
- $data['app_key'] = $this->app_key;
- $res = $this->SendCurl($url, $data);
- $access_token = $res['data'];
- $this->setCache(['access_token' => $access_token], 'daorui_access_token', 8600);
- }
- return $access_token;
- }
- /**
- * Desc :获取应用导航栏
- * User : zwq
- * Date : 2025-01-14 08:56
- */
- public function getHome($data)
- {
- $url = $this->baseURL . $this->ApiUrl['getHomeTab']['url'];
- $access_token = $this->getSign();
- $header = ['authorization' => $access_token];
- $res = $this->SendCurl($url, $data, $header);
- if ($res['code'] == 200) {
- return $res['data'];
- } else {
- throw new \Exception($res['msg'] ?? $res['message']);
- }
- }
- }
|