Modules_Web_Controllers_PcController.proxy.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <?php
  2. namespace Modules\Web\Controllers;
  3. use App\Constants\CreatorConstant;
  4. use App\Jobs\SavePcVideoCoverCebJob;
  5. use App\Model\TypeModel;
  6. use App\Model\TypeVideoModel;
  7. use App\Model\VideoModel;
  8. use App\Repositories\ConfigRepoistory;
  9. use App\Repositories\CreatorRepository;
  10. use App\Repositories\CreatorRuleRepository;
  11. use App\Repositories\UserRepository;
  12. use App\Repositories\Utils\MediaCenterRepository;
  13. use App\Repositories\VideoRepository;
  14. use Carbon\Carbon;
  15. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  16. use Modules\Web\Services\AuthService;
  17. use Psr\SimpleCache\CacheInterface;
  18. class PcController extends BaseController
  19. {
  20. use \Hyperf\Di\Aop\ProxyTrait;
  21. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  22. function __construct()
  23. {
  24. if (method_exists(parent::class, '__construct')) {
  25. parent::__construct(...func_get_args());
  26. }
  27. $this->__handlePropertyHandler(__CLASS__);
  28. }
  29. /**
  30. * 签名token/key
  31. * @var string
  32. */
  33. private $signToken = 'uwgnnDtzTZR1xzoW';
  34. /**
  35. * @var null|AuthService
  36. */
  37. private $authService = null;
  38. /**
  39. * @var null|UserRepository
  40. */
  41. private $userRepo = null;
  42. /**
  43. * @var null|CacheInterface
  44. */
  45. private $cacheRepo = null;
  46. public function index()
  47. {
  48. return 'pc-ok-pong';
  49. }
  50. /**
  51. * 轮询登陆是否成功.
  52. * @return mixed
  53. * @throws \Psr\SimpleCache\InvalidArgumentException
  54. */
  55. public function lookup()
  56. {
  57. $qrcodeContent = trim(request()->input('qc', ''));
  58. $qrFrom = request()->input('from', 'web');
  59. $qrInfo = $this->getUserCodeByQrCode($qrcodeContent);
  60. if (!empty($qrInfo['err_msg'])) {
  61. return $this->jsonFail($qrInfo['err_msg'], 5001);
  62. }
  63. $realUserCode = '';
  64. $userCode = $qrInfo['user_code'];
  65. $userInfo = $this->getAuthInfo();
  66. if (!empty($userInfo['code'])) {
  67. return $this->jsonFail('授权无效1', 5002);
  68. }
  69. if ($userInfo['code'] !== $userCode) {
  70. return $this->jsonFail('授权非法1', 5003);
  71. }
  72. $status = 2;
  73. // 状态,1=拿到token,2=未拿到,未登陆状态
  74. $cacheKey = $this->getAuthService()->getUserCacheKey($userCode);
  75. $token = $this->getCacheRepo()->get($cacheKey, '');
  76. if (empty($token)) {
  77. $status = 1;
  78. } else {
  79. $realUserCode = $userCode;
  80. }
  81. $result = ['status' => $status, 'token' => $token, 'user_code' => $realUserCode];
  82. return $this->jsonSuccess($result);
  83. }
  84. /**
  85. * 检查是否合法登陆
  86. * @return mixed
  87. */
  88. public function checkLogin()
  89. {
  90. $userInfo = $this->getAuthInfo();
  91. if (empty($userInfo['code'])) {
  92. return $this->jsonFail('授权无效', 5091);
  93. }
  94. $result = ['is_success' => true];
  95. return $this->jsonSuccess($result);
  96. }
  97. public function setting()
  98. {
  99. $userInfo = $this->getAuthInfo();
  100. if (empty($userInfo['code'])) {
  101. return $this->jsonFail('授权无效', 5091);
  102. }
  103. $userCode = $userInfo['code'];
  104. $configRepo = make(ConfigRepoistory::class);
  105. $creatorRepo = make(CreatorRepository::class);
  106. $ruleRepo = make(CreatorRuleRepository::class);
  107. $detail = $creatorRepo->detail($userCode);
  108. $todayCanUpload = false;
  109. $level = 0;
  110. $dayAddonNum = 0;
  111. $dayVideo = 0;
  112. if (!empty($detail)) {
  113. $level = intval($detail->level);
  114. $dayAddonNum = intval($detail->day_addon_num);
  115. $dayVideo = intval($detail->day_video);
  116. }
  117. $ruleLevel = $ruleRepo->getRuleByLevel($level);
  118. $dayMaxVideo = intval($ruleLevel->day_max_video) + $dayAddonNum;
  119. $todayVideo = !empty($detail) ? $dayVideo : 0;
  120. if ($todayVideo < $dayMaxVideo) {
  121. $todayCanUpload = true;
  122. }
  123. $fileMaxSizeMb = CreatorConstant::VIDEO_MAX_SIZE_MB;
  124. // 文件最大多少MB
  125. $maxCoin = CreatorConstant::VIDEO_SELL_MAX_COIN;
  126. // 最多设置金币个数
  127. $creatorMinVideoNum = CreatorConstant::FREE_VIDEO_NUM;
  128. // 创作者,level>0
  129. $normalMinVideoNum = CreatorConstant::LEVEL_0_FREE_VIDEO_NUM;
  130. // 普通人, level=0
  131. $maxTagNum = CreatorConstant::VIDEO_TAG_MAX_NUM;
  132. // 最多选择标签个数.
  133. $tags = $creatorRepo->canUseTags();
  134. $ppvodParams = $configRepo->gets(['ppvod_upload_category', 'ppvod_upload_tpl_id', 'ppvod_upload_tpl_name'], 'sys', []);
  135. $isCanUploadCoin = isset($detail->coin_uper) ? boolval($detail->coin_uper) : false;
  136. // 是否能传收费视频
  137. $needUploadFreeNum = 0;
  138. // 还需要上传免费视频个数.
  139. $countFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, true);
  140. // 统计免费视频个数
  141. $countNotFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, false);
  142. //统计收费视频个数
  143. if ($level <= 0) {
  144. if (CreatorConstant::LEVEL_0_FREE_VIDEO_NUM > 0) {
  145. // 金币视频 x 免费要求 = 最低历史上传免费个数
  146. $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::LEVEL_0_FREE_VIDEO_NUM : CreatorConstant::LEVEL_0_FREE_VIDEO_NUM;
  147. if ($countFreeVideos >= $leastFreeNum) {
  148. $isCanUploadCoin = true;
  149. } else {
  150. $needUploadFreeNum = $leastFreeNum - $countFreeVideos;
  151. }
  152. } else {
  153. $isCanUploadCoin = true;
  154. }
  155. } else {
  156. if (CreatorConstant::FREE_VIDEO_NUM > 0) {
  157. // 金币视频 x 免费要求 = 最低限制上传免费个数
  158. $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::FREE_VIDEO_NUM : CreatorConstant::FREE_VIDEO_NUM;
  159. if ($countFreeVideos >= $leastFreeNum) {
  160. $isCanUploadCoin = true;
  161. } else {
  162. $needUploadFreeNum = $leastFreeNum - $countFreeVideos;
  163. }
  164. } else {
  165. $isCanUploadCoin = true;
  166. }
  167. }
  168. $uploadIsMaintenance = false;
  169. $uploadMaintenanceDesc = '';
  170. $arrConfig = $configRepo->gets(['upload_maintenance_status', 'upload_maintenance_desc'], 'sys', []);
  171. if (isset($arrConfig['upload_maintenance_status']) && intval($arrConfig['upload_maintenance_status']) == 1) {
  172. $uploadIsMaintenance = true;
  173. $uploadMaintenanceDesc = $arrConfig['upload_maintenance_desc'] ?? '上传维护中,请稍后恢复再试';
  174. }
  175. $result = ['user_id' => $userInfo['code'], 'nick' => $userInfo['nick'], 'level' => $level, 'today_can_upload' => $todayCanUpload, 'file_max_size_mb' => $fileMaxSizeMb, 'max_coin' => $maxCoin, 'creator_min_video_num' => $creatorMinVideoNum, 'normal_min_video_num' => $normalMinVideoNum, 'max_tag_num' => $maxTagNum, 'tags' => $tags, 'is_can_upload_coin' => $isCanUploadCoin, 'need_upload_free_num' => $needUploadFreeNum, 'count_free_videos' => $countFreeVideos, 'count_not_free_videos' => $countNotFreeVideos, 'upload_category' => !empty($ppvodParams['ppvod_upload_category']) ? $ppvodParams['ppvod_upload_category'] : '用户上传', 'upload_tpl_id' => !empty($ppvodParams['ppvod_upload_tpl_id']) ? $ppvodParams['ppvod_upload_tpl_id'] : '', 'upload_tpl_name' => !empty($ppvodParams['ppvod_upload_tpl_name']) ? $ppvodParams['ppvod_upload_tpl_name'] : '默认', 'upload_is_maintenance' => $uploadIsMaintenance, 'upload_maintenance_desc' => $uploadMaintenanceDesc];
  176. return $this->jsonSuccess($result);
  177. }
  178. public function createVideo()
  179. {
  180. $userInfo = $this->getAuthInfo();
  181. if (empty($userInfo['code'])) {
  182. return $this->jsonFail('授权无效', 5091);
  183. }
  184. $userCode = $userInfo['code'];
  185. $validatorFactory = make(ValidatorFactoryInterface::class);
  186. $inputData = request()->all();
  187. $rules = [
  188. 'title' => 'required',
  189. 'cover' => 'nullable|max:700',
  190. 'coins' => 'required|int',
  191. 'tags' => 'required',
  192. // 这个是ID
  193. 'file_hash' => 'required',
  194. ];
  195. $validator = $validatorFactory->make($inputData, $rules);
  196. if ($validator->fails()) {
  197. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  198. return json_fail($validator->errors()->first());
  199. }
  200. $videoRepo = make(VideoRepository::class);
  201. if ($videoRepo->checkExist($inputData['file_hash'])) {
  202. return $this->jsonFail('此视频已被其他人上传过,请重新更换', 6444);
  203. }
  204. $mediaCenterRepo = make(MediaCenterRepository::class);
  205. $hashVideoInfo = $mediaCenterRepo->getHashInfo($inputData['file_hash']);
  206. if (!empty($hashVideoInfo)) {
  207. return $this->jsonFail('此视频有人上传过了,请重新更换', 6444);
  208. }
  209. $ruleRepo = make(CreatorRuleRepository::class);
  210. $creatorRepo = make(CreatorRepository::class);
  211. $detail = $creatorRepo->detail($userCode);
  212. $level = 0;
  213. $dayAddonNum = 0;
  214. $dayVideo = 0;
  215. if (!empty($detail)) {
  216. $level = intval($detail->level);
  217. $dayAddonNum = intval($detail->day_addon_num);
  218. $dayVideo = intval($detail->day_video);
  219. } else {
  220. // 自动申请为原创者.
  221. $detail = $creatorRepo->applyToUncheck($userCode);
  222. $level = intval($detail->level);
  223. }
  224. $ruleLevel = $ruleRepo->getRuleByLevel($level);
  225. $dayMaxVideo = intval($ruleLevel->day_max_video) + $dayAddonNum;
  226. $todayVideo = !empty($detail) ? $dayVideo : 0;
  227. if ($todayVideo >= $dayMaxVideo) {
  228. return $this->jsonFail('今日已经超出上传数量限制');
  229. }
  230. $cover = trim(data_get($inputData, 'cover', ''));
  231. $cover = substr($cover, 0, 255);
  232. $coins = intval(data_get($inputData, 'coins', 0));
  233. // 金币,单位数量个,10金币=1元人民币
  234. $uploadingUrl = '';
  235. // TODO,这里可以做一个固定视频,等待用户上传转码中.
  236. if ($coins < 0) {
  237. $coins = 0;
  238. }
  239. if ($coins > CreatorConstant::VIDEO_SELL_MAX_COIN) {
  240. return $this->jsonFail('售卖金币价格太大,可以提前联系客服');
  241. }
  242. $arrTagIds = [];
  243. $tmpTagIds = data_get($inputData, 'tags', '');
  244. if (is_string($tmpTagIds)) {
  245. $arrTagIds = explode(',', $tmpTagIds);
  246. } else {
  247. $arrTagIds = $tmpTagIds;
  248. }
  249. if (!empty($arrTagIds)) {
  250. $arrTagIds = array_filter($arrTagIds);
  251. $arrTagIds = array_unique($arrTagIds);
  252. }
  253. if (empty($arrTagIds)) {
  254. return $this->jsonFail('请选择至少1个口味');
  255. }
  256. if (count($arrTagIds) > CreatorConstant::VIDEO_TAG_MAX_NUM) {
  257. return $this->jsonFail('最多选择' . strval(CreatorConstant::VIDEO_TAG_MAX_NUM) . '个口味');
  258. }
  259. // 处理关联标签.
  260. $tagIdsRaltion = [];
  261. $tagNames = [];
  262. if (!empty($arrTagIds)) {
  263. foreach ($arrTagIds as $v) {
  264. $tagObj = TypeModel::query()->where('id', $v)->first();
  265. if (!empty($tagObj->id)) {
  266. $tagIdsRaltion[] = $tagObj->id;
  267. $tagNames[] = $tagObj->title;
  268. }
  269. }
  270. }
  271. $isCanUploadCoin = isset($detail->coin_uper) ? boolval($detail->coin_uper) : false;
  272. // 是否能传收费视频
  273. $needUploadFreeNum = 0;
  274. // 还需要上传免费视频个数.
  275. $countFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, true);
  276. // 统计免费视频个数
  277. $countNotFreeVideos = $creatorRepo->countPublishedCoinVideo($userCode, false);
  278. //统计收费视频个数
  279. if ($level <= 0) {
  280. if (CreatorConstant::LEVEL_0_FREE_VIDEO_NUM > 0) {
  281. // 金币视频 x 免费要求 = 最低历史上传免费个数
  282. $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::LEVEL_0_FREE_VIDEO_NUM : CreatorConstant::LEVEL_0_FREE_VIDEO_NUM;
  283. if ($countFreeVideos >= $leastFreeNum) {
  284. $isCanUploadCoin = true;
  285. } else {
  286. $needUploadFreeNum = $leastFreeNum - $countFreeVideos;
  287. }
  288. } else {
  289. $isCanUploadCoin = true;
  290. }
  291. } else {
  292. if (CreatorConstant::FREE_VIDEO_NUM > 0) {
  293. // 金币视频 x 免费要求 = 最低限制上传免费个数
  294. $leastFreeNum = $countNotFreeVideos > 0 ? $countNotFreeVideos * CreatorConstant::FREE_VIDEO_NUM : CreatorConstant::FREE_VIDEO_NUM;
  295. if ($countFreeVideos >= $leastFreeNum) {
  296. $isCanUploadCoin = true;
  297. } else {
  298. $needUploadFreeNum = $leastFreeNum - $countFreeVideos;
  299. }
  300. } else {
  301. $isCanUploadCoin = true;
  302. }
  303. }
  304. if ($coins > 0 && !$isCanUploadCoin) {
  305. return $this->jsonFail('还不能上传收费视频,请先再传' . strval($needUploadFreeNum) . '个免费视频');
  306. }
  307. $payType = 2;
  308. // 默认金币
  309. if ($coins == 0) {
  310. $payType = 1;
  311. // vip
  312. }
  313. $newStrTagNames = !empty($tagNames) ? implode(',', $tagNames) : '';
  314. $newStrTagIds = !empty($arrTagIds) ? implode(',', $arrTagIds) : '';
  315. $title = trim(data_get($inputData, 'title', ''));
  316. $title = mb_substr($title, 0, 24);
  317. $fileHash = trim(data_get($inputData, 'file_hash', ''));
  318. $fileHash = substr($fileHash, 0, 32);
  319. $setarr = ['uid' => $userCode, 'status' => 3, 'check' => 0, 'pay_type' => $payType, 'type' => 1, 'mu' => $uploadingUrl, 'title' => $title, 'cover' => $cover, 'coins' => $coins, 'tags' => $newStrTagNames, 'file_hash' => $fileHash, 'custom_cover' => $cover];
  320. $videoObj = VideoModel::query()->create($setarr);
  321. if ($videoObj) {
  322. $videoId = $videoObj->id;
  323. if (!empty($tagIdsRaltion)) {
  324. foreach ($tagIdsRaltion as $tagId) {
  325. $setarr2 = ['type_id' => $tagId, 'video_id' => $videoId, 'status' => 1];
  326. TypeVideoModel::query()->create($setarr2);
  327. }
  328. }
  329. // 累加今日上传视频数量.
  330. $detail->day_video++;
  331. $detail->save();
  332. if (!empty($cover)) {
  333. $coverFileName = basename($cover);
  334. $coverExt = $this->fileExt($coverFileName);
  335. if ($coverExt != 'ceb' && in_array($coverExt, ['jpg', 'jpeg', 'png', 'gif'])) {
  336. $jobParams = ['video_id' => $videoId, 'cover' => $cover];
  337. dispatch_job(new SavePcVideoCoverCebJob($jobParams));
  338. }
  339. }
  340. } else {
  341. return $this->jsonFail('创建视频失败');
  342. }
  343. $result = ['video' => ['id' => $videoObj->id]];
  344. return $this->jsonSuccess($result);
  345. }
  346. /**
  347. * 二维码登陆
  348. * @return mixed
  349. * @throws \Psr\SimpleCache\InvalidArgumentException
  350. */
  351. public function qrcodeLogin()
  352. {
  353. $qrcodeContent = trim(request()->input('qc', ''));
  354. $qrFrom = request()->input('from', 'web');
  355. $qrInfo = $this->getUserCodeByQrCode($qrcodeContent);
  356. if (!empty($qrInfo['err_msg'])) {
  357. return $this->jsonFail($qrInfo['err_msg']);
  358. }
  359. $userCode = $qrInfo['user_code'];
  360. // $cacheKey = $this->getAuthService()->getUserCacheKey($userCode);
  361. // $token = $this->getCacheRepo()->get($cacheKey);
  362. $tokenInfo = $this->getAuthService()->createSingleJwt($userCode);
  363. $token = $tokenInfo['token'];
  364. $result = ['token' => $token, 'user_code' => $userCode];
  365. return $this->jsonSuccess($result);
  366. }
  367. public function upAuth()
  368. {
  369. $userInfo = $this->getAuthInfo();
  370. if (empty($userInfo['code'])) {
  371. logger('upAuth', ['msg' => '[4]握手失败']);
  372. return response('[4]握手失败', 500);
  373. }
  374. $queryUserCode = $userInfo['code'];
  375. $inputData = request()->all();
  376. $rules = ['auth_event' => 'required', 'auth_timestamp' => 'required', 'app_name' => 'required', 'auth_user' => 'required', 'auth_sign' => 'required|string', 'file_hash' => 'nullable', 'file_origin_name' => 'nullable', 'file_ext' => 'nullable'];
  377. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  378. if ($validator->fails()) {
  379. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  380. logger('upAuth', ['msg' => $validator->errors()->first()]);
  381. return response($validator->errors()->first(), 500);
  382. }
  383. $authTimestamp = strval(data_get($inputData, 'auth_timestamp', ''));
  384. $appName = data_get($inputData, 'app_name', '');
  385. $authUserCode = data_get($inputData, 'auth_user', '');
  386. $authSign = data_get($inputData, 'auth_sign', '');
  387. $authEvent = data_get($inputData, 'auth_event', '');
  388. $fileOriginName = data_get($inputData, 'file_origin_name', '');
  389. $fileHash = data_get($inputData, 'file_hash', '');
  390. $fileExt = strtolower(data_get($inputData, 'file_ext', ''));
  391. $tmpTimestamp = substr($authTimestamp, 0, 10);
  392. if (abs(Carbon::createFromTimestamp($tmpTimestamp)->diffInMinutes(Carbon::now())) > 30) {
  393. logger('upAuth', ['msg' => '[5]握手失败']);
  394. return response('[5]握手失败', 500);
  395. }
  396. $inSign = $this->createSign($authTimestamp, $appName, $authUserCode, $authEvent);
  397. if ($inSign !== $authSign) {
  398. logger('upAuth', ['msg' => '[3]握手失败']);
  399. return response('[3]握手失败', 500);
  400. }
  401. if (empty($queryUserCode) || $queryUserCode !== $authUserCode) {
  402. logger('upAuth', ['msg' => '[6]握手失败']);
  403. return response('[6]握手失败', 500);
  404. }
  405. return response('success', 200);
  406. }
  407. /**
  408. * 获取认证里的用户信息.
  409. * @return array
  410. */
  411. private function getAuthInfo()
  412. {
  413. $authInfo = $this->getAuthService()->getTokenUserInfo();
  414. if (empty($authInfo['user_id'])) {
  415. return [];
  416. }
  417. $userInfo = $this->getAuthService()->checkValid($authInfo['user_id']);
  418. if (empty($userInfo)) {
  419. return [];
  420. }
  421. $userInfo['user_id'] = $userInfo['code'];
  422. // 兼容.
  423. return $userInfo;
  424. }
  425. /**
  426. * 获取服务.
  427. * @return mixed|AuthService
  428. */
  429. private function getAuthService()
  430. {
  431. if (!$this->authService instanceof AuthService) {
  432. $this->authService = make(AuthService::class);
  433. }
  434. return $this->authService;
  435. }
  436. /**
  437. * 获取用户仓库.
  438. * @return UserRepository|mixed
  439. */
  440. private function getUserRepo()
  441. {
  442. if (!$this->userRepo instanceof UserRepository) {
  443. $this->userRepo = make(UserRepository::class);
  444. }
  445. return $this->userRepo;
  446. }
  447. /**
  448. * 获取缓存仓库.
  449. * @return mixed|CacheInterface
  450. */
  451. private function getCacheRepo()
  452. {
  453. if (!$this->cacheRepo instanceof CacheInterface) {
  454. $this->cacheRepo = make(CacheInterface::class);
  455. }
  456. return $this->cacheRepo;
  457. }
  458. /**
  459. * 通过二维码内容获取用户code.
  460. * @param $qrcodeContent
  461. * @return string[]
  462. */
  463. private function getUserCodeByQrCode($qrcodeContent)
  464. {
  465. $result = ['err_msg' => '', 'user_code' => ''];
  466. if (empty($qrcodeContent)) {
  467. $result['err_msg'] = '无效的二维码1';
  468. return $result;
  469. }
  470. $txt = $qrcodeContent;
  471. if (empty($txt)) {
  472. $result['err_msg'] = '无效的二维码2';
  473. return $result;
  474. }
  475. $account = hand_decrypt($txt, $this->getUserRepo()->getAcKey(), $this->getUserRepo()->getAcIv());
  476. if (empty($account)) {
  477. $result['err_msg'] = '无效的二维码3';
  478. return $result;
  479. }
  480. $pattern = '/^user:\\/\\/([a-zA-Z0-9]{6,12})/';
  481. preg_match($pattern, $account, $matches);
  482. if (empty($matches[1])) {
  483. $result['err_msg'] = '无效的二维码4';
  484. return $result;
  485. }
  486. $userCode = $matches[1];
  487. $userInfo = $this->getUserRepo()->getUserInfoFromCache($userCode);
  488. if (empty($userInfo['code'])) {
  489. $result['err_msg'] = '无效的二维码5';
  490. return $result;
  491. }
  492. $result['user_code'] = $userCode;
  493. return $result;
  494. }
  495. /**
  496. * @param $timestamp
  497. * @param $appName
  498. * @param $userCode
  499. * @return string
  500. */
  501. private function createSign($timestamp, $appName, $userCode, $authEvent)
  502. {
  503. $strParams = $appName . '-' . $authEvent . '-' . $userCode . '-' . $timestamp;
  504. $strSign = md5(md5($strParams) . '-' . $this->signToken);
  505. return $strSign;
  506. }
  507. private function fileExt($filename)
  508. {
  509. return strtolower(trim(substr(strrchr($filename, '.'), 1)));
  510. }
  511. }