User.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Ems;
  5. use app\common\library\Sms;
  6. use fast\Random;
  7. use think\Config;
  8. use think\Validate;
  9. use app\common\library\Token;
  10. use think\Db;
  11. use app\common\model\UserDeviceInfo;
  12. use onlogin\onlogin;
  13. use addons\epay\library\Service;
  14. use app\common\library\Wechat;
  15. use TencentCloud\Common\Credential;
  16. use TencentCloud\Common\Profile\ClientProfile;
  17. use TencentCloud\Common\Profile\HttpProfile;
  18. use TencentCloud\Common\Exception\TencentCloudSDKException;
  19. use TencentCloud\Faceid\V20180301\FaceidClient;
  20. use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
  21. use TencentCloud\Iai\V20200303\IaiClient;
  22. use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  23. /**
  24. * 会员接口,登录,注册,修改资料等
  25. */
  26. class User extends Api
  27. {
  28. protected $noNeedLogin = ['emaillogin','emailregister','mobilelogin','resetpwd'];
  29. protected $noNeedRight = '*';
  30. public function _initialize()
  31. {
  32. parent::_initialize();
  33. }
  34. /**
  35. * 邮箱登录
  36. *
  37. * @ApiMethod (POST)
  38. * @param string $account 账号
  39. * @param string $password 密码
  40. */
  41. public function emaillogin()
  42. {
  43. $account = input('account');
  44. $password = input('password');
  45. if (!$account || !$password) {
  46. $this->error(__('Invalid parameters'));
  47. }
  48. if (!Validate::is($account, 'email')) {
  49. $this->error(__('Email is incorrect'));
  50. }
  51. $ret = $this->auth->login($account, $password);
  52. if ($ret) {
  53. $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
  54. } else {
  55. $this->error($this->auth->getError());
  56. }
  57. }
  58. //邮箱注册
  59. public function emailregister()
  60. {
  61. $account = input('account');
  62. $captcha = input('captcha');
  63. $password = input('password');
  64. if (!$account || !$captcha || !$password) {
  65. $this->error(__('Invalid parameters'));
  66. }
  67. if (!Validate::is($account, 'email')) {
  68. $this->error(__('Email is incorrect'));
  69. }
  70. $ret = Ems::check($account, $captcha, 'register');
  71. if (!$ret) {
  72. $this->error(__('Captcha is incorrect'));
  73. }
  74. $extend = [
  75. 'register_from' => input('register_from',''),
  76. 'gender' => -1
  77. ];
  78. $ret = $this->auth->register('',$password,$account,'', $extend);
  79. if ($ret) {
  80. Ems::flush($account);
  81. $this->success('注册成功', $this->auth->getUserinfo_simple());
  82. } else {
  83. $this->error($this->auth->getError());
  84. }
  85. }
  86. /**
  87. * 手机验证码登录 + 注册
  88. *
  89. * @ApiMethod (POST)
  90. * @param string $mobile 手机号
  91. * @param string $captcha 验证码
  92. */
  93. public function mobilelogin()
  94. {
  95. $mobile = input('mobile');
  96. $captcha = input('captcha');
  97. if (!$mobile || !$captcha) {
  98. $this->error(__('Invalid parameters'));
  99. }
  100. if (!Validate::regex($mobile, "^1\d{10}$")) {
  101. $this->error(__('Mobile is incorrect'));
  102. }
  103. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  104. $this->error(__('Captcha is incorrect'));
  105. }
  106. $user = \app\common\model\User::getByMobile($mobile);
  107. if ($user) {
  108. if ($user->status == -1) {
  109. $this->error('账户已注销');
  110. }
  111. if (!in_array($user->status,[1,2])) {
  112. $this->error(__('Account is locked'));
  113. }
  114. if ($user->frozentime > time()) {
  115. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  116. }
  117. //如果已经有账号则直接登录
  118. $ret = $this->auth->direct($user->id);
  119. } else {
  120. $extend = [
  121. 'register_from' => input('register_from',''),
  122. 'gender' => -1
  123. ];
  124. $ret = $this->auth->register('', '', '', $mobile, $extend);
  125. }
  126. if ($ret) {
  127. Sms::flush($mobile, 'mobilelogin');
  128. $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
  129. } else {
  130. $this->error($this->auth->getError());
  131. }
  132. }
  133. //注册设置性别
  134. public function setgender() {
  135. $user_id = $this->auth->id;
  136. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  137. if (!in_array($gender, [1, 0])) {
  138. $this->error('性别错误');
  139. }
  140. $edit_data['gender'] = $gender;
  141. $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
  142. $rs = Db::name('user')->where(['id' => $user_id])->update($edit_data);
  143. if ($rs === false) {
  144. $this->error('您的网络开小差啦~');
  145. }
  146. //$data = $this->userInfo('return');
  147. $data['gender'] = $edit_data['gender'];
  148. $data['avatar'] = $edit_data['avatar'];
  149. $this->success('success', $data);
  150. }
  151. //注册完善资料
  152. public function perfect_info() {
  153. $avatar = input('avatar', '', 'trim'); //头像
  154. $nickname = input('nickname', '', 'trim'); //昵称
  155. $birthday = input('birthday', '', 'strtotime'); //生日
  156. $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
  157. $bio = input('bio', '', 'trim'); //个性签名
  158. $hobby = input('hobby', '', 'trim'); //爱好
  159. $marital = input('marital', '', 'trim'); //婚姻
  160. $introcode = input('introcode', '', 'trim'); //邀请码
  161. $data = [];
  162. if ($avatar) {
  163. $data['avatar'] = $avatar;
  164. }
  165. if ($nickname !== '') {
  166. if (iconv_strlen($nickname, 'utf-8') > 10) {
  167. $this->error('昵称最多10个字~');
  168. }
  169. $data['nickname'] = $nickname;
  170. }
  171. if ($birthday) {
  172. $data['birthday'] = $birthday;
  173. }
  174. if ($hometown_cityid) {
  175. $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
  176. if (!$count) {
  177. $this->error('城市不存在');
  178. }
  179. $data['hometown_cityid'] = $hometown_cityid;
  180. }
  181. if ($bio) {
  182. $data['bio'] = $bio;
  183. }
  184. if ($hobby) {
  185. $data['hobby'] = $hobby;
  186. }
  187. if ($marital) {
  188. $data['marital'] = $marital;
  189. }
  190. if ($introcode && !$this->auth->intro_uid) {
  191. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  192. if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
  193. $data['intro_uid'] = $intro_user['id'];
  194. $data['invite_time'] = time();
  195. }
  196. }
  197. //开启事务
  198. Db::startTrans();
  199. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  200. if($update_rs === false){
  201. Db::rollback();
  202. $this->error('修改失败');
  203. }
  204. //给上级发放钻石
  205. if(isset($data['intro_uid'])){
  206. $intro_jewel = config('site.new_user_intro_jewel');
  207. if($intro_jewel > 0){
  208. $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
  209. if($rs_wallet['status'] === false){
  210. Db::rollback();
  211. $this->error('邀请新人奖励赠送失败');
  212. }
  213. }
  214. }
  215. //上传头像加5金币
  216. if(isset($data['avatar'])){
  217. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  218. if($task_rs === false){
  219. Db::rollback();
  220. $this->error('完成任务赠送奖励失败');
  221. }
  222. }
  223. if (isset($data['birthday'])) {
  224. //完成设置生日 +5金币
  225. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  226. if($task_rs === false){
  227. Db::rollback();
  228. $this->error('完成任务赠送奖励失败');
  229. }
  230. }
  231. Db::commit();
  232. $this->success('修改成功');
  233. }
  234. //用户详细资料
  235. public function userInfo($type = 1){
  236. $info = $this->auth->getUserinfo();
  237. if($type == 'return'){
  238. return $info;
  239. }
  240. $this->success(__('success'),$info);
  241. }
  242. /**
  243. * 修改会员个人信息
  244. *
  245. * @ApiMethod (POST)
  246. * @param string $avatar 头像地址
  247. * @param string $username 用户名
  248. * @param string $nickname 昵称
  249. * @param string $bio 个人简介
  250. */
  251. public function profile()
  252. {
  253. $field_array = ['nickname','introcode',/*'gender',*/'birthday','height','weight','bio','audio_bio','avatar','photo_images','education','hobby','job','marital','tag','wages','hometown_cityid','hide_is_finishinfo',/*'wechat_account',*/'character','constellation','stature','is_appointment', 'greet_voice', 'greet_chat', 'is_cohabit', 'live', 'is_house', 'car', 'chest', 'waist'];
  254. $data = [];
  255. foreach($field_array as $key => $field){
  256. if(!input('?'.$field)){
  257. continue;
  258. }
  259. $newone = input($field);
  260. if($field == 'avatar'){
  261. // if ($this->auth->real_status == 1) {
  262. //$this->error('您已经真人认证不能修改头像~');
  263. // die;
  264. // }
  265. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  266. }
  267. if($field == 'photo_images'){
  268. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  269. }
  270. $data[$field] = $newone;
  271. }
  272. if(isset($data['birthday'])){
  273. $data['birthday'] = strtotime($data['birthday']);
  274. }
  275. if(isset($data['avatar'])){
  276. //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
  277. }
  278. if(isset($data['introcode'])){
  279. if ($this->auth->intro_uid != 0) {
  280. $this->error('邀请人不可修改~');
  281. }
  282. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
  283. if(!$intro_user){
  284. $this->error('不存在的邀请人');
  285. }
  286. if ($intro_user['id'] == $this->auth->id) {
  287. $this->error('不能填写自己邀请码');
  288. }
  289. if ($intro_user['intro_uid'] == $this->auth->id) {
  290. $this->error('不能填写下级邀请码');
  291. }
  292. unset($data['introcode']);//别人的邀请码,不能改了自己的
  293. $data['intro_uid'] = $intro_user['id'];
  294. $data['invite_time'] = time();
  295. }
  296. //dump($data);
  297. if(empty($data)){
  298. $this->error('没有任何改变');
  299. }
  300. Db::startTrans();
  301. $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
  302. if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {//隐藏
  303. $boyAvatar = config('avatar_boy');
  304. $girlAvatar = config('avatar_girl');
  305. if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
  306. $data['status'] = 1;//更新为正常
  307. } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
  308. $data['status'] = 1;//更新为正常
  309. }
  310. }
  311. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  312. if($update_rs === false){
  313. Db::rollback();
  314. $this->error('修改资料失败');
  315. }
  316. //给上级发放钻石
  317. if(isset($data['intro_uid'])){
  318. $intro_jewel = config('site.new_user_intro_jewel');
  319. if($intro_jewel > 0){
  320. $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
  321. if($rs_wallet['status'] === false){
  322. Db::rollback();
  323. $this->error('邀请新人奖励赠送失败');
  324. }
  325. }
  326. }
  327. //tag任务赠送金币
  328. //上传头像加5金币
  329. if(isset($data['avatar'])){
  330. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  331. if($task_rs === false){
  332. Db::rollback();
  333. $this->error('完成任务赠送奖励失败');
  334. }
  335. }
  336. //上传生日 +5金币
  337. if (isset($data['birthday'])) {
  338. //完成设置生日 +5金币
  339. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  340. if($task_rs === false){
  341. Db::rollback();
  342. $this->error('完成任务赠送奖励失败');
  343. }
  344. }
  345. //上传个性签名 5金币
  346. if(isset($data['audio_bio'])){
  347. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
  348. if($task_rs === false){
  349. Db::rollback();
  350. $this->error('完成任务赠送奖励失败');
  351. }
  352. }
  353. //上传本人语音介绍 10金币
  354. if(isset($data['audio_bio'])){
  355. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
  356. if($task_rs === false){
  357. Db::rollback();
  358. $this->error('完成任务赠送奖励失败');
  359. }
  360. }
  361. //上传本人五张照片 10金币
  362. if(isset($data['photo_images'])){
  363. $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
  364. if ($photo_images_num >= 5) {
  365. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
  366. if ($task_rs === false) {
  367. Db::rollback();
  368. $this->error('完成任务赠送奖励失败');
  369. }
  370. }
  371. }
  372. Db::commit();
  373. $this->success();
  374. }
  375. /**
  376. * 退出登录
  377. * @ApiMethod (POST)
  378. */
  379. public function logout()
  380. {
  381. if (!$this->request->isPost()) {
  382. $this->error(__('Invalid parameters'));
  383. }
  384. //退出im
  385. $tenIm = new Tenim();
  386. $tenIm->loginoutim($this->auth->id);
  387. //修改用户活跃0
  388. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
  389. $this->auth->logout();
  390. $this->success(__('Logout successful'));
  391. }
  392. /**
  393. * 重置密码
  394. *
  395. * @ApiMethod (POST)
  396. * @param string $mobile 手机号
  397. * @param string $newpassword 新密码
  398. * @param string $captcha 验证码
  399. */
  400. public function resetpwd()
  401. {
  402. //$type = input("type");
  403. $type = 'email';
  404. $mobile = input("mobile");
  405. $email = input("email");
  406. $newpassword = input("newpassword");
  407. $captcha = input("captcha");
  408. if (!$newpassword || !$captcha) {
  409. $this->error(__('Invalid parameters'));
  410. }
  411. if ($type == 'mobile') {
  412. if (!Validate::regex($mobile, "^1\d{10}$")) {
  413. $this->error(__('Mobile is incorrect'));
  414. }
  415. $user = \app\common\model\User::getByMobile($mobile);
  416. if (!$user) {
  417. $this->error(__('User not found'));
  418. }
  419. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  420. if (!$ret) {
  421. $this->error(__('Captcha is incorrect'));
  422. }
  423. Sms::flush($mobile, 'resetpwd');
  424. } else {
  425. if (!Validate::is($email, "email")) {
  426. $this->error(__('Email is incorrect'));
  427. }
  428. $user = \app\common\model\User::getByEmail($email);
  429. if (!$user) {
  430. $this->error(__('User not found'));
  431. }
  432. $ret = Ems::check($email, $captcha, 'resetpwd');
  433. if (!$ret) {
  434. $this->error(__('Captcha is incorrect'));
  435. }
  436. Ems::flush($email, 'resetpwd');
  437. }
  438. //模拟一次登录
  439. $this->auth->direct($user->id);
  440. $ret = $this->auth->changepwd($newpassword, '', true);
  441. if ($ret) {
  442. $this->success(__('Reset password successful'));
  443. } else {
  444. $this->error($this->auth->getError());
  445. }
  446. }
  447. //假注销
  448. public function cancleUser(){
  449. if (!$this->request->isPost()) {
  450. $this->error(__('Invalid parameters'));
  451. }
  452. //退出im
  453. $tenIm = new Tenim();
  454. $tenIm->loginoutim($this->auth->id);
  455. $data = [
  456. 'status' => -1,
  457. 'mobile' => 'close_'.$this->auth->mobile,
  458. 'wechat_openid' => 'close_'.$this->auth->wechat_openid,
  459. ];
  460. Db::name('user')->where('id',$this->auth->id)->update($data);
  461. $this->auth->logout();
  462. $this->success('注销成功');
  463. }
  464. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  465. /**
  466. * 手机验证码验证
  467. *
  468. * @ApiMethod (POST)
  469. * @param string $mobile 手机号
  470. * @param string $captcha 验证码
  471. */
  472. /*public function mobilecheck()
  473. {
  474. $mobile = input('mobile');
  475. $captcha = input('captcha');
  476. if (!$mobile || !$captcha) {
  477. $this->error(__('Invalid parameters'));
  478. }
  479. if (!Validate::regex($mobile, "^1\d{10}$")) {
  480. $this->error(__('Mobile is incorrect'));
  481. }
  482. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  483. $this->error(__('Captcha is incorrect'));
  484. }
  485. $this->success('验证通过');
  486. }*/
  487. /**
  488. * 手机验证码注册
  489. *
  490. * @ApiMethod (POST)
  491. * @param string $mobile 手机号
  492. * @param string $captcha 验证码
  493. * @param string $gender 性别:1=男,0=女
  494. */
  495. /*public function mobileregister()
  496. {
  497. $mobile = input('mobile');
  498. $captcha = input('captcha');
  499. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  500. if (!$mobile || !$captcha) {
  501. $this->error(__('Invalid parameters'));
  502. }
  503. if (!Validate::regex($mobile, "^1\d{10}$")) {
  504. $this->error(__('Mobile is incorrect'));
  505. }
  506. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  507. $this->error(__('Captcha is incorrect'));
  508. }
  509. if (!in_array($gender, [1, 0])) {
  510. $this->error('性别错误');
  511. }
  512. $user = \app\common\model\User::getByMobile($mobile);
  513. if ($user) {
  514. $this->error('账号已经存在,请直接登录');
  515. if ($user->status == -1) {
  516. $this->error('账户已注销');
  517. }
  518. if (!in_array($user->status,[1,2])) {
  519. $this->error(__('Account is locked'));
  520. }
  521. //如果已经有账号则直接登录
  522. $ret = $this->auth->direct($user->id);
  523. } else {
  524. $extend = [
  525. 'register_from' => input('register_from',''),
  526. 'gender' => $gender
  527. ];
  528. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  529. }
  530. if ($ret) {
  531. Sms::flush($mobile, 'mobilelogin');
  532. $data = $this->userInfo('return');
  533. $this->success(__('Logged in successful'), $data);
  534. } else {
  535. $this->error($this->auth->getError());
  536. }
  537. }*/
  538. /**
  539. * 运营商一键登录
  540. */
  541. /*public function onLogin()
  542. {
  543. $accessToken = input('accessToken');// 运营商预取号获取到的token
  544. $token = input('tokenT');// 易盾返回的token
  545. if (!$accessToken || !$token) {
  546. $this->error("参数获取失败!");
  547. }
  548. $params = array(
  549. // 运营商预取号获取到的token
  550. "accessToken" => $accessToken,
  551. // 易盾返回的token
  552. "token" => $token
  553. );
  554. // 获取密钥配置
  555. $configInfo = config("onLogin");
  556. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  557. $onret = $onlogin->check($params);
  558. // $ret = [];
  559. // $ret["code"] = 200;
  560. // $ret["msg"] = "ok";
  561. // $ret["data"] = [
  562. // "phone" => "17574504021",
  563. // "resultCode" => 0
  564. // ];
  565. if ($onret["code"] == 200) {
  566. $mobile = $onret["data"]["phone"];
  567. if (empty($mobile)) {
  568. // 取号失败,建议进行二次验证,例如短信验证码
  569. $this->error("取号登录失败,请用验证码方式登录!");
  570. } else {
  571. // 取号成功, 执行登录等流程
  572. // 用户登录逻辑 === 开始
  573. $user = \app\common\model\User::getByMobile($mobile);
  574. if ($user) {
  575. if (!in_array($user->status,[1,2])) {
  576. $this->error(__('Account is locked'));
  577. }
  578. if ($user->frozentime > time()) {
  579. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  580. }
  581. //如果已经有账号则直接登录
  582. $ret = $this->auth->direct($user->id);
  583. $is_register = 0;
  584. } else {
  585. $extend = [
  586. 'register_from' => input('register_from',''),
  587. 'gender' => -1
  588. ];
  589. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  590. $is_register = 1;
  591. }
  592. if ($ret) {
  593. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  594. } else {
  595. $this->error($this->auth->getError());
  596. }
  597. // 用户登录逻辑 === 结束
  598. }
  599. } else {
  600. $this->error("登录失败,请用验证码方式登录!");
  601. }
  602. }*/
  603. /**
  604. * 运营商一键登录注册
  605. */
  606. /*public function onregister()
  607. {
  608. $accessToken = input('accessToken');// 运营商预取号获取到的token
  609. $token = input('tokenT');// 易盾返回的token
  610. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  611. if (!$accessToken || !$token) {
  612. $this->error("参数获取失败!");
  613. }
  614. if (!in_array($gender, [1, 0])) {
  615. $this->error('性别错误');
  616. }
  617. $params = array(
  618. // 运营商预取号获取到的token
  619. "accessToken" => $accessToken,
  620. // 易盾返回的token
  621. "token" => $token
  622. );
  623. // 获取密钥配置
  624. $configInfo = config("onLogin");
  625. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  626. $onret = $onlogin->check($params);
  627. // $ret = [];
  628. // $ret["code"] = 200;
  629. // $ret["msg"] = "ok";
  630. // $ret["data"] = [
  631. // "phone" => "17574504021",
  632. // "resultCode" => 0
  633. // ];
  634. if ($onret["code"] == 200) {
  635. $mobile = $onret["data"]["phone"];
  636. if (empty($mobile)) {
  637. // 取号失败,建议进行二次验证,例如短信验证码
  638. $this->error("取号登录失败,请用验证码方式登录!");
  639. } else {
  640. // 取号成功, 执行登录等流程
  641. // 用户登录逻辑 === 开始
  642. $user = \app\common\model\User::getByMobile($mobile);
  643. if ($user) {
  644. $this->error('账号已经存在,请直接登录');
  645. if (!in_array($user->status,[1,2])) {
  646. $this->error(__('Account is locked'));
  647. }
  648. //如果已经有账号则直接登录
  649. $ret = $this->auth->direct($user->id);
  650. $is_register = 0;
  651. } else {
  652. $extend = [
  653. 'register_from' => input('register_from',''),
  654. 'gender' => $gender
  655. ];
  656. $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
  657. $is_register = 1;
  658. }
  659. //结果
  660. if ($ret) {
  661. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  662. } else {
  663. $this->error($this->auth->getError());
  664. }
  665. // 用户登录逻辑 === 结束
  666. }
  667. } else {
  668. $this->error("登录失败,请用验证码方式登录!");
  669. }
  670. }*/
  671. //微信登录,预先假注册
  672. /*public function wechatlogin(){
  673. $code = input('code','');
  674. if(!$code){
  675. $this->error(__('Invalid parameters'));
  676. }
  677. //微信
  678. $wechat = new Wechat();
  679. $wxuserinfo = $wechat->getAccessToken($code);
  680. if(!$wxuserinfo){
  681. $this->error('openid获取失败');
  682. }
  683. if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
  684. $this->error('openid获取失败');
  685. }
  686. $openid = $wxuserinfo['openid'];
  687. //检查用户
  688. $user = Db::name('user')->where('wechat_openid',$openid)->find();
  689. if ($user) {
  690. if ($user['status'] == -1) {
  691. $this->error('账户已注销');
  692. }
  693. if ($user['status'] != 1) {
  694. $this->error(__('Account is locked'));
  695. }
  696. //如果已经有账号则直接登录
  697. $ret = $this->auth->direct($user['id']);
  698. if ($ret) {
  699. $userInfo = $this->auth->getUserinfo();
  700. $userInfo['is_register'] = 0;
  701. $userInfo['code'] = $code;
  702. $this->success(__('Logged in successful'), $userInfo);
  703. } else {
  704. $this->error($this->auth->getError());
  705. }
  706. } else {
  707. //记录code和openid,绑定手机号的时候更新openid
  708. $wechatCodeData = [
  709. 'code' => $code,
  710. 'openid' => $openid,
  711. 'createtime' => time(),
  712. ];
  713. $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
  714. if (empty($wechatCode)) {
  715. Db::name('wechat_code')->insertGetId($wechatCodeData);
  716. } else {
  717. Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
  718. }
  719. //直接返回
  720. $userInfo = [];
  721. $userInfo['is_register'] = 1;
  722. $userInfo['code'] = $code;
  723. $this->success('获取信息成功', $userInfo);
  724. }
  725. }*/
  726. /**
  727. * 微信注册来的,绑定手机号
  728. *
  729. * @ApiMethod (POST)
  730. * @param string $mobile 手机号
  731. * @param string $captcha 验证码
  732. */
  733. /*public function wechatbindmobile()
  734. {
  735. $mobile = $this->request->param('mobile');
  736. $captcha = $this->request->param('captcha');
  737. $code = $this->request->param('code');
  738. if (!$mobile || !$captcha || !$code) {
  739. $this->error(__('Invalid parameters'));
  740. }
  741. if (!Validate::regex($mobile, "^1\d{10}$")) {
  742. $this->error(__('Mobile is incorrect'));
  743. }
  744. $result = Sms::check($mobile, $captcha, 'changemobile');
  745. if (!$result) {
  746. $this->error(__('Captcha is incorrect'));
  747. }
  748. $wechatCodeWhere['code'] = $code;
  749. $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
  750. if (empty($wechatCode)) {
  751. $this->error('请先微信登录');
  752. }
  753. //检查appid绑定的用户
  754. $user = Db::name('user')->where('wechat_openid',$wechatCode['openid'])->find();
  755. if ($user) {
  756. if ($user['status'] == -1) {
  757. $this->error('账户已注销');
  758. }
  759. if ($user['status'] != 1) {
  760. $this->error(__('Account is locked'));
  761. }
  762. //如果已经有账号则直接登录
  763. $ret = $this->auth->direct($user['id']);
  764. $this->success('success',$this->auth->getUserinfo());
  765. }
  766. //新的openid用户
  767. $where = [];
  768. $where['mobile'] = $mobile;
  769. $userData = Db::name('user')->where($where)->find();//老用户
  770. if (!empty($userData)) {
  771. if (empty($userData['wechat_openid'])) {
  772. Db::name('user')->where('id',$userData['id'])->update(['wechat_openid' => $wechatCode['openid']]);//老用户更新openid
  773. } else {
  774. if ($userData['wechat_openid'] != $wechatCode['openid']) {
  775. $this->error('该手机号已被其他用户绑定');
  776. }
  777. }
  778. $ret = $this->auth->direct($userData['id']);
  779. } else {
  780. $extend = [
  781. 'wechat_openid' => $wechatCode['openid'],
  782. ];
  783. $ret = $this->auth->register('', '','', $mobile, $extend);
  784. }
  785. if (!$ret) {
  786. $this->error($this->auth->getError());
  787. }
  788. $this->success('success',$this->auth->getUserinfo());
  789. }*/
  790. public function testhaibao(){
  791. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
  792. // dump($haibao);
  793. $this->success('success', $haibao);
  794. }
  795. //海报
  796. public function haibao($player_id,$data){
  797. //下载页二维码,没必要保留
  798. $params = [
  799. 'text' => config('site.domain_name').'?code=' . $data['introcode'],
  800. 'size' => 90,
  801. 'logo' => false,
  802. 'label' => false,
  803. 'padding' => 0,
  804. ];
  805. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  806. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  807. mk_dir($qrcode_path);
  808. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  809. $qrCode->writeFile($download_qrcode);
  810. //海报
  811. $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
  812. return $haibao;
  813. }
  814. /*public function createhaibao($download_qrcode,$player_id,$sub_data){
  815. //背景图
  816. $background = $sub_data['background'] ? $sub_data['background'] : config('site.domain_name').'/assets/img/haibao.png';
  817. //海报图片路径
  818. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  819. mk_dir($new_path);
  820. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  821. //二维码
  822. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  823. //合成wap图片
  824. $image = new \addons\poster\library\Image2();
  825. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  826. return '/'.$wap_file_name;
  827. }*/
  828. public function createhaibao($download_qrcode,$player_id,$sub_data){
  829. //二维码
  830. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  831. $data = [
  832. [
  833. "left" => "15px",
  834. "top" => "296px",
  835. "type" => "img",
  836. "width" => "58px",
  837. "height" => "58px",
  838. "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  839. ],
  840. [
  841. "left" => "81px",
  842. "top" => "300px",
  843. "type" => "nickname",
  844. "width" => "80px",
  845. "height" => "24px",
  846. "size" => "12px",
  847. "color" => "#000",
  848. "content" => $this->auth->nickname
  849. ],
  850. [
  851. "left" => "81px",
  852. "top" => "327px",
  853. "type" => "nickname",
  854. "width" => "80px",
  855. "height" => "24px",
  856. "size" => "12px",
  857. "color" => "#000",
  858. "content" => $this->auth->introcode
  859. ],
  860. [
  861. "left" => "227px",
  862. "top" => "283px",
  863. "type" => "img",
  864. "width" => "80px",
  865. "height" => "80px",
  866. // "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  867. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  868. ]
  869. ];
  870. $data = json_encode($data, 320);
  871. $poster = [
  872. 'id' => 1,
  873. 'title' => '测试2',
  874. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  875. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  876. 'data' => $data,
  877. 'status' => 'normal',
  878. 'weigh' => 0,
  879. 'createtime' => 1653993709,
  880. 'updatetime' => 1653994259,
  881. ];
  882. $image = new \addons\poster\library\Image();
  883. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  884. if (!$imgurl) {
  885. $this->error('生成海报出错');
  886. }
  887. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  888. return '/' . $imgurl;
  889. }
  890. //实名认证信息
  891. public function idcard_confirm_info(){
  892. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  893. if (!$check) {
  894. $check = (object)[];
  895. }
  896. $this->success('success',$check);
  897. }
  898. /*
  899. * 修改用户的坐标
  900. * */
  901. public function change_longlat(){
  902. $longitude = input_post('longitude');
  903. $latitude = input_post('latitude');
  904. $cityname = input_post('cityname');
  905. if(empty($longitude) || empty($latitude) || empty($cityname)){
  906. $this->error();
  907. }
  908. $data = [
  909. 'longitude' => $longitude,
  910. 'latitude' => $latitude,
  911. 'cityname' => $cityname,
  912. ];
  913. Db::name('user')->where('id',$this->auth->id)->update($data);
  914. $this->success();
  915. }
  916. /**
  917. * 修改手机号
  918. *
  919. * @ApiMethod (POST)
  920. * @param string $mobile 手机号
  921. * @param string $captcha 验证码
  922. */
  923. public function changemobile()
  924. {
  925. $user = $this->auth->getUser();
  926. $oldcaptcha = $this->request->request('oldcaptcha');
  927. $mobile = $this->request->request('mobile');
  928. $captcha = $this->request->request('captcha');
  929. if (!$oldcaptcha || !$mobile || !$captcha) {
  930. $this->error(__('Invalid parameters'));
  931. }
  932. if (!Validate::regex($mobile, "^1\d{10}$")) {
  933. $this->error(__('Mobile is incorrect'));
  934. }
  935. if($user->mobile == $mobile){
  936. $this->error('新手机号不能与旧手机号相同');
  937. }
  938. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  939. $this->error(__('Mobile already exist'));
  940. }
  941. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  942. if (!$result) {
  943. $this->error(__('Captcha is incorrect'));
  944. }
  945. $result = Sms::check($mobile, $captcha, 'changemobile');
  946. if (!$result) {
  947. $this->error(__('Captcha is incorrect'));
  948. }
  949. /*$verification = $user->verification;
  950. $verification->mobile = 1;
  951. $user->verification = $verification;*/
  952. $user->mobile = $mobile;
  953. $user->save();
  954. Sms::flush($user->mobile, 'changemobile');
  955. Sms::flush($mobile, 'changemobile');
  956. $this->success();
  957. }
  958. /**
  959. * 微信注册来的,绑定手机号
  960. *
  961. * @ApiMethod (POST)
  962. * @param string $mobile 手机号
  963. * @param string $captcha 验证码
  964. */
  965. /*public function bindmobile()
  966. {
  967. $user = $this->auth->getUser();
  968. $mobile = $this->request->request('mobile');
  969. $captcha = $this->request->request('captcha');
  970. if(!empty($this->auth->mobile)){
  971. $this->error('已经绑定了手机号');
  972. }
  973. if (!$mobile || !$captcha) {
  974. $this->error(__('Invalid parameters'));
  975. }
  976. if (!Validate::regex($mobile, "^1\d{10}$")) {
  977. $this->error(__('Mobile is incorrect'));
  978. }
  979. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  980. $this->error('该手机号已被其他用户绑定');
  981. }
  982. $result = Sms::check($mobile, $captcha, 'changemobile');
  983. if (!$result) {
  984. $this->error(__('Captcha is incorrect'));
  985. }
  986. $verification = $user->verification;
  987. $verification->mobile = 1;
  988. $user->verification = $verification;
  989. $user->mobile = $mobile;
  990. $user->save();
  991. Sms::flush($mobile, 'changemobile');
  992. //手机号奖励
  993. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
  994. if($task_rs === false){
  995. Db::rollback();
  996. return false;
  997. }
  998. $this->success('success',$this->userInfo('return'));
  999. }*/
  1000. /**
  1001. * 手机号注册来的,绑定微信
  1002. *
  1003. * @ApiMethod (POST)
  1004. * @param string wechat_openid 微信openid
  1005. */
  1006. /*public function bindopenid()
  1007. {
  1008. $user = $this->auth->getUser();
  1009. $wechat_openid = $this->request->request('wechat_openid');
  1010. if(!empty($this->auth->wechat_openid)){
  1011. $this->error('已经绑定了微信号');
  1012. }
  1013. if (!$wechat_openid) {
  1014. $this->error(__('Invalid parameters'));
  1015. }
  1016. if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
  1017. $this->error('该微信号已被其他用户绑定');
  1018. }
  1019. $user->wechat_openid = $wechat_openid;
  1020. $user->save();
  1021. $this->success('success',$this->userInfo('return'));
  1022. }*/
  1023. /**
  1024. * 修改密码
  1025. *
  1026. * @ApiMethod (POST)
  1027. * @param string $newpassword 新密码
  1028. * @param string $oldpassword 旧密码
  1029. */
  1030. public function changepwd(){
  1031. $newpassword = input('newpassword');
  1032. $oldpassword = input('oldpassword','');
  1033. if (!$newpassword) {
  1034. $this->error(__('Invalid parameters'));
  1035. }
  1036. if($this->auth->password && empty($oldpassword)){
  1037. $this->error('原密码必填');
  1038. }
  1039. if(empty($this->auth->password)){
  1040. $ret = $this->auth->changepwd($newpassword, '', true);
  1041. }else{
  1042. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  1043. }
  1044. if ($ret) {
  1045. $this->success(__('Reset password successful'));
  1046. } else {
  1047. $this->error($this->auth->getError());
  1048. }
  1049. }
  1050. /**
  1051. * 记录当前登陆的设备ID,设备信息,IP等
  1052. */
  1053. /* public function changeDeviceIp()
  1054. {
  1055. // 接口防并发
  1056. if (!$this->apiLimit(1, 5)) {
  1057. return ;
  1058. }
  1059. $user = $this->auth->getUser();
  1060. $ip = request()->ip();
  1061. $deviceId = $this->request->request('device_id','');
  1062. $phoneModel = $this->request->request('phone_model','');
  1063. $brand = $this->request->request('brand','');
  1064. $apiVersion = $this->request->request('api_version','');
  1065. $deviceOs = $this->request->request('device_os','');
  1066. if ($ip !== $user->loginip){
  1067. $update = [];
  1068. $update['id'] = $user->id;
  1069. $update['loginip'] = $ip;
  1070. \app\common\model\User::update($update);
  1071. }
  1072. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  1073. if (empty($userDeviceInfo)){
  1074. $userDeviceInfo = new UserDeviceInfo();
  1075. $userDeviceInfo->user_id = $user->u_id;
  1076. }
  1077. $userDeviceInfo->device_os = $deviceOs;
  1078. $userDeviceInfo->device_id = $deviceId;
  1079. $userDeviceInfo->phone_model = $phoneModel;
  1080. $userDeviceInfo->brand = $brand;
  1081. $userDeviceInfo->api_version = $apiVersion;
  1082. $userDeviceInfo->save();
  1083. //首页接口调用,这里不反回信息
  1084. // $this->success("更新成功!");
  1085. }*/
  1086. //修改用户活跃1
  1087. /*public function useractive(){
  1088. $this->success('success');
  1089. }*/
  1090. //公众号获取openid
  1091. /*public function getUserOpenid_gzh(){
  1092. $configValue = Service::getConfig('wechat');
  1093. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1094. $rs = $wechat->getOpenid();
  1095. $this->success('success',$rs);
  1096. }*/
  1097. /**
  1098. * 微信内H5-JSAPI支付
  1099. */
  1100. /*public function jssdkBuildConfig() {
  1101. $url = $this->request->request("url");
  1102. $configValue = Service::getConfig('wechat');
  1103. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1104. $sign = $wechat->getSignPackage(urldecode($url));
  1105. $this->success("获取成功!",$sign);
  1106. }*/
  1107. //苹果账号登录
  1108. /*public function ioslogin(){
  1109. $ios_openid = input('ios_openid','');
  1110. if (!$ios_openid) {
  1111. $this->error(__('Invalid parameters'));
  1112. }
  1113. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1114. // if (!$user) {
  1115. // $this->success('选择性别', ['code' => 5]);
  1116. // }
  1117. if ($user) {
  1118. if (!in_array($user->status,[1,2])) {
  1119. $this->error(__('Account is locked'));
  1120. }
  1121. if ($user->frozentime > time()) {
  1122. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  1123. }
  1124. //如果已经有账号则直接登录
  1125. $ret = $this->auth->direct($user->id);
  1126. } else {
  1127. $reg_data = [
  1128. 'register_from' => input('register_from',''),
  1129. 'gender' => -1
  1130. ];
  1131. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1132. }
  1133. if ($ret) {
  1134. $data = $this->userInfo('return');
  1135. $this->success(__('Logged in successful'), $data);
  1136. } else {
  1137. $this->error($this->auth->getError());
  1138. }
  1139. }*/
  1140. //苹果账号注册
  1141. /*public function iosregiter(){
  1142. $ios_openid = input('ios_openid', '', 'trim');
  1143. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1144. if (!$ios_openid) {
  1145. $this->error(__('Invalid parameters'));
  1146. }
  1147. if (!in_array($gender, [1, 0])) {
  1148. $this->error('性别错误');
  1149. }
  1150. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1151. if ($user) {
  1152. $this->error('账号已经存在,请直接登录');
  1153. }
  1154. $reg_data = [
  1155. 'register_from' => input('register_from',''),
  1156. 'gender' => $gender
  1157. ];
  1158. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1159. if ($ret) {
  1160. $data = $this->userInfo('return');
  1161. $this->success(__('Logged in successful'), $data);
  1162. } else {
  1163. $this->error($this->auth->getError());
  1164. }
  1165. }*/
  1166. //实名认证
  1167. public function idcard_auth() {
  1168. $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
  1169. // if ($info && $info['status'] == 0) {
  1170. // $this->error('您已经提交信息了,请进行人脸认证!');
  1171. // }
  1172. if ($info && $info['status'] == 1) {
  1173. $this->error('您已通过审核!');
  1174. }
  1175. $nickname = input('nickname', '', 'trim'); // 姓名
  1176. $idcard = input('idcard', '', 'trim'); // 身份证号
  1177. if ($nickname === '') {
  1178. $this->error('请输入姓名');
  1179. }
  1180. if (iconv_strlen($nickname, 'utf-8') > 50) {
  1181. $this->error('请输入正确姓名');
  1182. }
  1183. if ($idcard === '') {
  1184. $this->error('请输入身份证号');
  1185. }
  1186. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1187. $this->error('请输入正确身份证号');
  1188. }
  1189. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  1190. if ($count) {
  1191. $this->error('身份证号已存在');
  1192. }
  1193. $data = [];
  1194. $data['truename'] = $nickname;
  1195. $data['idcard'] = $idcard;
  1196. //腾讯云身份证二要素认证
  1197. $auth_restult = $this->userauth_tencent($idcard, $nickname);
  1198. if ($auth_restult) {
  1199. $data['status'] = 1; //通过
  1200. $msg = '认证通过';
  1201. } else {
  1202. $data['status'] = 2; //不通过
  1203. $msg = '认证不通过';
  1204. }
  1205. //开启事务
  1206. Db::startTrans();
  1207. if (!$info) { //未认证
  1208. $data["user_id"] = $this->auth->id;
  1209. $data["createtime"] = time();
  1210. $res = Db::name('user_idconfirm')->insertGetId($data);
  1211. } else { //认证被拒绝过
  1212. $data['updatetime'] = time();
  1213. $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
  1214. }
  1215. if (!$res) {
  1216. Db::rollback();
  1217. $this->error('认证失败');
  1218. }
  1219. $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
  1220. if ($rt === false) {
  1221. Db::rollback();
  1222. $this->error('认证失败');
  1223. }
  1224. if ($data['status'] == 1) {
  1225. //完成实名认证 +20金币
  1226. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
  1227. if($task_rs === false){
  1228. Db::rollback();
  1229. $this->error('完成任务赠送奖励失败');
  1230. }
  1231. //系统消息
  1232. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  1233. } else {
  1234. //系统消息
  1235. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
  1236. }
  1237. Db::commit();
  1238. $this->success($msg);
  1239. }
  1240. //腾讯云身份证二要素认证
  1241. public function userauth_tencent($idcard = '', $nickname = '') {
  1242. // require_once 'vendor/autoload.php';
  1243. try {
  1244. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1245. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1246. $config = config('tencent_im');
  1247. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1248. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1249. $httpProfile = new HttpProfile();
  1250. $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
  1251. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1252. $clientProfile = new ClientProfile();
  1253. $clientProfile->setHttpProfile($httpProfile);
  1254. // 实例化要请求产品的client对象,clientProfile是可选的
  1255. $client = new FaceidClient($cred, "", $clientProfile);
  1256. // 实例化一个请求对象,每个接口都会对应一个request对象
  1257. $req = new IdCardVerificationRequest();
  1258. $params = array(
  1259. "IdCard" => $idcard,
  1260. "Name" => $nickname
  1261. );
  1262. $req->fromJsonString(json_encode($params));
  1263. // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
  1264. $resp = $client->IdCardVerification($req);
  1265. // 输出json格式的字符串回包
  1266. // print_r($resp->toJsonString());
  1267. $result = json_decode($resp->toJsonString(), true);
  1268. if (isset($result['Result']) && $result['Result'] == 0) {
  1269. return 1; //通过
  1270. } else {
  1271. return 0;
  1272. }
  1273. }
  1274. catch(TencentCloudSDKException $e) {
  1275. // echo $e;
  1276. return 0;
  1277. }
  1278. }
  1279. //绑定支付宝
  1280. public function addalipayaccount() {
  1281. $id = input('id', 0, 'intval'); //账号id
  1282. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1283. // $type = 1;
  1284. $realname = input('realname', '', 'trim'); //账户真实姓名
  1285. $banknumber = input('banknumber', '', 'trim'); //卡号或账号
  1286. $bankname = input('bankname', '', 'trim'); //银行名称
  1287. // if ($id) {
  1288. // $this->error('您已经拥有该类型账号,请联系后台解绑');
  1289. // }
  1290. if (!in_array($type, [1, 2])) {
  1291. $this->error('参数错误');
  1292. }
  1293. /*if ($type == 1) {
  1294. $this->error('暂不支持绑定支付宝');
  1295. }*/
  1296. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1297. $this->error('账号姓名1-30位');
  1298. }
  1299. if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
  1300. $this->error('账号1-50位');
  1301. }
  1302. if ($type == 1) {
  1303. if (iconv_strlen($bankname, 'utf-8') != 18) {
  1304. $this->error('请输入正确身份证号');
  1305. }
  1306. }
  1307. if ($type == 2) {
  1308. if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
  1309. $this->error('开户行名称1-50位');
  1310. }
  1311. }
  1312. $user_bank = Db::name('user_bank');
  1313. if ($id) {
  1314. //编辑
  1315. //查询账号是否存在
  1316. $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1317. if (!$info) {
  1318. $this->error('账号不存在');
  1319. }
  1320. if ($info['type'] != $type) {
  1321. $this->error('账号类型错误');
  1322. }
  1323. //查询是否未通过提现记录
  1324. $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
  1325. if ($count) {
  1326. $this->error('该账户有未审核的提现记录,暂不可修改');
  1327. }
  1328. $data['realname'] = $realname;
  1329. $data['banknumber'] = $banknumber;
  1330. $data['updatetime'] = time();
  1331. // if ($type == 2) {
  1332. $data['bankname'] = $bankname;
  1333. // }
  1334. $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
  1335. if ($rs === false) {
  1336. $this->error('修改失败');
  1337. }
  1338. $this->success('修改成功');
  1339. } else {
  1340. //添加
  1341. //查询是否已经拥有该类型账号
  1342. $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1343. if ($count) {
  1344. $this->error('您已经拥有该类型账号,请联系后台解绑');
  1345. }
  1346. $data['user_id'] = $this->auth->id;
  1347. $data['type'] = $type;
  1348. $data['realname'] = $realname;
  1349. $data['banknumber'] = $banknumber;
  1350. // if ($type == 2) {
  1351. $data['bankname'] = $bankname;
  1352. // }
  1353. $data['createtime'] = time();
  1354. $rs = $user_bank->insertGetId($data);
  1355. if (!$rs) {
  1356. $this->error('添加失败');
  1357. }
  1358. $this->success('添加成功');
  1359. }
  1360. }
  1361. //查询支付宝/银行卡信息
  1362. public function alipayinfo() {
  1363. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1364. $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  1365. if (!$info) {
  1366. $info = (object)[];
  1367. }
  1368. $this->success('success', $info);
  1369. }
  1370. //申请真人认证
  1371. public function realauth() {
  1372. if ($this->auth->real_status == 1) {
  1373. $this->error('您已经真人认证过了~');
  1374. }
  1375. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  1376. $this->error('请先上传真人头像~');
  1377. }
  1378. //获取token
  1379. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  1380. $token_result = file_get_contents($token_url);
  1381. if (!$token_result) {
  1382. $this->error('您的网络开小差啦1~');
  1383. }
  1384. $token_result = json_decode($token_result, true);
  1385. if ($token_result['code'] != 0) {
  1386. $this->error('您的网络开小差啦2~');
  1387. }
  1388. $token = $token_result['access_token'];
  1389. //获取签名鉴权参数ticket
  1390. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1391. $ticket_result = file_get_contents($ticket_url);
  1392. if (!$ticket_result) {
  1393. $this->error('您的网络开小差啦3~');
  1394. }
  1395. $ticket_result = json_decode($ticket_result, true);
  1396. if ($ticket_result['code'] != 0) {
  1397. $this->error('您的网络开小差啦4~');
  1398. }
  1399. $ticket = $ticket_result['tickets'][0]['value'];
  1400. //获取签名
  1401. $sign_data = [
  1402. 'wbappid' => config('tencent_yun')['secret_id'],
  1403. 'userId' => (string)$this->auth->id,
  1404. 'version' => '1.0.0',
  1405. 'ticket' => $ticket,
  1406. 'nonce' => Random::alnum(32)
  1407. ];//p($sign_data);
  1408. asort($sign_data); //p($sign_data);//排序
  1409. $sign_string = join('', $sign_data);//p($sign_string);
  1410. $sign = sha1($sign_string);//p($sign);
  1411. //上传身份信息
  1412. $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
  1413. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  1414. $avatar = one_domain_image($this->auth->avatar);
  1415. $avatar = str_replace('https', 'http', $avatar);
  1416. $img = file_get_contents($avatar);
  1417. $img = str_replace('data:image/jpg;base64', '', $img);
  1418. $img = str_replace('\n', '', $img);
  1419. $sourcePhotoStr = base64_encode($img);
  1420. $data = [
  1421. 'webankAppId' => config('tencent_yun')['secret_id'],
  1422. 'orderNo' => $orderNo,
  1423. 'userId' => (string)$this->auth->id,
  1424. 'sourcePhotoStr' => $sourcePhotoStr,
  1425. 'sourcePhotoType' => 2,
  1426. 'version' => '1.0.0',
  1427. 'sign' => $sign,
  1428. 'nonce' => $sign_data['nonce']
  1429. ];
  1430. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1431. if (!$rs) {
  1432. $this->error('您的网络开小差啦5~');
  1433. }
  1434. $rs = json_decode($rs, true);
  1435. if (!$rs || $rs['code'] != 0) {
  1436. $this->error('您的网络开小差啦6~');
  1437. }
  1438. $user_auth = [
  1439. 'user_id' => $this->auth->id,
  1440. 'certify_id' => $rs['result']['faceId'],
  1441. 'out_trade_no' => $data['orderNo'],
  1442. 'status' => 0,
  1443. 'createtime' => time(),
  1444. 'updatetime' => time()
  1445. ];
  1446. //开启事务
  1447. Db::startTrans();
  1448. //查询是否认证过
  1449. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1450. if ($info) {
  1451. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  1452. } else {
  1453. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  1454. }
  1455. if (!$auth_rs) {
  1456. Db::rollback();
  1457. $this->error('您的网络开小差啦7~');
  1458. }
  1459. //修改用户表认证状态
  1460. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  1461. if ($user_rs === false) {
  1462. Db::rollback();
  1463. $this->error('您的网络开小差啦8~');
  1464. }
  1465. Db::commit();
  1466. $return_data = [
  1467. 'face_id' => $user_auth['certify_id'],
  1468. 'order_no' => $user_auth['out_trade_no'],
  1469. 'user_id' => (string)$this->auth->id,
  1470. 'nonce' => $sign_data['nonce'],
  1471. 'sign' => $sign
  1472. ];
  1473. $this->success('success', $return_data);
  1474. }
  1475. //查询真人认证结果
  1476. public function getrealauthresult() {
  1477. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1478. if (!$user_auth) {
  1479. $this->success('尚未认证');
  1480. }
  1481. if ($user_auth['status'] == 1) {
  1482. $this->success('真人认证通过');
  1483. }
  1484. if (!$user_auth['certify_id']) {
  1485. $this->success('请先进行真人认证');
  1486. }
  1487. //获取token
  1488. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  1489. $token_result = file_get_contents($token_url);
  1490. if (!$token_result) {
  1491. $this->error('您的网络开小差啦1~');
  1492. }
  1493. $token_result = json_decode($token_result, true);
  1494. if ($token_result['code'] != 0) {
  1495. $this->error('您的网络开小差啦2~');
  1496. }
  1497. $token = $token_result['access_token'];
  1498. //获取签名鉴权参数ticket
  1499. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  1500. $ticket_result = file_get_contents($ticket_url);
  1501. if (!$ticket_result) {
  1502. $this->error('您的网络开小差啦3~');
  1503. }
  1504. $ticket_result = json_decode($ticket_result, true);
  1505. if ($ticket_result['code'] != 0) {
  1506. $this->error('您的网络开小差啦4~');
  1507. }
  1508. $ticket = $ticket_result['tickets'][0]['value'];
  1509. //获取签名
  1510. $sign_data = [
  1511. 'wbappid' => config('tencent_yun')['secret_id'],
  1512. 'orderNo' => $user_auth['out_trade_no'],
  1513. 'version' => '1.0.0',
  1514. 'ticket' => $ticket,
  1515. 'nonce' => Random::alnum(32)
  1516. ];//p($sign_data);
  1517. asort($sign_data); //p($sign_data);//排序
  1518. $sign_string = join('', $sign_data);//p($sign_string);
  1519. $sign = sha1($sign_string);//p($sign);
  1520. //人脸核身结果查询
  1521. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1522. $data = [
  1523. 'appId' => config('tencent_yun')['secret_id'],
  1524. 'version' => '1.0.0',
  1525. 'nonce' => $sign_data['nonce'],
  1526. 'orderNo' => $user_auth['out_trade_no'],
  1527. 'sign' => $sign
  1528. ];
  1529. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1530. if (!$rs) {
  1531. $this->error('您的网络开小差啦5~');
  1532. }
  1533. $rs = json_decode($rs, true);
  1534. if (!$rs || $rs['code'] != 0) {
  1535. $this->error($rs['msg']);
  1536. }
  1537. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1538. $edit_data['status'] = 1;
  1539. $msg = '真人认证成功';
  1540. } else {
  1541. $edit_data['status'] = 2;
  1542. $edit_data['certify_id'] = '';
  1543. $edit_data['out_trade_no'] = '';
  1544. $msg = '真人认证失败';
  1545. }
  1546. $edit_data['updatetime'] = time();
  1547. //开启事务
  1548. Db::startTrans();
  1549. //修改认证信息
  1550. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1551. if (!$result) {
  1552. Db::rollback();
  1553. $this->error('查询认证结果失败2');
  1554. }
  1555. //修改用户信息
  1556. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  1557. if (!$rs) {
  1558. Db::rollback();
  1559. $this->error('查询认证结果失败3');
  1560. }
  1561. if ($edit_data['status'] == 1) { //通过
  1562. //tag任务赠送金币
  1563. //真人认证奖励
  1564. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1565. if($task_rs === false){
  1566. Db::rollback();
  1567. $this->error('完成任务赠送奖励失败');
  1568. }
  1569. //系统消息
  1570. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1571. } else {
  1572. //系统消息
  1573. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1574. }
  1575. Db::commit();
  1576. $this->success($msg);
  1577. }
  1578. //客服
  1579. public function kefu() {
  1580. $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
  1581. if (!in_array($type, [0, 1])) {
  1582. $this->error('您的网络开小差啦~');
  1583. }
  1584. if ($type == 0) {
  1585. $user_id = config('site.customer_service_id') ? : 0; //指定客服id
  1586. } else {
  1587. $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
  1588. }
  1589. $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
  1590. if (!$list) {
  1591. $this->success('success', $list);
  1592. }
  1593. foreach ($list as $k => &$v) {
  1594. $v['nickname'] = '客服' . ($k + 1);
  1595. $v['avatar'] = config('avatar_girl');
  1596. }
  1597. $this->success('success', $list);
  1598. }
  1599. //海报背景图
  1600. public function posterlist() {
  1601. $list = config('site.intro_images');
  1602. if (!$list) {
  1603. $this->success('success', (object)[]);
  1604. }
  1605. foreach ($list as &$v) {
  1606. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  1607. }
  1608. $this->success('success', $list);
  1609. }
  1610. //生成海报
  1611. public function createposter($image = '') {
  1612. // $image = input('image', '', 'trim');
  1613. // if (!$image) {
  1614. // $this->error('您的网络开小差啦~');
  1615. // }
  1616. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  1617. return $haibao;
  1618. // $this->success('success', $haibao);
  1619. }
  1620. //真人认证后修改头像前比对
  1621. public function realavatar_auit() {
  1622. if ($this->auth->real_status != 1) {
  1623. $this->error('尚未通过真人认证');
  1624. }
  1625. $avatar = input('avatar', '', 'trim'); //头像地址
  1626. if ($avatar === '') {
  1627. $this->error('参数缺失');
  1628. }
  1629. $avatar = one_domain_image($avatar);
  1630. $now_avatar = one_domain_image($this->auth->avatar);
  1631. if ($avatar == $now_avatar) {
  1632. $this->error('头像未改变');
  1633. }
  1634. //腾讯云人脸识别
  1635. $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1636. $this->success('结果', $result);
  1637. }
  1638. //真人认证后修改头像
  1639. public function editrealavatar() {
  1640. if ($this->auth->real_status != 1) {
  1641. $this->error('尚未通过真人认证');
  1642. }
  1643. $avatar = input('avatar', '', 'trim'); //头像地址
  1644. if ($avatar === '') {
  1645. $this->error('参数缺失');
  1646. }
  1647. $avatar = one_domain_image($avatar);
  1648. $now_avatar = one_domain_image($this->auth->avatar);
  1649. if ($avatar == $now_avatar) {
  1650. $this->error('头像未改变');
  1651. }
  1652. //腾讯云人脸识别
  1653. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1654. if ($auit_result != 1) {
  1655. $this->success('提示', ['code' => 2]);
  1656. }
  1657. $data['avatar'] = $avatar;
  1658. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1659. if (!$user_result) {
  1660. $this->error('修改失败');
  1661. }
  1662. $this->success('修改成功');
  1663. }
  1664. //真人认证后修改头像并取消真人认证
  1665. public function editrealavatarcancelauit() {
  1666. if ($this->auth->real_status != 1) {
  1667. $this->error('尚未通过真人认证');
  1668. }
  1669. $avatar = input('avatar', '', 'trim'); //头像地址
  1670. if ($avatar === '') {
  1671. $this->error('参数缺失');
  1672. }
  1673. $avatar = one_domain_image($avatar);
  1674. $now_avatar = one_domain_image($this->auth->avatar);
  1675. if ($avatar == $now_avatar) {
  1676. $this->error('头像未改变');
  1677. }
  1678. $data['avatar'] = $avatar;
  1679. $data['real_status'] = -1;
  1680. //开启事务
  1681. Db::startTrans();
  1682. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1683. if (!$user_result) {
  1684. Db::rollback();
  1685. $this->error('修改失败');
  1686. }
  1687. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  1688. if (!$user_auth_result) {
  1689. Db::rollback();
  1690. $this->error('修改失败');
  1691. }
  1692. Db::commit();
  1693. $this->success('修改成功');
  1694. }
  1695. //腾讯云人脸识别
  1696. public function face_tencent($urla = '', $urlb = '') {
  1697. // require_once 'vendor/autoload.php';
  1698. try {
  1699. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1700. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1701. $config = config('tencent_im');
  1702. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1703. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1704. $httpProfile = new HttpProfile();
  1705. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  1706. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1707. $clientProfile = new ClientProfile();
  1708. $clientProfile->setHttpProfile($httpProfile);
  1709. // 实例化要请求产品的client对象,clientProfile是可选的
  1710. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  1711. // 实例化一个请求对象,每个接口都会对应一个request对象
  1712. $req = new CompareFaceRequest();
  1713. $params = array(
  1714. "UrlA" => $urla,
  1715. "UrlB" => $urlb,
  1716. "FaceModelVersion" => "3.0"
  1717. );
  1718. $req->fromJsonString(json_encode($params));
  1719. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  1720. $resp = $client->CompareFace($req);
  1721. // 输出json格式的字符串回包
  1722. // print_r($resp->toJsonString());
  1723. $result = json_decode($resp->toJsonString(), true);
  1724. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  1725. if (isset($result['Score']) && $result['Score'] >= 60) {
  1726. return 1; //通过
  1727. } else {
  1728. return 0;
  1729. }
  1730. }
  1731. catch(TencentCloudSDKException $e) {
  1732. // echo $e;
  1733. return 0;
  1734. }
  1735. }
  1736. //修改城市
  1737. public function editcity() {
  1738. $name = input('name', '', 'trim'); //城市名
  1739. if ($name === '') {
  1740. $this->error('参数缺失');
  1741. }
  1742. $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
  1743. if (!$hometown_cityid) {
  1744. $this->success('修改成功');
  1745. }
  1746. Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
  1747. $this->success('修改成功');
  1748. }
  1749. //搜索用户
  1750. public function searchuser() {
  1751. $keyword = input('keyword', '', 'trim'); //昵称或ID
  1752. if ($keyword === '') {
  1753. $this->error('请输入关键字');
  1754. }
  1755. $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
  1756. $id = $id ? : 0;
  1757. $this->success('用户', $id);
  1758. }
  1759. //绑定支付宝账号信息
  1760. public function bindalipayaccount() {
  1761. $mt_user_bank = Db::name('user_bank');
  1762. $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
  1763. if ($count) {
  1764. $this->error('您已绑定支付宝啦');
  1765. }
  1766. $auth_code = input('auth_code', '', 'trim');
  1767. if (!$auth_code) {
  1768. $this->error('授权码缺失');
  1769. }
  1770. //获取支付宝用户信息
  1771. $rs = getAlipayInfo($auth_code);
  1772. if ($rs['status'] == 0) {
  1773. $this->error($rs['info']);
  1774. }
  1775. $rs = $rs['data'];
  1776. /*
  1777. * Array(
  1778. [alipay_user_info_share_response] => Array
  1779. (
  1780. [code] => 10000
  1781. [msg] => Success
  1782. [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
  1783. [city] => 临沂市 市名称。
  1784. [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
  1785. [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
  1786. [is_student_certified] => F 是否是学生 T是 F否
  1787. [nick_name] => 风的追求 用户昵称
  1788. [province] => 山东省 省份名称
  1789. [user_id] => 2088902918001020 支付宝用户的userId
  1790. [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
  1791. [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
  1792. )
  1793. )
  1794. */
  1795. $data['banknumber'] = $rs['user_id']; //支付宝用户id
  1796. if (!$data['banknumber']) {
  1797. $this->error('获取用户信息失败');
  1798. }
  1799. $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
  1800. if ($bank_number_count) {
  1801. $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
  1802. }
  1803. if (isset($rs['nick_name'])) {
  1804. $data['realname'] = $rs['nick_name']; //支付宝用户昵称
  1805. }
  1806. $data['user_id'] = $this->auth->id;
  1807. $data['createtime'] = time();
  1808. $data['type'] = 1;
  1809. $rt = $mt_user_bank->insertGetId($data);
  1810. if (!$rt) {
  1811. $this->error('绑定失败');
  1812. }
  1813. $this->success('绑定成功');
  1814. }
  1815. //添加打招呼内容,女性使用
  1816. public function addgreetcontent() {
  1817. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  1818. $title = input('title', '', 'trim'); //标题(type=1必传)
  1819. $content = input('content', '', 'trim'); //内容
  1820. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  1821. if (!in_array($type, [0, 1, 2])) {
  1822. $this->error('您的网络开小差了');
  1823. }
  1824. if ($content === '') {
  1825. $this->error('请设置打招呼内容');
  1826. }
  1827. if (iconv_strlen($content, 'utf-8') > 255) {
  1828. $this->error('打招呼内容最多255位');
  1829. }
  1830. if ($type == 1) {
  1831. if ($title === '') {
  1832. $this->error('请输入语音名称');
  1833. }
  1834. if (iconv_strlen($title, 'utf-8') > 50) {
  1835. $this->error('语音名称最多50字');
  1836. }
  1837. if (!$duration) {
  1838. $this->error('参数缺失');
  1839. }
  1840. }
  1841. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1842. if ($count > 10) {
  1843. $this->error('同一类型打招呼最多设置10条');
  1844. }
  1845. $data['user_id'] = $this->auth->id;
  1846. $data['type'] = $type;
  1847. $data['content'] = $content;
  1848. if ($type == 1) {
  1849. $data['title'] = $title;
  1850. $data['duration'] = $duration;
  1851. }
  1852. $data['createtime'] = time();
  1853. //查询是否有默认打招呼内容
  1854. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  1855. if (!$default_greet_count) {
  1856. $data['is_default'] = 1;
  1857. }
  1858. $rs = Db::name('user_greet_content')->insertGetId($data);
  1859. if (!$rs) {
  1860. $this->error('您的网络开小差了');
  1861. }
  1862. $this->success('设置成功');
  1863. }
  1864. //查询打招呼内容,女性使用
  1865. public function getgreetcontent() {
  1866. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  1867. if (!in_array($type, [0, 1, 2, 3])) {
  1868. $this->error('您的网络开小差了');
  1869. }
  1870. if ($type == 3) {
  1871. $list = Db::name('user_greet_content')->where(function ($query) {
  1872. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  1873. })->whereOr(function ($query) {
  1874. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  1875. })->select();
  1876. } else {
  1877. $where['user_id'] = $this->auth->id;
  1878. $where['type'] = $type;
  1879. $list = Db::name('user_greet_content')->where($where)->select();
  1880. }
  1881. if ($list) {
  1882. foreach ($list as &$v) {
  1883. if ($v['type'] != 0) {
  1884. $v['content'] = one_domain_image($v['content']);
  1885. }
  1886. }
  1887. }
  1888. $this->success('打招呼内容', $list);
  1889. }
  1890. //设置默认打招呼内容,女性使用
  1891. public function setdefaultgreet() {
  1892. $id = input('id', 0, 'intval'); //打招呼id
  1893. if (!$id) {
  1894. $this->error('您的网络开小差了');
  1895. }
  1896. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  1897. if (!$count) {
  1898. $this->error('您的网络开小差了');
  1899. }
  1900. //开启事务
  1901. Db::startTrans();
  1902. //清除之前默认
  1903. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  1904. if ($rs === false) {
  1905. Db::rollback();
  1906. $this->error('您的网络开小差了');
  1907. }
  1908. //设置
  1909. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  1910. if ($rt === false) {
  1911. Db::rollback();
  1912. $this->error('您的网络开小差了');
  1913. }
  1914. Db::commit();
  1915. $this->success('设置成功');
  1916. }
  1917. //删除打招呼内容,女性使用
  1918. public function deldefaultgreet() {
  1919. $id = input('id', 0, 'intval'); //打招呼id
  1920. if (!$id) {
  1921. $this->error('您的网络开小差了');
  1922. }
  1923. $mt_user_greet_content = Db::name('user_greet_content');
  1924. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  1925. if (!$info) {
  1926. $this->error('您的网络开小差了');
  1927. }
  1928. //开启事务
  1929. Db::startTrans();
  1930. //删除
  1931. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  1932. if ($rs === false) {
  1933. Db::rollback();
  1934. $this->error('您的网络开小差了');
  1935. }
  1936. //若为默认打招呼内容则重新设置一条
  1937. if ($info['is_default'] == 1) {
  1938. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  1939. if ($first_greet) {
  1940. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  1941. if ($rt === false) {
  1942. Db::rollback();
  1943. $this->error('您的网络开小差了');
  1944. }
  1945. }
  1946. }
  1947. Db::commit();
  1948. $this->success('删除成功');
  1949. }
  1950. }