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