User.php 78 KB

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