User.php 82 KB

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