MemberTFBService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dingran
  5. * Date: 2020/3/12
  6. * Time: 下午8:08
  7. */
  8. namespace app\frontend\modules\member\services;
  9. use app\common\exceptions\ShopException;
  10. use app\common\services\Session;
  11. use app\frontend\modules\member\models\MemberModel;
  12. use Yunshop\Haifen\common\service\HfSign;
  13. class MemberTFBService extends MemberService
  14. {
  15. private $appGateWay;
  16. private $appId;
  17. private $appSecret;
  18. public function login()
  19. {
  20. $this->verify(request()->input());
  21. }
  22. /**
  23. * 验证登录状态
  24. *
  25. * @return bool
  26. */
  27. public function checkLogged()
  28. {
  29. return $this->verify(request()->input());
  30. }
  31. public function verify($data)
  32. {
  33. $this->getAppData();
  34. $hfSign = new HfSign();
  35. $hfSign->setKey($this->appSecret);
  36. if ($hfSign->verify($data)) {
  37. $MemberModel = MemberModel::getId($data['i'], $data['mob_parent']);
  38. if (!is_null($MemberModel)) {
  39. Session::set('member_id', $MemberModel->uid);
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45. private function getAppData()
  46. {
  47. $appData = \Setting::get('plugin.haifen_set');
  48. if (is_null($appData) || 0 == $appData['status']) {
  49. throw new ShopException('应用未启用');
  50. }
  51. if (empty($appData['app_id']) || empty($appData['app_secret'])) {
  52. throw new ShopException('应用参数错误');
  53. }
  54. if ($appData['app_id'] != request()->input('appid')) {
  55. throw new ShopException('访问身份异常');
  56. }
  57. $this->appGateWay = $appData['app_gateway'];
  58. $this->appId = $appData['app_id'];
  59. $this->appSecret = $appData['app_secret'];
  60. }
  61. }