User.php 76 KB

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