User.php 77 KB

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