ThirdApi.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * 第三方接口
  4. * User: solu
  5. * Date: 2018/12/10
  6. * Time: 4:40 PM
  7. */
  8. class ThirdApi {
  9. /**
  10. * 检测token有效性
  11. * @author solu
  12. * @param $userId
  13. * @param $accessToken
  14. * @return bool
  15. */
  16. public static function checkToken($userId, $accessToken) {
  17. $data = [
  18. 'user_id' => $userId,
  19. 'app_id' => MEE_APP_ID,
  20. 'access_token' => $accessToken
  21. ];
  22. $api = URL_MEECHAT . 'auth/checkAccessToken';
  23. $resp = (new dwHttp())->post2($api, $data);
  24. $json = json_decode($resp, true);
  25. return $json['data']['valid'];
  26. }
  27. /**
  28. * 获取用户信息
  29. * @author solu
  30. * @param $userId
  31. * @param $accessToken
  32. * @return null|array
  33. */
  34. public static function getMeeUserInfo($userId, $accessToken) {
  35. $data = [
  36. 'user_id' => $userId,
  37. 'app_id' => MEE_APP_ID,
  38. 'access_token' => $accessToken
  39. ];
  40. $api = URL_MEECHAT . 'auth/getUserInfo';
  41. $resp = (new dwHttp())->post2($api, $data);
  42. $json = json_decode($resp, true);
  43. if (!$json['result']) {
  44. return null;
  45. }
  46. return $json['data'];
  47. }
  48. /**
  49. * 获取授权页面地址
  50. * @author solu
  51. * @param $callbackURL
  52. * @return string
  53. */
  54. public static function getAuthUrl($callbackURL) {
  55. $ts = time();
  56. $params = [
  57. 'callback' => $callbackURL,
  58. 'app_id' => MEE_APP_ID,
  59. 'ts' => $ts,
  60. 'sign' => self::meeSign(MEE_APP_ID, MEE_APP_SECRET, $ts),
  61. ];
  62. return URL_MEECHAT . 'auth/login?' . http_build_query($params);
  63. }
  64. private static function meeSign($appId, $appSecret, $ts) {
  65. return md5(sprintf('%s_%s_%s', $appId, $appSecret, $ts));
  66. }
  67. }