User.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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 addons\epay\library\Wechat;
  15. use app\common\library\Wechat;
  16. /**
  17. * 会员接口,登录,注册,修改资料等
  18. */
  19. class User extends Api
  20. {
  21. protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin','applelogin', 'register', 'resetpwd', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig'];
  22. protected $noNeedRight = '*';
  23. public function _initialize()
  24. {
  25. parent::_initialize();
  26. }
  27. /**
  28. * 会员中心
  29. */
  30. public function index()
  31. {
  32. $this->success('', ['welcome' => $this->auth->nickname]);
  33. }
  34. /**
  35. * 会员登录
  36. *
  37. * @ApiMethod (POST)
  38. * @param string $account 账号
  39. * @param string $password 密码
  40. */
  41. public function login()
  42. {
  43. $account = input('account');
  44. $password = input('password');
  45. if (!$account || !$password) {
  46. $this->error(__('Invalid parameters'));
  47. }
  48. $ret = $this->auth->login($account, $password);
  49. if ($ret) {
  50. $data = $this->userInfo('return');
  51. $this->success(__('Logged in successful'), $data);
  52. } else {
  53. $this->error($this->auth->getError());
  54. }
  55. }
  56. /**
  57. * 手机验证码登录
  58. *
  59. * @ApiMethod (POST)
  60. * @param string $mobile 手机号
  61. * @param string $captcha 验证码
  62. */
  63. public function mobilelogin()
  64. {
  65. $mobile = input('mobile');
  66. $captcha = input('captcha');
  67. if (!$mobile || !$captcha) {
  68. $this->error(__('Invalid parameters'));
  69. }
  70. /*if (!Validate::regex($mobile, "^1\d{10}$")) {
  71. $this->error(__('Mobile is incorrect'));
  72. }*/
  73. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  74. $this->error(__('Captcha is incorrect'));
  75. }
  76. $user = \app\common\model\User::getByMobile($mobile);
  77. if ($user) {
  78. if ($user->status == -1) {
  79. $this->error('账户已注销');
  80. }
  81. if ($user->status != 1) {
  82. $this->error(__('Account is locked'));
  83. }
  84. //如果已经有账号则直接登录
  85. $ret = $this->auth->direct($user->id);
  86. } else {
  87. $extend = [
  88. // 'register_from' => input('register_from',''),
  89. ];
  90. $ret = $this->auth->register('', '', '', $mobile, $extend);
  91. }
  92. if ($ret) {
  93. Sms::flush($mobile, 'mobilelogin');
  94. $data = $this->userInfo('return');
  95. $this->success(__('Logged in successful'), $data);
  96. } else {
  97. $this->error($this->auth->getError());
  98. }
  99. }
  100. /**
  101. * 注册会员
  102. *
  103. * @ApiMethod (POST)
  104. * @param string $username 用户名
  105. * @param string $password 密码
  106. * @param string $email 邮箱
  107. * @param string $mobile 手机号
  108. * @param string $code 验证码
  109. */
  110. /*public function register()
  111. {
  112. $username = $this->request->post('username');
  113. $password = $this->request->post('password');
  114. $email = $this->request->post('email');
  115. $mobile = $this->request->post('mobile');
  116. $code = $this->request->post('code');
  117. if (!$username || !$password) {
  118. $this->error(__('Invalid parameters'));
  119. }
  120. if ($email && !Validate::is($email, "email")) {
  121. $this->error(__('Email is incorrect'));
  122. }
  123. //if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  124. // $this->error(__('Mobile is incorrect'));
  125. //}
  126. $ret = Sms::check($mobile, $code, 'register');
  127. if (!$ret) {
  128. $this->error(__('Captcha is incorrect'));
  129. }
  130. $ret = $this->auth->register($username, $password, $email, $mobile, []);
  131. if ($ret) {
  132. $data = $this->userInfo('return');
  133. $this->success(__('Sign up successful'), $data);
  134. } else {
  135. $this->error($this->auth->getError());
  136. }
  137. }*/
  138. //微信登录,预先假注册
  139. public function wechatlogin(){
  140. $code = $this->request->param('code','');
  141. if(!$code){
  142. $this->error(__('Invalid parameters'));
  143. }
  144. //微信
  145. $wechat = new Wechat();
  146. $wxuserinfo = $wechat->getwxuserinfo($code);
  147. if(!$wxuserinfo){
  148. $this->error('openid获取失败');
  149. }
  150. $openid = $wxuserinfo['openid'];
  151. $user = Db::name('user')->where('openid',$openid)->find();
  152. if ($user) {
  153. if ($user['status'] == -1) {
  154. $this->error('账户已注销');
  155. }
  156. if ($user['status'] != 1) {
  157. $this->error(__('Account is locked'));
  158. }
  159. //如果已经有账号则直接登录
  160. $ret = $this->auth->direct($user['id']);
  161. $is_register = 0;
  162. $userInfo = $this->auth->getUserinfo();
  163. } else {
  164. //记录code和openid,绑定手机号的时候更新openid
  165. $wechatCodeData = [
  166. 'code' => $code,
  167. 'openid' => $openid,
  168. 'createtime' => time(),
  169. ];
  170. $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
  171. if (empty($wechatCode)) {
  172. Db::name('wechat_code')->insertGetId($wechatCodeData);
  173. } else {
  174. Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
  175. }
  176. $ret = true;
  177. $is_register = 1;
  178. $userInfo = [];
  179. $data = ['code'=>$code,'is_register' => $is_register, 'userinfo' => $userInfo];
  180. $this->success('获取信息成功', $data, 2);
  181. }
  182. if ($ret) {
  183. $data = ['code'=>$code,'is_register' => $is_register, 'userinfo' => $userInfo];
  184. $this->success(__('Logged in successful'), $data);
  185. } else {
  186. $this->error($this->auth->getError());
  187. }
  188. }
  189. /**
  190. * 运营商一键登录
  191. */
  192. public function onLogin()
  193. {
  194. $accessToken = input('accessToken');// 运营商预取号获取到的token
  195. $token = input('tokenT');// 易盾返回的token
  196. if (!$accessToken || !$token) {
  197. $this->error("参数获取失败!");
  198. }
  199. $params = array(
  200. // 运营商预取号获取到的token
  201. "accessToken" => $accessToken,
  202. // 易盾返回的token
  203. "token" => $token
  204. );
  205. // 获取密钥配置
  206. $configInfo = config("onLogin");
  207. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  208. $onret = $onlogin->check($params);
  209. // $ret = [];
  210. // $ret["code"] = 200;
  211. // $ret["msg"] = "ok";
  212. // $ret["data"] = [
  213. // "phone" => "17574504021",
  214. // "resultCode" => 0
  215. // ];
  216. if ($onret["code"] == 200) {
  217. $mobile = $onret["data"]["phone"];
  218. if (empty($mobile)) {
  219. // 取号失败,建议进行二次验证,例如短信验证码
  220. $this->error("取号登录失败,请用验证码方式登录!");
  221. } else {
  222. // 取号成功, 执行登录等流程
  223. // 用户登录逻辑 === 开始
  224. $user = \app\common\model\User::getByMobile($mobile);
  225. if ($user) {
  226. if ($user->status == -1) {
  227. $this->error('账户已注销');
  228. }
  229. if ($user->status != 1) {
  230. $this->error(__('Account is locked'));
  231. }
  232. //如果已经有账号则直接登录
  233. $ret = $this->auth->direct($user->id);
  234. $is_register = 0;
  235. } else {
  236. $ret = $this->auth->register('', '', '', $mobile, []);
  237. $is_register = 1;
  238. }
  239. if ($ret) {
  240. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  241. } else {
  242. $this->error($this->auth->getError());
  243. }
  244. // 用户登录逻辑 === 结束
  245. }
  246. } else {
  247. $this->error("登录失败,请用验证码方式登录!");
  248. }
  249. }
  250. //苹果登录+注册
  251. public function applelogin(){
  252. $iosUserId = input_post('ios_user_id','');
  253. if(!$iosUserId){
  254. $this->error(__('Invalid parameters'));
  255. }
  256. $user = Db::name('user')->where('ios_user_id',$iosUserId)->find();
  257. if ($user) {
  258. if ($user['status'] == -1) {
  259. $this->error('账户已经注销');
  260. }
  261. if ($user['status'] != 1) {
  262. $this->error(__('Account is locked'));
  263. }
  264. //如果已经有账号则直接登录
  265. $ret = $this->auth->direct($user['id']);
  266. } else {
  267. $ret = $this->auth->ios_register($iosUserId);
  268. }
  269. if ($ret) {
  270. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  271. } else {
  272. $this->error($this->auth->getError());
  273. }
  274. }
  275. //用户详细资料
  276. public function userInfo($type = 1){
  277. $info = $this->auth->getUserinfo();
  278. if($type == 'return'){
  279. return $info;
  280. }
  281. $this->success(__('success'),$info);
  282. }
  283. /**
  284. * 退出登录
  285. * @ApiMethod (POST)
  286. */
  287. public function logout()
  288. {
  289. if (!$this->request->isPost()) {
  290. $this->error(__('Invalid parameters'));
  291. }
  292. //退出im
  293. // $tenIm = new Tenim();
  294. // $tenIm->loginoutim($this->auth->id);
  295. $this->auth->logout();
  296. $this->success(__('Logout successful'));
  297. }
  298. /**
  299. * 修改会员个人信息
  300. *
  301. * @ApiMethod (POST)
  302. * @param string $avatar 头像地址
  303. * @param string $username 用户名
  304. * @param string $nickname 昵称
  305. * @param string $bio 个人简介
  306. */
  307. public function profile()
  308. {
  309. $field_array = ['nickname','introcode','gender','birthday','attribute','shoesize','height','weight','bio','avatar','photo_images','tag_ids','hide_is_finishinfo'];
  310. $data = [];
  311. foreach($field_array as $key => $field){
  312. //前端传不了post,改了
  313. /*if(!request()->has($field,'post')){
  314. continue;
  315. }*/
  316. if(!input('?'.$field)){
  317. continue;
  318. }
  319. $newone = input($field);
  320. if($field == 'avatar'){
  321. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  322. }
  323. if($field == 'photo_images'){
  324. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  325. }
  326. $data[$field] = $newone;
  327. }
  328. if(isset($data['birthday'])){
  329. $data['birthday'] = strtotime($data['birthday']);
  330. }
  331. if(isset($data['tag_ids'])){
  332. $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
  333. }
  334. if(isset($data['introcode']) && !empty($data['introcode'])){
  335. $intro_user = Db::name('user')->where('introcode',$data['introcode'])->value('id');
  336. if(!$intro_user){
  337. $this->error('不存在的邀请人');
  338. }
  339. if(!empty($this->auth->intro_uid)){
  340. $this->error('您已经填写过邀请人');
  341. }
  342. unset($data['introcode']);//别人的邀请码,不能改了自己的
  343. $data['intro_uid'] = $intro_user;
  344. //邀请用户注册,给邀请人奖励
  345. if(isset($data['intro_uid']) && !empty($data['intro_uid'])){
  346. $intro_gold = config('site.intro_newuser_gift_goldnum') ?: 0;
  347. if($intro_gold > 0){
  348. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],'gold',$intro_gold,63,'邀请'.$this->auth->username);
  349. if($wallet_rs['status'] === false){
  350. Db::rollback();
  351. $this->setError($wallet_rs['msg']);
  352. return false;
  353. }
  354. }
  355. }
  356. }
  357. //dump($data);
  358. if(empty($data)){
  359. $this->error('没有任何改变');
  360. }
  361. Db::startTrans();
  362. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  363. if($update_rs === false){
  364. Db::rollback();
  365. $this->error('修改资料失败');
  366. }
  367. //task任务
  368. //上传本人头像
  369. if(isset($data['avatar'])&& $data['avatar'] != config('site.domain_cdnurl').'/avatar.png'){
  370. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  371. if($task_rs === false){
  372. Db::rollback();
  373. $this->error('完成任务失败');
  374. }
  375. }
  376. Db::commit();
  377. $this->success();
  378. }
  379. /**
  380. * 修改会员权限
  381. */
  382. public function setpower()
  383. {
  384. $is_vip = $this->is_vip($this->auth->id);
  385. if(!$is_vip){
  386. $this->error('VIP才能设置隐私权限');
  387. }
  388. $field_array = ['yinsi','yinshen','wuhen'];
  389. $data = [];
  390. foreach($field_array as $key => $field){
  391. if(!input('?'.$field)){
  392. continue;
  393. }
  394. $newone = input($field);
  395. $data[$field] = $newone;
  396. }
  397. $update_rs = Db::name('user_power')->where('user_id',$this->auth->id)->update($data);
  398. $this->success();
  399. }
  400. /*
  401. * 修改用户的坐标
  402. * */
  403. public function change_longlat(){
  404. $longitude = input_post('longitude',0);
  405. $latitude = input_post('latitude',0);
  406. $cityname = input_post('cityname','');
  407. $plat_unique_id = input_post('plat_unique_id','');
  408. if(empty($longitude) || empty($latitude) || empty($cityname)){
  409. $this->error();
  410. }
  411. $data = [
  412. 'longitude' => $longitude,
  413. 'latitude' => $latitude,
  414. 'cityname' => $cityname,
  415. 'plat_unique_id' => $plat_unique_id,
  416. ];
  417. Db::name('user')->where('id',$this->auth->id)->update($data);
  418. $this->success();
  419. }
  420. //修改用户设备id
  421. public function change_plat_unique_id(){
  422. $plat_unique_id = input_post('plat_unique_id','');
  423. $data = [
  424. 'plat_unique_id' => $plat_unique_id,
  425. ];
  426. Db::name('user')->where('id',$this->auth->id)->update($data);
  427. $this->success();
  428. }
  429. /**
  430. * 修改手机号
  431. *
  432. * @ApiMethod (POST)
  433. * @param string $mobile 手机号
  434. * @param string $captcha 验证码
  435. */
  436. public function changemobile()
  437. {
  438. $user = $this->auth->getUser();
  439. $oldcaptcha = $this->request->request('oldcaptcha');
  440. $mobile = $this->request->request('mobile');
  441. $captcha = $this->request->request('captcha');
  442. if (!$oldcaptcha || !$mobile || !$captcha) {
  443. $this->error(__('Invalid parameters'));
  444. }
  445. /*if (!Validate::regex($mobile, "^1\d{10}$")) {
  446. $this->error(__('Mobile is incorrect'));
  447. }*/
  448. if($user->mobile == $mobile){
  449. $this->error('新手机号不能与旧手机号相同');
  450. }
  451. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  452. $this->error(__('Mobile already exist'));
  453. }
  454. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  455. if (!$result) {
  456. $this->error(__('Captcha is incorrect'));
  457. }
  458. $result = Sms::check($mobile, $captcha, 'changemobile');
  459. if (!$result) {
  460. $this->error(__('Captcha is incorrect'));
  461. }
  462. $verification = $user->verification;
  463. $verification->mobile = 1;
  464. $user->verification = $verification;
  465. $user->mobile = $mobile;
  466. $user->save();
  467. Sms::flush($user->mobile, 'changemobile');
  468. Sms::flush($mobile, 'changemobile');
  469. $this->success();
  470. }
  471. /**
  472. * 微信注册来的,绑定手机号
  473. *
  474. * @ApiMethod (POST)
  475. * @param string $mobile 手机号
  476. * @param string $captcha 验证码
  477. */
  478. public function bindmobile()
  479. {
  480. Db::startTrans();
  481. try {
  482. $code = $this->request->param('code');
  483. $mobile = $this->request->param('mobile');
  484. $captcha = $this->request->param('captcha');
  485. if (!$mobile || !$captcha || !$code) {
  486. throw new Exception(__('Invalid parameters'));
  487. }
  488. /*if (!Validate::regex($mobile, "^1\d{10}$")) {
  489. throw new Exception(__('Mobile is incorrect'));
  490. }*/
  491. $result = Sms::check($mobile, $captcha, 'changemobile');
  492. if (!$result) {
  493. throw new Exception(__('Captcha is incorrect'));
  494. }
  495. $wechatCodeWhere['code'] = $code;
  496. $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
  497. if (empty($wechatCode)) {
  498. throw new Exception('请先微信登录');
  499. }
  500. $where['mobile'] = $mobile;
  501. $userData = model('User')->where($where)->find();//老用户
  502. if (!empty($userData)) {
  503. if (empty($userData['openid'])) {
  504. model('User')->update(['wechat_openid' => $wechatCode['openid']],$where);//老用户更新openid
  505. } else {
  506. if ($userData['wechat_openid'] != $wechatCode['openid']) {
  507. throw new Exception('该手机号已被其他用户绑定');
  508. }
  509. }
  510. $ret = $this->auth->direct($userData['id']);
  511. } else {
  512. $extend = [
  513. 'wechat_openid' => $wechatCode['openid'],
  514. ];
  515. $ret = $this->auth->register('', '','', $mobile, $extend);
  516. }
  517. if (!$ret) {
  518. throw new Exception($this->auth->getError());
  519. }
  520. Sms::flush($mobile, 'changemobile');
  521. Db::commit();
  522. $this->success('success',$this->userInfo('return'));
  523. } catch (Exception $e) {
  524. Db::rollback();
  525. $this->error($e->getMessage());
  526. }
  527. }
  528. /**
  529. * 手机注册来的,绑定微信
  530. *
  531. * @ApiMethod (POST)
  532. * @param string $wechat_openid
  533. */
  534. public function bindopenid()
  535. {
  536. $wechat_openid = $this->request->request('wechat_openid');
  537. if (!$wechat_openid) {
  538. $this->error(__('Invalid parameters'));
  539. }
  540. if(!empty($this->auth->wechat_openid)){
  541. $this->error('已经绑定了微信号');
  542. }
  543. $otherUserWhere['wechat_openid'] = $wechat_openid;
  544. $otherUserWhere['id'] = ['neq',$this->auth->id];
  545. if (\app\common\model\User::where($otherUserWhere)->find()) {
  546. $this->error('该微信号已被其他用户绑定');
  547. }
  548. $user = $this->auth->getUser();
  549. $user->wechat_openid = $wechat_openid;
  550. $user->save();
  551. $this->success('success',$this->userInfo('return'));
  552. }
  553. /**
  554. * 重置密码
  555. *
  556. * @ApiMethod (POST)
  557. * @param string $mobile 手机号
  558. * @param string $newpassword 新密码
  559. * @param string $captcha 验证码
  560. */
  561. public function resetpwd()
  562. {
  563. //$type = input("type");
  564. $type = 'mobile';
  565. $mobile = input("mobile");
  566. $email = input("email");
  567. $newpassword = input("newpassword");
  568. $captcha = input("captcha");
  569. if (!$newpassword || !$captcha) {
  570. $this->error(__('Invalid parameters'));
  571. }
  572. if ($type == 'mobile') {
  573. /*if (!Validate::regex($mobile, "^1\d{10}$")) {
  574. $this->error(__('Mobile is incorrect'));
  575. }*/
  576. $user = \app\common\model\User::getByMobile($mobile);
  577. if (!$user) {
  578. $this->error(__('User not found'));
  579. }
  580. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  581. if (!$ret) {
  582. $this->error(__('Captcha is incorrect'));
  583. }
  584. Sms::flush($mobile, 'resetpwd');
  585. } else {
  586. if (!Validate::is($email, "email")) {
  587. $this->error(__('Email is incorrect'));
  588. }
  589. $user = \app\common\model\User::getByEmail($email);
  590. if (!$user) {
  591. $this->error(__('User not found'));
  592. }
  593. $ret = Ems::check($email, $captcha, 'resetpwd');
  594. if (!$ret) {
  595. $this->error(__('Captcha is incorrect'));
  596. }
  597. Ems::flush($email, 'resetpwd');
  598. }
  599. //模拟一次登录
  600. $this->auth->direct($user->id);
  601. $ret = $this->auth->changepwd($newpassword, '', true);
  602. if ($ret) {
  603. $this->success(__('Reset password successful'));
  604. } else {
  605. $this->error($this->auth->getError());
  606. }
  607. }
  608. /**
  609. * 修改密码
  610. *
  611. * @ApiMethod (POST)
  612. * @param string $newpassword 新密码
  613. * @param string $oldpassword 旧密码
  614. */
  615. public function changepwd(){
  616. $newpassword = input('newpassword');
  617. $oldpassword = input('oldpassword','');
  618. if (!$newpassword) {
  619. $this->error(__('Invalid parameters'));
  620. }
  621. if($this->auth->password && empty($oldpassword)){
  622. $this->error('原密码必填');
  623. }
  624. if(empty($this->auth->password)){
  625. $ret = $this->auth->changepwd($newpassword, '', true);
  626. }else{
  627. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  628. }
  629. if ($ret) {
  630. $this->success('设置密码成功');
  631. } else {
  632. $this->error($this->auth->getError());
  633. }
  634. }
  635. /**
  636. * 记录当前登陆的设备ID,设备信息,IP等
  637. */
  638. public function changeDeviceIp()
  639. {
  640. // 接口防并发
  641. if (!$this->apiLimit(1, 5000)) {
  642. return ;
  643. }
  644. $user = $this->auth->getUser();
  645. $ip = request()->ip();
  646. $deviceId = $this->request->request('device_id','');
  647. $phoneModel = $this->request->request('phone_model','');
  648. $brand = $this->request->request('brand','');
  649. $apiVersion = $this->request->request('api_version','');
  650. $deviceOs = $this->request->request('device_os','');
  651. if ($ip !== $user->loginip){
  652. $update = [];
  653. $update['id'] = $user->id;
  654. $update['loginip'] = $ip;
  655. \app\common\model\User::update($update);
  656. }
  657. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  658. if (empty($userDeviceInfo)){
  659. $userDeviceInfo = new UserDeviceInfo();
  660. $userDeviceInfo->user_id = $user->u_id;
  661. }
  662. $userDeviceInfo->device_os = $deviceOs;
  663. $userDeviceInfo->device_id = $deviceId;
  664. $userDeviceInfo->phone_model = $phoneModel;
  665. $userDeviceInfo->brand = $brand;
  666. $userDeviceInfo->api_version = $apiVersion;
  667. $userDeviceInfo->save();
  668. //首页接口调用,这里不反回信息
  669. // $this->success("更新成功!");
  670. }
  671. //假注销
  672. public function cancleUser(){
  673. if (!$this->request->isPost()) {
  674. $this->error(__('Invalid parameters'));
  675. }
  676. //退出im
  677. // $tenIm = new Tenim();
  678. // $tenIm->loginoutim($this->auth->id);
  679. Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
  680. $this->auth->logout();
  681. $this->success('注销成功');
  682. }
  683. //公众号获取openid
  684. public function getUserOpenid_gzh(){
  685. $configValue = Service::getConfig('wechat');
  686. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  687. $rs = $wechat->getOpenid();
  688. $this->success('success',$rs);
  689. }
  690. /**
  691. * 微信内H5-JSAPI支付
  692. */
  693. public function jssdkBuildConfig() {
  694. $url = $this->request->request("url");
  695. $configValue = Service::getConfig('wechat');
  696. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  697. $sign = $wechat->getSignPackage(urldecode($url));
  698. $this->success("获取成功!",$sign);
  699. }
  700. }