SystemMemberMiniappToken.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. *
  7. * 微信认证权限表
  8. */
  9. namespace app\common\model;
  10. use think\Model;
  11. class SystemMemberMiniappToken extends Model{
  12. protected $pk = 'id';
  13. /**
  14. * 添加编辑
  15. * @param array $param 数组
  16. */
  17. public static function edit(array $param){
  18. $data['authorizer_access_token'] = $param['access_token'];
  19. $data['authorizer_refresh_token'] = $param['refresh_token'];
  20. $data['expires_in'] = $param['expires_in'];
  21. $data['update_time'] = time();
  22. $miniapp = self::where(['member_miniapp_id' => $param['member_miniapp_id'],'authorizer_appid' => $param['appid']])->find();
  23. if($miniapp){
  24. return self::where(['member_miniapp_id' => $param['member_miniapp_id'],'authorizer_appid' => $param['appid']])->update($data);
  25. }else {
  26. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  27. $data['authorizer_appid'] = $param['appid'];
  28. return self::insert($data);
  29. }
  30. }
  31. /**
  32. * 获取AccessToken
  33. * @param array $param 数组
  34. */
  35. public static function accessToken(int $id,string $appid){
  36. $where['member_miniapp_id'] = $id;
  37. $where['authorizer_appid'] = $appid;
  38. $assess = self::where($where)->find();
  39. if ($assess) {
  40. $expires_in = time()-$assess['update_time'];
  41. if ($expires_in >= 6600) {
  42. return false;
  43. }
  44. return ['access_token'=>$assess['authorizer_access_token'],'appid' => $appid];
  45. }
  46. return false;
  47. }
  48. /**
  49. * 获取refreshToken
  50. * @param array $param 数组
  51. */
  52. public static function refreshToken(int $id,string $appid){
  53. $where['member_miniapp_id'] = $id;
  54. $where['authorizer_appid'] = $appid;
  55. $assess = self::where($where)->find();
  56. if ($assess) {
  57. return ['refreshToken' => $assess['authorizer_refresh_token'],'appid' => $appid];
  58. }
  59. return false;
  60. }
  61. }