User.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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', '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. $nickname = input('nickname','');
  141. $avatar = input('avatar','');
  142. $gender = input('gender',1);
  143. $wechat_openid = input('wechat_openid','');
  144. if (!$wechat_openid) {
  145. $this->error(__('Invalid parameters'));
  146. }
  147. if($gender != 1){
  148. $gender = 0;
  149. }
  150. $user = \app\common\model\User::getByOpenid($wechat_openid);
  151. if ($user) {
  152. if ($user->status == -1) {
  153. $this->error('账户已注销');
  154. }
  155. if ($user->status != 1) {
  156. $this->error(__('Account is locked'));
  157. }
  158. //如果已经有账号则直接登录
  159. $ret = $this->auth->direct($user->id);
  160. } else {
  161. if (!$nickname || !$avatar) {
  162. $this->error(__('Invalid parameters'));
  163. }
  164. $reg_data = [
  165. 'nickname'=>$nickname,
  166. 'avatar'=>$avatar,
  167. 'gender'=>$gender,
  168. 'register_from' => input('register_from',''),
  169. ];
  170. $ret = $this->auth->openid_register($wechat_openid,$reg_data);
  171. }
  172. if ($ret) {
  173. $data = $this->userInfo('return');
  174. $this->success(__('Logged in successful'), $data);
  175. } else {
  176. $this->error($this->auth->getError());
  177. }
  178. }
  179. /**
  180. * 运营商一键登录
  181. */
  182. public function onLogin()
  183. {
  184. $accessToken = input('accessToken');// 运营商预取号获取到的token
  185. $token = input('tokenT');// 易盾返回的token
  186. if (!$accessToken || !$token) {
  187. $this->error("参数获取失败!");
  188. }
  189. $params = array(
  190. // 运营商预取号获取到的token
  191. "accessToken" => $accessToken,
  192. // 易盾返回的token
  193. "token" => $token
  194. );
  195. // 获取密钥配置
  196. $configInfo = config("onLogin");
  197. $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
  198. $onret = $onlogin->check($params);
  199. // $ret = [];
  200. // $ret["code"] = 200;
  201. // $ret["msg"] = "ok";
  202. // $ret["data"] = [
  203. // "phone" => "17574504021",
  204. // "resultCode" => 0
  205. // ];
  206. if ($onret["code"] == 200) {
  207. $mobile = $onret["data"]["phone"];
  208. if (empty($mobile)) {
  209. // 取号失败,建议进行二次验证,例如短信验证码
  210. $this->error("取号登录失败,请用验证码方式登录!");
  211. } else {
  212. // 取号成功, 执行登录等流程
  213. // 用户登录逻辑 === 开始
  214. $user = \app\common\model\User::getByMobile($mobile);
  215. if ($user) {
  216. if ($user->status == -1) {
  217. $this->error('账户已注销');
  218. }
  219. if ($user->status != 1) {
  220. $this->error(__('Account is locked'));
  221. }
  222. //如果已经有账号则直接登录
  223. $ret = $this->auth->direct($user->id);
  224. $is_register = 0;
  225. } else {
  226. $ret = $this->auth->register('', '', '', $mobile, []);
  227. $is_register = 1;
  228. }
  229. if ($ret) {
  230. $this->success(__('Logged in successful'), $this->auth->getUserinfo());
  231. } else {
  232. $this->error($this->auth->getError());
  233. }
  234. // 用户登录逻辑 === 结束
  235. }
  236. } else {
  237. $this->error("登录失败,请用验证码方式登录!");
  238. }
  239. }
  240. //苹果登录+注册
  241. public function applelogin(){
  242. $iosUserId = input_post('ios_user_id','');
  243. if(!$iosUserId){
  244. $this->error(__('Invalid parameters'));
  245. }
  246. $user = Db::name('user')->where('ios_user_id',$iosUserId)->find();
  247. if ($user) {
  248. if ($user['status'] == -1) {
  249. $this->error('账户已经注销');
  250. }
  251. if ($user['status'] != 1) {
  252. $this->error(__('Account is locked'));
  253. }
  254. //如果已经有账号则直接登录
  255. $ret = $this->auth->direct($user['id']);
  256. } else {
  257. $ret = $this->auth->ios_register($iosUserId);
  258. }
  259. if ($ret) {
  260. $data = ['userinfo' => $this->auth->getUserinfo()];
  261. $this->success(__('Logged in successful'), $data);
  262. } else {
  263. $this->error($this->auth->getError());
  264. }
  265. }
  266. //用户详细资料
  267. public function userInfo($type = 1){
  268. $info = $this->auth->getUserinfo();
  269. if($type == 'return'){
  270. return $info;
  271. }
  272. $this->success(__('success'),$info);
  273. }
  274. /**
  275. * 退出登录
  276. * @ApiMethod (POST)
  277. */
  278. public function logout()
  279. {
  280. if (!$this->request->isPost()) {
  281. $this->error(__('Invalid parameters'));
  282. }
  283. //退出im
  284. // $tenIm = new Tenim();
  285. // $tenIm->loginoutim($this->auth->id);
  286. $this->auth->logout();
  287. $this->success(__('Logout successful'));
  288. }
  289. /**
  290. * 修改会员个人信息
  291. *
  292. * @ApiMethod (POST)
  293. * @param string $avatar 头像地址
  294. * @param string $username 用户名
  295. * @param string $nickname 昵称
  296. * @param string $bio 个人简介
  297. */
  298. public function profile()
  299. {
  300. $field_array = ['nickname','introcode','gender','birthday','attribute','shoesize','height','weight','bio','avatar','photo_images','tag_ids','hide_is_finishinfo'];
  301. $data = [];
  302. foreach($field_array as $key => $field){
  303. //前端传不了post,改了
  304. /*if(!request()->has($field,'post')){
  305. continue;
  306. }*/
  307. if(!input('?'.$field)){
  308. continue;
  309. }
  310. $newone = input($field);
  311. if($field == 'avatar'){
  312. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  313. }
  314. if($field == 'photo_images'){
  315. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  316. }
  317. $data[$field] = $newone;
  318. }
  319. if(isset($data['birthday'])){
  320. $data['birthday'] = strtotime($data['birthday']);
  321. }
  322. if(isset($data['tag_ids'])){
  323. $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
  324. }
  325. if(isset($data['introcode'])){
  326. $intro_user = Db::name('user')->where('introcode',$data['introcode'])->value('id');
  327. if(!$intro_user){
  328. $this->error('不存在的邀请人');
  329. }
  330. unset($data['introcode']);//别人的邀请码,不能改了自己的
  331. $data['intro_uid'] = $intro_user;
  332. }
  333. //dump($data);
  334. if(empty($data)){
  335. $this->error('没有任何改变');
  336. }
  337. //默认头像
  338. //现在没头像,也没穿头像,但是却传了性别
  339. /*if($this->auth->avatar == config('site.domain_cdnurl').'/avatar.png' && isset($data['gender']) && $data['avatar'] == config('site.domain_cdnurl').'/avatar.png'){
  340. if($data['gender'] == 1){
  341. $data['avatar'] = 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/f9277fba97fd76d9ecfc63b506a3674a.png';
  342. }else{
  343. $data['avatar'] = 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/5030460c05c86774f60123ffea7b78a1.png';
  344. }
  345. }*/
  346. //默认头像
  347. Db::startTrans();
  348. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  349. if($update_rs === false){
  350. Db::rollback();
  351. $this->error('修改资料失败');
  352. }
  353. //tag任务赠送金币
  354. //上传头像加5金币
  355. /*if(isset($data['avatar'])){
  356. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  357. if($task_rs === false){
  358. Db::rollback();
  359. $this->error('完成任务赠送奖励失败');
  360. }
  361. }*/
  362. //上传本人语音介绍 10金币
  363. /*if(isset($data['audio_bio'])){
  364. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,6);
  365. if($task_rs === false){
  366. Db::rollback();
  367. $this->error('完成任务赠送奖励失败');
  368. }
  369. }*/
  370. //上传本人五张照片 10金币
  371. /*if(isset($data['photo_images']) && count(explode(',',$data['photo_images'])) >= 5){
  372. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,8);
  373. if($task_rs === false){
  374. Db::rollback();
  375. $this->error('完成任务赠送奖励失败');
  376. }
  377. }*/
  378. //所有资料完成
  379. /*$user_info = Db::name('user')->where('id',$this->auth->id)->find();
  380. if($user_info['avatar'] && $user_info['nickname'] && $user_info['mobile'] && $user_info['audio_bio'] && $user_info['photo_images']){
  381. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
  382. if($task_rs === false){
  383. Db::rollback();
  384. $this->error('完成任务赠送奖励失败');
  385. }
  386. }*/
  387. Db::commit();
  388. $this->success();
  389. }
  390. /**
  391. * 修改会员权限
  392. */
  393. public function setpower()
  394. {
  395. $is_vip = $this->is_vip($this->auth->id);
  396. if(!$is_vip){
  397. $this->error('VIP才能设置隐私权限');
  398. }
  399. $data = [
  400. 'yinsi' => input('yinsi',0),
  401. 'yinshen' => input('yinshen',0),
  402. 'wuhen' => input('wuhen',0),
  403. ];
  404. $update_rs = Db::name('user_power')->where('id',$this->auth->id)->update($data);
  405. $this->success();
  406. }
  407. /*
  408. * 修改用户的坐标
  409. * */
  410. public function change_longlat(){
  411. $longitude = input_post('longitude',0);
  412. $latitude = input_post('latitude',0);
  413. $cityname = input_post('cityname','');
  414. if(empty($longitude) || empty($latitude) || empty($cityname)){
  415. $this->error();
  416. }
  417. $data = [
  418. 'longitude' => $longitude,
  419. 'latitude' => $latitude,
  420. 'cityname' => $cityname,
  421. ];
  422. Db::name('user')->where('id',$this->auth->id)->update($data);
  423. $this->success();
  424. }
  425. /**
  426. * 修改手机号
  427. *
  428. * @ApiMethod (POST)
  429. * @param string $mobile 手机号
  430. * @param string $captcha 验证码
  431. */
  432. public function changemobile()
  433. {
  434. $user = $this->auth->getUser();
  435. $oldcaptcha = $this->request->request('oldcaptcha');
  436. $mobile = $this->request->request('mobile');
  437. $captcha = $this->request->request('captcha');
  438. if (!$oldcaptcha || !$mobile || !$captcha) {
  439. $this->error(__('Invalid parameters'));
  440. }
  441. if (!Validate::regex($mobile, "^1\d{10}$")) {
  442. $this->error(__('Mobile is incorrect'));
  443. }
  444. if($user->mobile == $mobile){
  445. $this->error('新手机号不能与旧手机号相同');
  446. }
  447. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  448. $this->error(__('Mobile already exist'));
  449. }
  450. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  451. if (!$result) {
  452. $this->error(__('Captcha is incorrect'));
  453. }
  454. $result = Sms::check($mobile, $captcha, 'changemobile');
  455. if (!$result) {
  456. $this->error(__('Captcha is incorrect'));
  457. }
  458. $verification = $user->verification;
  459. $verification->mobile = 1;
  460. $user->verification = $verification;
  461. $user->mobile = $mobile;
  462. $user->save();
  463. Sms::flush($user->mobile, 'changemobile');
  464. Sms::flush($mobile, 'changemobile');
  465. $this->success();
  466. }
  467. /**
  468. * 微信注册来的,绑定手机号
  469. *
  470. * @ApiMethod (POST)
  471. * @param string $mobile 手机号
  472. * @param string $captcha 验证码
  473. */
  474. public function bindmobile()
  475. {
  476. $user = $this->auth->getUser();
  477. $mobile = $this->request->request('mobile');
  478. $captcha = $this->request->request('captcha');
  479. if(!empty($this->auth->mobile)){
  480. $this->error('已经绑定了手机号');
  481. }
  482. if (!$mobile || !$captcha) {
  483. $this->error(__('Invalid parameters'));
  484. }
  485. if (!Validate::regex($mobile, "^1\d{10}$")) {
  486. $this->error(__('Mobile is incorrect'));
  487. }
  488. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  489. $this->error('该手机号已被其他用户绑定');
  490. }
  491. $result = Sms::check($mobile, $captcha, 'changemobile');
  492. if (!$result) {
  493. $this->error(__('Captcha is incorrect'));
  494. }
  495. $verification = $user->verification;
  496. $verification->mobile = 1;
  497. $user->verification = $verification;
  498. $user->mobile = $mobile;
  499. $user->save();
  500. Sms::flush($mobile, 'changemobile');
  501. $this->success('success',$this->userInfo('return'));
  502. }
  503. /**
  504. * 手机注册来的,绑定微信
  505. *
  506. * @ApiMethod (POST)
  507. * @param string $wechat_openid
  508. */
  509. public function bindopenid()
  510. {
  511. $wechat_openid = $this->request->request('wechat_openid');
  512. if (!$wechat_openid) {
  513. $this->error(__('Invalid parameters'));
  514. }
  515. if(!empty($this->auth->wechat_openid)){
  516. $this->error('已经绑定了微信号');
  517. }
  518. $otherUserWhere['wechat_openid'] = $wechat_openid;
  519. $otherUserWhere['id'] = ['neq',$this->auth->id];
  520. if (\app\common\model\User::where($otherUserWhere)->find()) {
  521. $this->error('该微信号已被其他用户绑定');
  522. }
  523. $user = $this->auth->getUser();
  524. $user->wechat_openid = $wechat_openid;
  525. $user->save();
  526. $this->success('success',$this->userInfo('return'));
  527. }
  528. /**
  529. * 重置密码
  530. *
  531. * @ApiMethod (POST)
  532. * @param string $mobile 手机号
  533. * @param string $newpassword 新密码
  534. * @param string $captcha 验证码
  535. */
  536. public function resetpwd()
  537. {
  538. //$type = input("type");
  539. $type = 'mobile';
  540. $mobile = input("mobile");
  541. $email = input("email");
  542. $newpassword = input("newpassword");
  543. $captcha = input("captcha");
  544. if (!$newpassword || !$captcha) {
  545. $this->error(__('Invalid parameters'));
  546. }
  547. if ($type == 'mobile') {
  548. if (!Validate::regex($mobile, "^1\d{10}$")) {
  549. $this->error(__('Mobile is incorrect'));
  550. }
  551. $user = \app\common\model\User::getByMobile($mobile);
  552. if (!$user) {
  553. $this->error(__('User not found'));
  554. }
  555. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  556. if (!$ret) {
  557. $this->error(__('Captcha is incorrect'));
  558. }
  559. Sms::flush($mobile, 'resetpwd');
  560. } else {
  561. if (!Validate::is($email, "email")) {
  562. $this->error(__('Email is incorrect'));
  563. }
  564. $user = \app\common\model\User::getByEmail($email);
  565. if (!$user) {
  566. $this->error(__('User not found'));
  567. }
  568. $ret = Ems::check($email, $captcha, 'resetpwd');
  569. if (!$ret) {
  570. $this->error(__('Captcha is incorrect'));
  571. }
  572. Ems::flush($email, 'resetpwd');
  573. }
  574. //模拟一次登录
  575. $this->auth->direct($user->id);
  576. $ret = $this->auth->changepwd($newpassword, '', true);
  577. if ($ret) {
  578. $this->success(__('Reset password successful'));
  579. } else {
  580. $this->error($this->auth->getError());
  581. }
  582. }
  583. /**
  584. * 修改密码
  585. *
  586. * @ApiMethod (POST)
  587. * @param string $newpassword 新密码
  588. * @param string $oldpassword 旧密码
  589. */
  590. public function changepwd(){
  591. $newpassword = input('newpassword');
  592. $oldpassword = input('oldpassword','');
  593. if (!$newpassword) {
  594. $this->error(__('Invalid parameters'));
  595. }
  596. if($this->auth->password && empty($oldpassword)){
  597. $this->error('原密码必填');
  598. }
  599. if(empty($this->auth->password)){
  600. $ret = $this->auth->changepwd($newpassword, '', true);
  601. }else{
  602. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  603. }
  604. if ($ret) {
  605. $this->success('设置密码成功');
  606. } else {
  607. $this->error($this->auth->getError());
  608. }
  609. }
  610. /**
  611. * 记录当前登陆的设备ID,设备信息,IP等
  612. */
  613. public function changeDeviceIp()
  614. {
  615. // 接口防并发
  616. if (!$this->apiLimit(1, 5000)) {
  617. return ;
  618. }
  619. $user = $this->auth->getUser();
  620. $ip = request()->ip();
  621. $deviceId = $this->request->request('device_id','');
  622. $phoneModel = $this->request->request('phone_model','');
  623. $brand = $this->request->request('brand','');
  624. $apiVersion = $this->request->request('api_version','');
  625. $deviceOs = $this->request->request('device_os','');
  626. if ($ip !== $user->loginip){
  627. $update = [];
  628. $update['id'] = $user->id;
  629. $update['loginip'] = $ip;
  630. \app\common\model\User::update($update);
  631. }
  632. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  633. if (empty($userDeviceInfo)){
  634. $userDeviceInfo = new UserDeviceInfo();
  635. $userDeviceInfo->user_id = $user->u_id;
  636. }
  637. $userDeviceInfo->device_os = $deviceOs;
  638. $userDeviceInfo->device_id = $deviceId;
  639. $userDeviceInfo->phone_model = $phoneModel;
  640. $userDeviceInfo->brand = $brand;
  641. $userDeviceInfo->api_version = $apiVersion;
  642. $userDeviceInfo->save();
  643. //首页接口调用,这里不反回信息
  644. // $this->success("更新成功!");
  645. }
  646. //假注销
  647. public function cancleUser(){
  648. if (!$this->request->isPost()) {
  649. $this->error(__('Invalid parameters'));
  650. }
  651. //退出im
  652. // $tenIm = new Tenim();
  653. // $tenIm->loginoutim($this->auth->id);
  654. Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
  655. $this->auth->logout();
  656. $this->success('注销成功');
  657. }
  658. //公众号获取openid
  659. public function getUserOpenid_gzh(){
  660. $configValue = Service::getConfig('wechat');
  661. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  662. $rs = $wechat->getOpenid();
  663. $this->success('success',$rs);
  664. }
  665. /**
  666. * 微信内H5-JSAPI支付
  667. */
  668. public function jssdkBuildConfig() {
  669. $url = $this->request->request("url");
  670. $configValue = Service::getConfig('wechat');
  671. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  672. $sign = $wechat->getSignPackage(urldecode($url));
  673. $this->success("获取成功!",$sign);
  674. }
  675. }