ProfileService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <?php
  2. namespace App\Services\User;
  3. use AlicFeng\IdentityCard\Birthday;
  4. use App\Events\AuditMedia;
  5. use App\Exceptions\AlertException;
  6. use App\Jobs\AppearanceUserJob;
  7. use App\Jobs\FaceVerifyJob;
  8. use App\Jobs\GrowingIO\UserInfoReportJob;
  9. use App\Jobs\GrowingIO\UserVipReportJob;
  10. use App\Models\Common\TokenModel;
  11. use App\Models\Fpdx\ActivityModel;
  12. use App\Models\Fpdx\PairModel;
  13. use App\Models\Log\UserPhotoLogModel;
  14. use App\Models\Log\VipLogModel;
  15. use App\Models\PartnerModel;
  16. use App\Models\TagModel;
  17. use App\Models\User\AuthKey;
  18. use App\Models\User\FaceMatchModel;
  19. use App\Models\User\Openid;
  20. use App\Models\User\UserModel;
  21. use App\Models\Wxkf\UserInfoModel;
  22. use App\Services\Partner\NoticeService;
  23. use App\Services\Service;
  24. use App\Services\Vendor\BaiduAi\FaceService;
  25. use Carbon\Carbon;
  26. use Illuminate\Support\Facades\DB;
  27. use Illuminate\Support\Facades\Redis;
  28. use Sentry\SentryLaravel\SentryFacade;
  29. /**
  30. * 用户信息配置服务
  31. */
  32. class ProfileService extends Service
  33. {
  34. /**
  35. * 更新用户基础配置信息
  36. * @param UserModel $user
  37. * @param array $data
  38. * @return void
  39. * @throws AlertException
  40. * @throws \AlicFeng\IdentityCard\Exception\BirthdayException
  41. */
  42. public function updateUser($user, array $data)
  43. {
  44. if (empty($data)) {
  45. return;
  46. }
  47. // 输入检验
  48. if (array_key_exists('location', $data) && is_array($data['location'])) {
  49. $data['location'] = "";
  50. }
  51. if (
  52. (isset($data['photo_src'])
  53. && empty($data['photo_src']))
  54. || (isset($data['photo_1'])
  55. && empty($data['photo_1']))
  56. || (isset($data['photo_2'])
  57. && empty($data['photo_2']))
  58. || (isset($data['photo_3'])
  59. && empty($data['photo_3']))
  60. || (isset($data['photo_4'])
  61. && empty($data['photo_4']))
  62. ) {
  63. throw new AlertException("照片非法删除", 103);
  64. }
  65. // 判断是否在活动期间更新敏感信息
  66. $ings = ActivityModel::getActivitys();
  67. if ($ings['ing'] != -1) {
  68. $exists = PairModel::where([
  69. ['uid', $user->uid],
  70. ['stage_id', $ings['ing']],
  71. ])->whereNotNull('assoc_id')->exists();
  72. $week4_18 = mktime(18, 0, 0, date('m'), date('d') - date('w') + 4, date('Y'));
  73. $week5_10 = mktime(10, 0, 0, date('m'), date('d') - date('w') + 5, date('Y'));
  74. if (
  75. (time() < $week4_18
  76. || time() > $week5_10)
  77. && $exists
  78. && (array_key_exists('sex', $data)
  79. || array_key_exists('sxo', $data)
  80. || array_key_exists('age', $data)
  81. || array_key_exists('address', $data)
  82. || array_key_exists('home', $data))
  83. ) {
  84. throw new AlertException("72小时活动进行或预匹配期间,不允许修改敏感信息", 102);
  85. }
  86. }
  87. // 提交素材审核事件
  88. $this->auditDiscribute($user, $data);
  89. // 是否修改了认证消息
  90. if (!empty($user->identity_auth)) {
  91. $identitys = explode(',', $user->identity_auth);
  92. $ids = array_flip($identitys);
  93. foreach ($identitys as $identity) {
  94. if (array_key_exists($identity, $data)) {
  95. unset($ids[$identity]);
  96. }
  97. }
  98. $identitys = array_flip($ids);
  99. $user->identity_auth = implode(",", $identitys);
  100. }
  101. if (array_key_exists('weixin', $data) && $user->weixin != $data['weixin']) {
  102. $data['wx_auth'] = 0;
  103. }
  104. isset($data['photo_src']) && UserPhotoLogModel::create(['uid' => $user->uid, 'src' => $data['photo_src']]);
  105. isset($data['photo_1']) && UserPhotoLogModel::create(['uid' => $user->uid, 'src' => $data['photo_1']]);
  106. isset($data['photo_2']) && UserPhotoLogModel::create(['uid' => $user->uid, 'src' => $data['photo_2']]);
  107. isset($data['photo_3']) && UserPhotoLogModel::create(['uid' => $user->uid, 'src' => $data['photo_3']]);
  108. isset($data['photo_4']) && UserPhotoLogModel::create(['uid' => $user->uid, 'src' => $data['photo_4']]);
  109. $age = $data['age'] ?? $user->age ?? null;
  110. if ($age) {
  111. $data['star'] = Birthday::star(strtotime($age));
  112. }
  113. $user->fill($data);
  114. // 更改定位后处理feed流池
  115. if ((isset($data['lat']) && isset($data['lng']) && isset($data['location']))) {
  116. $rank1 = Redis::zrank("fpdx:user:locations:sell:girl", $user->uid);
  117. $rank2 = Redis::zrank("fpdx:user:locations:sell:boy", $user->uid);
  118. if ($rank1 || $rank2) {
  119. if ($user->sex == 1) {
  120. Redis::zrem("fpdx:user:locations:sell:girl", $user->uid);
  121. Redis::geoAdd("fpdx:user:locations:sell:boy", $user->lng, $user->lat, $user->uid);
  122. } elseif ($user->sex == 2) {
  123. Redis::zrem("fpdx:user:locations:sell:boy", $user->uid);
  124. Redis::geoAdd("fpdx:user:locations:sell:girl", $user->lng, $user->lat, $user->uid);
  125. }
  126. }
  127. }
  128. $user->save();
  129. $syncFields = array(
  130. 'home',
  131. 'address',
  132. 'sex',
  133. 'photo_src',
  134. 'photo_1',
  135. 'photo_2',
  136. 'photo_3',
  137. 'photo_4',
  138. 'voice',
  139. 'school',
  140. 'subject',
  141. 'grade',
  142. 'height',
  143. 'age',
  144. 'star',
  145. 'introduce',
  146. 'expect',
  147. 'qq',
  148. 'weixin',
  149. 'education',
  150. );
  151. if (isset($syncFields['sex'])) {
  152. dispatch_now(new UserInfoReportJob([
  153. [
  154. 'loginUserId' => $user->uid,
  155. 'gender' => $syncFields['sex'] == 1 ? '男性' : ($syncFields['sex'] == 2 ? '女性' : '未知'),
  156. ],
  157. ]));
  158. }
  159. // 同步更新卡片
  160. if (
  161. isset($user->partner_id) && $user->partner_id > 0 && !empty(array_intersect(
  162. array_keys($data),
  163. $syncFields
  164. ))
  165. ) {
  166. $ps = new PartnerService();
  167. $ps->updatePartner($user->partner_id, $data);
  168. }
  169. }
  170. /**
  171. * 提交素材审核事件
  172. * @param $user
  173. * @param $data
  174. * @throws AlertException
  175. */
  176. private function auditDiscribute($user, $data)
  177. {
  178. // 昵称
  179. if (array_key_exists('nickname', $data) && $data['nickname']) {
  180. event(new AuditMedia($user->uid, 'text', $data['nickname'], 'nickname', "uid={$user->uid}"));
  181. }
  182. // 头像
  183. if (array_key_exists('headimgurl', $data) && $data['headimgurl']) {
  184. event(new AuditMedia($user->uid, 'image', $data['headimgurl'], 'headimgurl', "uid={$user->uid}"));
  185. }
  186. // 个性签名
  187. if (array_key_exists('introduce', $data) && $data['introduce']) {
  188. event(new AuditMedia($user->uid, 'text', $data['introduce'], 'introduce', "uid={$user->uid}"));
  189. }
  190. }
  191. public function toggleTag(int $uid, $tag_id, $group)
  192. {
  193. $user = UserModel::findOrFail($uid, ['tag_1', 'tag_2', 'tag_3', 'tag_4']);
  194. $taged = explode(',', $user->{"tag_{$group}"});
  195. if (in_array($tag_id, $taged)) {
  196. $key = array_search($tag_id, $taged);
  197. array_splice($taged, $key, 1);
  198. $is_add = false;
  199. } else {
  200. array_push($taged, $tag_id);
  201. $is_add = true;
  202. }
  203. UserModel::where('uid', $uid)->update(["tag_{$group}" => ltrim(trim(implode(',', $taged)), ',')]);
  204. $tagModel = new TagModel();
  205. $tagModel->flushTagByUser($uid, compact('group', 'tag_id'), $is_add);
  206. }
  207. /**
  208. * 删除照片
  209. * @param int $uid
  210. * @param string $pField
  211. * @return bool
  212. * @throws \Exception
  213. */
  214. public function deletePhoto(int $uid, string $pField)
  215. {
  216. $fields = ['photo_src', 'photo_1', 'photo_2', 'photo_3', 'photo_4'];
  217. $checks = array(
  218. 'photo_src' => 'check_photo',
  219. 'photo_1' => 'photo_1_check',
  220. 'photo_2' => 'photo_2_check',
  221. 'photo_3' => 'photo_3_check',
  222. 'photo_4' => 'photo_4_check',
  223. );
  224. $user = UserModel::findOrFail($uid);
  225. $identitys = array_flip(explode(',', $user->identity_auth));
  226. $partner = PartnerModel::find($user->partner_id);
  227. $photos = array(
  228. 'photo_src' => [
  229. 'field' => 'photo_src',
  230. 'src' => $user->photo_src,
  231. 'check' => $partner->check_photo ?? -1,
  232. 'identity_auth' => isset($identitys['photo_src']) ? true : false,
  233. ],
  234. 'photo_1' => [
  235. 'field' => 'photo_1',
  236. 'src' => $user->photo_1,
  237. 'check' => $partner->photo_1_check ?? -1,
  238. 'identity_auth' => isset($identitys['photo_1']) ? true : false,
  239. ],
  240. 'photo_2' => [
  241. 'field' => 'photo_2',
  242. 'src' => $user->photo_2,
  243. 'check' => $partner->photo_2_check ?? -1,
  244. 'identity_auth' => isset($identitys['photo_2']) ? true : false,
  245. ],
  246. 'photo_3' => [
  247. 'field' => 'photo_3',
  248. 'src' => $user->photo_3,
  249. 'check' => $partner->photo_3_check ?? -1,
  250. 'identity_auth' => isset($identitys['photo_3']) ? true : false,
  251. ],
  252. 'photo_4' => [
  253. 'field' => 'photo_4',
  254. 'src' => $user->photo_4,
  255. 'check' => $partner->photo_4_check ?? -1,
  256. 'identity_auth' => isset($identitys['photo_4']) ? true : false,
  257. ],
  258. );
  259. unset($photos[$pField]);
  260. $u_save = $p_save = $u_identity = array();
  261. foreach ($fields as $field) {
  262. $photo = array_shift($photos);
  263. if (is_null($photo)) {
  264. $u_save[$field] = null;
  265. $p_save[$field] = null;
  266. $p_save[$checks[$field]] = -1;
  267. } else {
  268. $u_save[$field] = $photo['src'];
  269. $p_save[$field] = $photo['src'];
  270. $p_save[$checks[$field]] = $photo['check'];
  271. if ($photo['identity_auth']) {
  272. array_push($u_identity, $field);
  273. }
  274. }
  275. }
  276. $u_save['identity_auth'] = implode(",", $u_identity);
  277. DB::beginTransaction();
  278. try {
  279. $user->fill($u_save);
  280. $partner->fill($p_save);
  281. // 修正上架状态
  282. if (
  283. 1 == $partner->is_sell
  284. && (empty($partner->qq)
  285. && empty($partner->weixin))
  286. || !(1 == $partner->check_photo
  287. || 1 == $partner->photo_1_check
  288. || 1 == $partner->photo_2_check
  289. || 1 == $partner->photo_3_check
  290. || 1 == $partner->photo_4_check
  291. || 1 == $partner->voice_check)
  292. ) {
  293. $partner->is_sell = 0;
  294. Redis::zrem("fpdx:user:locations:sell:boy", $partner->uid);
  295. Redis::zrem("fpdx:user:locations:sell:girl", $partner->uid);
  296. }
  297. // 修正审核状态
  298. if (
  299. 1 == $partner->is_commit_check
  300. && 0 != $partner->check_photo
  301. && 0 != $partner->photo_1_check
  302. && 0 != $partner->photo_2_check
  303. && 0 != $partner->photo_3_check
  304. && 0 != $partner->photo_4_check
  305. && 0 != $partner->voice_check
  306. ) {
  307. $partner->is_commit_check = 0;
  308. }
  309. $user->save();
  310. $partner->save();
  311. AppearanceUserJob::dispatch($user->uid)->onQueue('{appearance:user}');
  312. DB::commit();
  313. return true;
  314. } catch (\Exception $exception) {
  315. DB::rollBack();
  316. throw $exception;
  317. }
  318. }
  319. /**
  320. * 活体身份认证
  321. * @param int $uid 用户信息
  322. * @param string $face_url 用于活体检测的图片
  323. * @param string $photo_field 用于对比的图片字段
  324. * @return bool
  325. * @throws AlertException
  326. */
  327. public function fatchmatch(int $uid, string $face_url, string $photo_field)
  328. {
  329. $checks = array(
  330. 'photo_src' => 'check_photo',
  331. 'photo_1' => 'photo_1_check',
  332. 'photo_2' => 'photo_2_check',
  333. 'photo_3' => 'photo_3_check',
  334. 'photo_4' => 'photo_4_check',
  335. );
  336. $user = UserModel::findOrFail($uid);
  337. $isfield = true;
  338. if (in_array($photo_field, ['photo_src', 'photo_1', 'photo_2', 'photo_3', 'photo_4'])) {
  339. if (empty($user->{$photo_field})) {
  340. throw new AlertException("没有找到可对比的图片", 101);
  341. } else {
  342. $match_photo = "https://oss.pocketuniversity.cn" . $user->{$photo_field};
  343. }
  344. } else {
  345. $isfield = false;
  346. $match_photo = $photo_field;
  347. }
  348. $fs = new FaceService();
  349. $images = array(
  350. [
  351. 'image' => $face_url,
  352. 'image_type' => 'URL',
  353. 'face_type' => 'LIVE',
  354. 'quality_control' => 'NONE',
  355. 'liveness_control' => 'LOW',
  356. ],
  357. [
  358. 'image' => $match_photo,
  359. 'image_type' => 'URL',
  360. 'face_type' => 'LIVE',
  361. 'quality_control' => 'NONE',
  362. 'liveness_control' => 'NONE',
  363. ],
  364. );
  365. $data = $fs->match($images);
  366. $fmm = new FaceMatchModel();
  367. $md = $fmm->fill([
  368. 'uid' => $user->uid,
  369. 'check_img' => $match_photo,
  370. 'match_img' => $face_url,
  371. ]);
  372. if ($data['error_code'] == 0) {
  373. $md->score = $data['result']['score'] ?? 0;
  374. $md->save();
  375. if ($data['result']['score'] > 69) {
  376. if ($isfield) {
  377. if (empty($user->identity_auth)) {
  378. $user->identity_auth = $photo_field;
  379. } else {
  380. $identity = explode(',', $user->identity_auth);
  381. array_push($identity, $photo_field);
  382. $user->identity_auth = implode(",", array_unique($identity));
  383. }
  384. $user->save();
  385. $ns = new NoticeService();
  386. if ($user->partner_id > 0) {
  387. $ps = new PartnerService();
  388. $ps->check($user->partner_id, $checks[$photo_field], 1);
  389. }
  390. if ($user->wx_auth == 1) {
  391. $ns->authenticationSuccess($user->uid);
  392. }
  393. }
  394. return true;
  395. } else {
  396. throw new AlertException("与上传照片相似度低", 101);
  397. }
  398. } else {
  399. if ($isfield && $data['error_code'] == 222204) {
  400. FaceVerifyJob::dispatch($uid, $face_url, $user->{$photo_field}, 0)->delay(Carbon::now()->addMinutes(1));
  401. throw new AlertException("图片加载失败,已加入审核队列", 102);
  402. }
  403. $md->score = 0;
  404. $md->save();
  405. throw new AlertException("请确保光线充足,没有翻拍照片", 101);
  406. }
  407. }
  408. /**
  409. * 微信认证
  410. * @param int $uid
  411. * @param string $wxid
  412. * @param string $wxkf
  413. * @return array
  414. * @throws \Exception
  415. */
  416. public function wxverify(int $uid, string $wxid, string $wxkf): array
  417. {
  418. $user = UserModel::findOrFail($uid);
  419. $before_auth = 0;
  420. $after_auth = 0;
  421. if ($user->identity_auth && $user->wx_auth == 1) {
  422. $before_auth = 1;
  423. }
  424. if ($user->wx_auth == 1) {
  425. return array(
  426. "code" => 200,
  427. "message" => "验证成功",
  428. );
  429. }
  430. $userinfo = UserInfoModel::where('wxid', $wxid)->first();
  431. if (collect($userinfo)->isEmpty()) {
  432. app('sentry')->captureMessage("微信客服验证异常日志:%s", array("无法验证的微信号"), array(
  433. 'level' => 'info',
  434. 'extra' => array(
  435. '用户' => $uid,
  436. '微信id' => $wxid,
  437. '服务微信客服' => $wxkf,
  438. ),
  439. 'tags' => array(
  440. 'uid' => $uid,
  441. ),
  442. ));
  443. $kfmsg = array(
  444. 'task_type' => 1,
  445. 'task_dict' => array(
  446. 'wxid_to' => $wxid,
  447. 'at_list' => "",
  448. 'msg_list' => array(
  449. [
  450. 'msg_type' => 1,
  451. 'msg' => "很抱歉,认证失败。\n\n可能原因:\n\n小遇出错了,暂时没有能够检测到您设置的微信号。\n\n请确保您已设置微信号后,👇点击下方链接提醒小象导帮您人工审核。",
  452. ],
  453. [
  454. 'msg_type' => 1,
  455. 'msg' => "点击链接提醒小遇人工审核\nhttps://m.fenpeiduixiang.com/fpdx-wxauth/artifical.html?wxid={$wxid}&kf={$wxkf}",
  456. ],
  457. ),
  458. ),
  459. );
  460. Redis::sadd("wehub:task:list:{$wxkf}", [json_encode($kfmsg)]);
  461. return array(
  462. "code" => 101,
  463. "message" => "已提交验证,请耐心等待",
  464. );
  465. }
  466. DB::beginTransaction();
  467. try {
  468. // 无微信号且wxid为默认值
  469. if (empty($userinfo->wx_alias) && preg_match("/^wxid_/", $userinfo->wxid)) {
  470. $kfmsg = array(
  471. 'task_type' => 1,
  472. 'task_dict' => array(
  473. 'wxid_to' => $wxid,
  474. 'at_list' => "",
  475. 'msg_list' => array(
  476. [
  477. 'msg_type' => 1,
  478. 'msg' => "你还没有设置微信号哦,请在微信客户端设置微信号【点此链接参阅设置方法:https://jingyan.baidu.com/article/a948d6512dd2d50a2dcd2e8a.html】后,向我回复“认证”再试。\n\n若多次尝试失败,可向我回复\"人工认证\",辅助认证。",
  479. ],
  480. ),
  481. ),
  482. );
  483. Redis::sadd("wehub:task:list:{$wxkf}", [json_encode($kfmsg)]);
  484. return array(
  485. "code" => 101,
  486. "message" => "已提交验证,请耐心等待",
  487. );
  488. }
  489. // 无微信号且wxid不为默认值
  490. if (empty($userinfo->wx_alias) && !preg_match("/^wxid_/", $userinfo->wxid)) {
  491. $wx_alias = $userinfo->wxid;
  492. } elseif (empty($userinfo->wx_alias)) {
  493. $kfmsg = array(
  494. 'task_type' => 1,
  495. 'task_dict' => array(
  496. 'wxid_to' => $wxid,
  497. 'at_list' => "",
  498. 'msg_list' => array(
  499. array(
  500. 'msg_type' => 1,
  501. 'msg' => "很抱歉,认证失败。\n\n可能原因:\n\n小遇出错了,暂时没有能够检测到您设置的微信号。\n\n请确保您已设置微信号后,👇点击下方链接提醒小象导帮您人工审核",
  502. ),
  503. [
  504. 'msg_type' => 1,
  505. 'msg' => "点击链接提醒小遇人工审核\nhttps://m.fenpeiduixiang.com/fpdx-wxauth/artifical.html?wxid={$wxid}&kf={$wxkf}",
  506. ],
  507. ),
  508. ),
  509. );
  510. Redis::sadd("wehub:task:list:{$wxkf}", [json_encode($kfmsg)]);
  511. return array(
  512. "code" => 101,
  513. "message" => "已提交验证,请耐心等待",
  514. );
  515. } else {
  516. $wx_alias = $userinfo->wx_alias;
  517. }
  518. $user->wx_auth = 1;
  519. $user->weixin = $wx_alias;
  520. $user->save();
  521. if ($user->partner_id > 0) {
  522. $ps = new PartnerService();
  523. $ps->updatePartner($user->partner_id, ['weixin' => $wx_alias]);
  524. }
  525. DB::commit();
  526. (new NoticeService())->partnerCheckLog($user->uid, $user->partner_id, 'weixin', 1, 1);
  527. if ($user->identity_auth && $user->wx_auth == 1) {
  528. $after_auth = 1;
  529. }
  530. $kfmsg = array(
  531. 'task_type' => 1,
  532. 'task_dict' => array(
  533. 'wxid_to' => $wxid,
  534. 'at_list' => "",
  535. 'msg_list' => array(
  536. [
  537. 'msg_type' => 1,
  538. 'msg' => "恭喜你已完成微信认证,现在你可以回到小程序向喜欢的ta发起“心动邀请”啦。补全信息会帮助认识彼此,同时将获得更高的曝光度。\n\n小遇祝你早日脱单哦!加油~\n\n👇👇👇👇👇",
  539. ],
  540. [
  541. 'msg_type' => 3,
  542. 'msg' => "https://oss.pocketuniversity.cn/media/2019-01-09/5c35d017d6771.png",
  543. ],
  544. ),
  545. ),
  546. );
  547. Redis::sadd("wehub:task:list:{$wxkf}", [json_encode($kfmsg)]);
  548. // 发送认证通知
  549. try {
  550. if ($before_auth == 0 && $after_auth == 1) {
  551. (new NoticeService())->authenticationSuccess($user->uid);
  552. }
  553. } catch (\Exception $e) {
  554. app('sentry')->captureException($e);
  555. }
  556. return array(
  557. "code" => 200,
  558. "message" => "验证成功",
  559. );
  560. } catch (\Exception $exception) {
  561. app('sentry')->captureException($exception);
  562. $kfmsg = array(
  563. 'task_type' => 1,
  564. 'task_dict' => array(
  565. 'wxid_to' => $wxid,
  566. 'at_list' => "",
  567. 'msg_list' => array(
  568. [
  569. 'msg_type' => 1,
  570. 'msg' => "很抱歉,认证失败。\n\n可能原因:\n①您未设置微信号,请在微信客户端【我-微信号】设置。\n②小遇出错了,暂时没有能够检测到您设置的微信号。\n\n请确保您已设置微信号后,👇点击下方链接提醒小象导帮您人工审核",
  571. ],
  572. [
  573. 'msg_type' => 1,
  574. 'msg' => "点击链接提醒小遇人工审核:\nhttps://m.fenpeiduixiang.com/fpdx-wxauth/artifical.html?uid={$user->uid}&wxid={$wxid}&kf={$wxkf}",
  575. ],
  576. ),
  577. ),
  578. );
  579. Redis::sadd("wehub:task:list:{$wxkf}", [json_encode($kfmsg)]);
  580. return array(
  581. "code" => 101,
  582. "message" => "已提交验证,请耐心等待",
  583. );
  584. }
  585. }
  586. /**
  587. * 申请人工认证微信提醒
  588. * @param array $content
  589. * @param string $url
  590. * @throws \Exception
  591. */
  592. public function wxverifyWarn(array $content, string $url)
  593. {
  594. $admins = array(
  595. 10002 => "oCyEB1S75zmwncQpLI8ljxq-4oPg",
  596. 103143 => "oCyEB1ebnmeW_OUXZuaGq6-Hb-5Y",
  597. );
  598. $public_id = "gh_43ba50c16fba";
  599. $access_token = TokenModel::getToken($public_id);
  600. $apiurl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}";
  601. foreach ($admins as $admin) {
  602. $data = [
  603. 'touser' => $admin,
  604. 'template_id' => 'DhPjGWXQZqKd4ic9hSTccOOSm3AGHiYjM1ppb7td8Wo',
  605. 'url' => $url,
  606. 'data' => $content,
  607. ];
  608. \Curl::to($apiurl)->withData($data)->asJson()->post();
  609. }
  610. }
  611. /**
  612. * 成为vip
  613. * @param int $uid
  614. * @param bool $bevip 是否成为vip
  615. * @param bool $isAllNotice
  616. * @return bool
  617. */
  618. public function beVip(int $uid, $bevip = true, $isAllNotice = false)
  619. {
  620. $ns = new \App\Services\User\NoticeService();
  621. /** @var UserModel $user */
  622. $user = UserModel::findOrFail($uid);
  623. $platform = \Config::get('platform');
  624. if ($user->be_vip_at > 0 && $bevip === true) {
  625. if ($isAllNotice) {
  626. $ns->bevip($user->uid);
  627. }
  628. return true;
  629. }
  630. if ($bevip) {
  631. $user->be_vip_at = time();
  632. VipLogModel::openVip($uid);
  633. try {
  634. $ns->bevip($user->uid);
  635. dispatch_now(new UserVipReportJob($user, true, $platform));
  636. } catch (\Exception $exception) {
  637. }
  638. } else {
  639. $auth = AuthKey::where([['auth_type', 'kdgx_unionid'], ['uid', $uid]])->first();
  640. if (
  641. $auth && !Openid::where([['unionid', $auth->auth_key], ['subscribe', 1]])->whereIn(
  642. 'public_id',
  643. ['gh_c94c95866ca5', 'gh_b598cb7474d8']
  644. )->exists()
  645. ) {
  646. $user->be_vip_at = 0;
  647. VipLogModel::closeVip($uid);
  648. try {
  649. $ns->outvip($user->uid);
  650. dispatch_now(new UserVipReportJob($user, false, $platform));
  651. } catch (\Exception $exception) {
  652. SentryFacade::captureMessage($exception);
  653. }
  654. } else {
  655. return false;
  656. }
  657. }
  658. $user->save();
  659. return false;
  660. }
  661. }