User.php 76 KB

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