platformAuth.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @title:中平台授权
  4. * @user: zwq
  5. * @date: 2025-01-09 15:01
  6. */
  7. namespace daorui\platform;
  8. use app\common\model\base\dic\Dic;
  9. use daorui\DaoRuiBase;
  10. class platformAuth extends DaoRuiBase
  11. {
  12. //应用id
  13. protected $app_id = "250227093116888";
  14. //应用key
  15. protected $app_key = "cc83cc5c4b832d65c86120c965b12939";
  16. /**
  17. * @var string 请求地址
  18. */
  19. private $baseURL = "http://jdf.app2.hbdrwh.cn/index.php";
  20. /**
  21. * @var string 接口地址
  22. */
  23. private $ApiUrl = [
  24. //token获取用户信息
  25. 'getUserToken' => ['url' => '/interfaces/authorize/getUserToken', 'method' => 'POST'],
  26. //获取外部内置角色类型列表
  27. 'getRoleType' => ['url' => '/interfaces/org/getRoleType', 'method' => 'POST'],
  28. //登录中台账号
  29. 'accountLogin' => ['url' => '/interfaces/authorize/accountLogin', 'method' => 'POST'],
  30. //获取openid
  31. 'socialLogin' => ['url' => '/admin/base.user.user/socialLogin', 'method' => 'POST'],
  32. //获取用户角色码
  33. 'getUserRole' => ['url' => '/interfaces/authorize/getUserRole', 'method' => 'POST'],
  34. //获取组织类型列表
  35. 'getOrgType' => ['url' => '/interfaces/org/getOrgType', 'method' => 'POST'],
  36. //发送短信验证码
  37. 'sendSmsCode' => ['url' => '/interfaces/user/sendSmsCode', 'method' => 'POST'],
  38. //验证短信验证码
  39. 'checkSmsCode' => ['url' => '/interfaces/user/checkSmsCode', 'method' => 'POST'],
  40. //公众号消息推送
  41. 'sendWeChatMsg' => ['url' => '/interfaces/user/sendWeChatMsg', 'method' => 'POST'],
  42. //创建账户
  43. 'createAccount' => ['url' => '/interfaces/user/createAccount', 'method' => 'POST'],
  44. // 企业微信消息推送
  45. 'sendWeComMsg' => ['url' => '/interfaces/user/sendWeComMsg', 'method' => 'POST'],
  46. // 获取应用签名
  47. 'getSignInfo' => ['url' => '/interfaces/sign', 'method' => 'POST'],
  48. // 获取以前就读学校
  49. "getPreviousSchool" => ['url' => '/interfaces/school/getPreviousSchool', 'method' => 'POST'],
  50. //获取组织架构
  51. "getOrg" => ['url' => '/interfaces/org/getOrg', 'method' => 'POST'],
  52. //获取全国地区信息
  53. "getArea" => ['url' => '/interfaces/school/getArea', 'method' => 'POST'],
  54. //获取学校类型
  55. 'getSchoolCode' => ['url' => '/interfaces/school/getSchoolCode', 'method' => 'GET'],
  56. //获取学校列表
  57. 'getSchool' => ['url' => '/interfaces/school/getSchool', 'method' => 'POST'],
  58. ];
  59. /**
  60. * 构造方法
  61. */
  62. public function __construct()
  63. {
  64. parent::__construct();
  65. }
  66. /**
  67. * @title :[公共接口请求]
  68. * @param string $url
  69. * @param array|string $data
  70. * @param array $header
  71. * @return array|json|{*}
  72. * @Author : byl
  73. * @Date :2025/1/9 9:49
  74. */
  75. public function interfaceRequest($scene, $data, $header = [])
  76. {
  77. $url = $this->baseURL . $this->ApiUrl[$scene]['url'] ?? null;
  78. if (!$url) return Result(false, 490005);
  79. $method = $this->ApiUrl[$scene]['method'] ?? 'POST';
  80. $resToken = $this->getSign();
  81. $header['authorization'] = $resToken;
  82. if ($resToken) {
  83. $res = $this->SendCurl($url, $data, $header, $method);
  84. WLog("apiResult", ['url' => $url, 'data' => $data, 'res' => $res['code'] ?? "", 'method' => $method, 'resToken' => $resToken, 'header' => $header]);
  85. if ($res['code'] != 200 && $res['code'] != 1) {
  86. return Result(false, $res['message'] ?? $res['msg']);
  87. } else {
  88. return Result(true, '', $res['data']);
  89. }
  90. } else {
  91. return Result(false, '请求失败');
  92. }
  93. }
  94. /**
  95. * Desc :获取应用签名
  96. * User : zwq
  97. * Date : 2025-01-09 15:33
  98. * @throws \Exception
  99. */
  100. public function getSign()
  101. {
  102. $access_token = $this->getCache('daorui_access_token');
  103. if (!empty($access_token) && is_array($access_token)) {
  104. $access_token = $access_token['access_token'];
  105. }
  106. if (empty($access_token)) {
  107. $url = $this->baseURL . $this->ApiUrl['getSignInfo']['url'];
  108. $data['app_id'] = $this->app_id;
  109. $data['app_key'] = $this->app_key;
  110. $res = $this->SendCurl($url, $data);
  111. $access_token = $res['data'];
  112. $this->setCache(['access_token' => $access_token], 'daorui_access_token', 8600);
  113. }
  114. return $access_token;
  115. }
  116. /**
  117. * Desc :获取应用导航栏
  118. * User : zwq
  119. * Date : 2025-01-14 08:56
  120. */
  121. public function getHome($data)
  122. {
  123. $url = $this->baseURL . $this->ApiUrl['getHomeTab']['url'];
  124. $access_token = $this->getSign();
  125. $header = ['authorization' => $access_token];
  126. $res = $this->SendCurl($url, $data, $header);
  127. if ($res['code'] == 200) {
  128. return $res['data'];
  129. } else {
  130. throw new \Exception($res['msg'] ?? $res['message']);
  131. }
  132. }
  133. }