User.php 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434
  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. //用户邀请信息
  517. public function userintroinfo(){
  518. $intro_num = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  519. $money_sum = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'log_type'=>63])->sum('change_value');
  520. $user_list = Db::name('user')->field('id,avatar,nickname,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  521. $rs = [
  522. 'intro_num' => $intro_num,
  523. 'money_sum' => $money_sum,
  524. 'user_list' => $user_list,
  525. ];
  526. $this->success('success',$rs);
  527. }
  528. public function testhaibao(){
  529. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
  530. // dump($haibao);
  531. $this->success('success', $haibao);
  532. }
  533. //海报
  534. public function haibao($player_id,$data){
  535. //下载页二维码,没必要保留
  536. $params = [
  537. 'text' => config('site.domain_name').'?code=' . $data['introcode'],
  538. 'size' => 90,
  539. 'logo' => false,
  540. 'label' => false,
  541. 'padding' => 0,
  542. ];
  543. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  544. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  545. mk_dir($qrcode_path);
  546. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  547. $qrCode->writeFile($download_qrcode);
  548. //海报
  549. $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
  550. return $haibao;
  551. }
  552. /*public function createhaibao($download_qrcode,$player_id,$sub_data){
  553. //背景图
  554. $background = $sub_data['background'] ? $sub_data['background'] : config('site.domain_name').'/assets/img/haibao.png';
  555. //海报图片路径
  556. $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
  557. mk_dir($new_path);
  558. $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
  559. //二维码
  560. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  561. //合成wap图片
  562. $image = new \addons\poster\library\Image2();
  563. $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
  564. return '/'.$wap_file_name;
  565. }*/
  566. public function createhaibao($download_qrcode,$player_id,$sub_data){
  567. //二维码
  568. $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
  569. $data = [
  570. [
  571. "left" => "15px",
  572. "top" => "296px",
  573. "type" => "img",
  574. "width" => "58px",
  575. "height" => "58px",
  576. "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  577. ],
  578. [
  579. "left" => "81px",
  580. "top" => "300px",
  581. "type" => "nickname",
  582. "width" => "80px",
  583. "height" => "24px",
  584. "size" => "12px",
  585. "color" => "#000",
  586. "content" => $this->auth->nickname
  587. ],
  588. [
  589. "left" => "81px",
  590. "top" => "327px",
  591. "type" => "nickname",
  592. "width" => "80px",
  593. "height" => "24px",
  594. "size" => "12px",
  595. "color" => "#000",
  596. "content" => $this->auth->introcode
  597. ],
  598. [
  599. "left" => "227px",
  600. "top" => "283px",
  601. "type" => "img",
  602. "width" => "80px",
  603. "height" => "80px",
  604. // "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  605. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  606. ]
  607. ];
  608. $data = json_encode($data, 320);
  609. $poster = [
  610. 'id' => 1,
  611. 'title' => '测试2',
  612. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  613. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  614. 'data' => $data,
  615. 'status' => 'normal',
  616. 'weigh' => 0,
  617. 'createtime' => 1653993709,
  618. 'updatetime' => 1653994259,
  619. ];
  620. $image = new \addons\poster\library\Image();
  621. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  622. if (!$imgurl) {
  623. $this->error('生成海报出错');
  624. }
  625. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  626. return '/' . $imgurl;
  627. }
  628. //申请真人认证
  629. public function apply_real_confirm(){
  630. $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  631. if(!$avatar){
  632. $this->error('请上传真人头像');
  633. }
  634. Db::startTrans();
  635. $data = [
  636. 'avatar' => $avatar,
  637. 'real_status' => 1,
  638. ];
  639. $rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  640. if($rs === false){
  641. Db::rollback();
  642. $this->error('认证失败');
  643. }
  644. //tag任务赠送金币
  645. //完成本人基本资料 +15金币《所有资料完善,包括真人认证和实名认证》
  646. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
  647. if($task_rs === false){
  648. Db::rollback();
  649. $this->error('完成任务赠送奖励失败');
  650. }
  651. //完成真人头像 +5金币
  652. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,7);
  653. if($task_rs === false){
  654. Db::rollback();
  655. $this->error('完成任务赠送奖励失败');
  656. }
  657. //邀请人拿奖励,男性3元
  658. $intro_money = $this->auth->gender == 1 ? config('site.intro_man_money') : config('site.intro_woman_money');
  659. if($this->auth->idcard_status == 1 && !empty($this->auth->intro_uid) && $intro_money > 0){
  660. $task_rs = model('wallet')->lockChangeAccountRemain($this->auth->intro_uid,$this->auth->id,'money',$intro_money,63,$remark='邀请人拿奖励');
  661. if($task_rs['status'] === false){
  662. Db::rollback();
  663. $this->error($task_rs['msg']);
  664. }
  665. }
  666. //系统消息
  667. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  668. Db::commit();
  669. $this->success();
  670. }
  671. //实名认证信息
  672. public function idcard_confirm_info(){
  673. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  674. if (!$check) {
  675. $check = (object)[];
  676. }
  677. $this->success('success',$check);
  678. }
  679. /**
  680. * 退出登录
  681. * @ApiMethod (POST)
  682. */
  683. public function logout()
  684. {
  685. if (!$this->request->isPost()) {
  686. $this->error(__('Invalid parameters'));
  687. }
  688. //退出im
  689. $tenIm = new Tenim();
  690. $tenIm->loginoutim($this->auth->id);
  691. //修改用户活跃0
  692. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
  693. $this->auth->logout();
  694. $this->success(__('Logout successful'));
  695. }
  696. /**
  697. * 修改会员个人信息
  698. *
  699. * @ApiMethod (POST)
  700. * @param string $avatar 头像地址
  701. * @param string $username 用户名
  702. * @param string $nickname 昵称
  703. * @param string $bio 个人简介
  704. */
  705. public function profile()
  706. {
  707. $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'];
  708. $data = [];
  709. foreach($field_array as $key => $field){
  710. if(!input('?'.$field)){
  711. continue;
  712. }
  713. $newone = input($field);
  714. if($field == 'avatar'){
  715. // if ($this->auth->real_status == 1) {
  716. //$this->error('您已经真人认证不能修改头像~');
  717. // die;
  718. // }
  719. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  720. }
  721. if($field == 'photo_images'){
  722. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  723. }
  724. $data[$field] = $newone;
  725. }
  726. if(isset($data['birthday'])){
  727. $data['birthday'] = strtotime($data['birthday']);
  728. }
  729. if(isset($data['avatar'])){
  730. //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
  731. }
  732. if(isset($data['hobby_ids'])){
  733. $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
  734. }
  735. if(isset($data['tag_ids'])){
  736. $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
  737. }
  738. if(isset($data['introcode'])){
  739. if ($this->auth->intro_uid != 0) {
  740. $this->error('邀请人不可修改~');
  741. }
  742. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
  743. if(!$intro_user){
  744. $this->error('不存在的邀请人');
  745. }
  746. if ($intro_user['id'] == $this->auth->id) {
  747. $this->error('不能填写自己邀请码');
  748. }
  749. if ($intro_user['intro_uid'] == $this->auth->id) {
  750. $this->error('不能填写下级邀请码');
  751. }
  752. unset($data['introcode']);//别人的邀请码,不能改了自己的
  753. $data['intro_uid'] = $intro_user['id'];
  754. $data['invite_time'] = time();
  755. }
  756. //dump($data);
  757. if(empty($data)){
  758. $this->error('没有任何改变');
  759. }
  760. Db::startTrans();
  761. $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
  762. if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {//隐藏
  763. $boyAvatar = config('avatar_boy');
  764. $girlAvatar = config('avatar_girl');
  765. if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
  766. $data['status'] = 1;//更新为正常
  767. } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
  768. $data['status'] = 1;//更新为正常
  769. }
  770. }
  771. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  772. if($update_rs === false){
  773. Db::rollback();
  774. $this->error('修改资料失败');
  775. }
  776. //tag任务赠送金币
  777. //上传头像加5金币
  778. if(isset($data['avatar'])){
  779. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  780. if($task_rs === false){
  781. Db::rollback();
  782. $this->error('完成任务赠送奖励失败');
  783. }
  784. }
  785. //上传生日 +5金币
  786. if (isset($data['birthday'])) {
  787. //完成设置生日 +5金币
  788. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  789. if($task_rs === false){
  790. Db::rollback();
  791. $this->error('完成任务赠送奖励失败');
  792. }
  793. }
  794. //上传个性签名 5金币
  795. if(isset($data['audio_bio'])){
  796. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
  797. if($task_rs === false){
  798. Db::rollback();
  799. $this->error('完成任务赠送奖励失败');
  800. }
  801. }
  802. //上传本人语音介绍 10金币
  803. if(isset($data['audio_bio'])){
  804. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
  805. if($task_rs === false){
  806. Db::rollback();
  807. $this->error('完成任务赠送奖励失败');
  808. }
  809. }
  810. //上传本人五张照片 10金币
  811. if(isset($data['photo_images'])){
  812. $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
  813. if ($photo_images_num >= 5) {
  814. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
  815. if ($task_rs === false) {
  816. Db::rollback();
  817. $this->error('完成任务赠送奖励失败');
  818. }
  819. }
  820. }
  821. /*if (isset($data['intro_uid'])) { //邀请人获得金币
  822. $intro_gold = config('site.intro_gold');
  823. if ($intro_gold > 0) {
  824. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],$this->auth->id,'gold',$intro_gold,64,'邀请注册奖励','user', $this->auth->id);
  825. if($wallet_rs['status'] === false){
  826. Db::rollback();
  827. $this->error($wallet_rs['msg']);
  828. }
  829. }
  830. }*/
  831. Db::commit();
  832. /*//开启事务
  833. Db::startTrans();
  834. //所有基本资料完成
  835. $user_info = Db::name('user')->where('id',$this->auth->id)->find();
  836. if($user_info['hometown_cityid'] && $user_info['job_id'] && $user_info['education_id'] && $user_info['wages_id'] && $user_info['character_id'] && $user_info['stature_id'] && $user_info['weight'] && $user_info['height'] && $user_info['marital_id']){
  837. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,6);
  838. if($task_rs === false){
  839. Db::rollback();
  840. $this->error('完成任务赠送奖励失败');
  841. }
  842. }
  843. //兴趣爱好
  844. if($user_info['hobby_ids']){
  845. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,7);
  846. if($task_rs === false){
  847. Db::rollback();
  848. $this->error('完成任务赠送奖励失败');
  849. }
  850. }
  851. //个人标签
  852. if($user_info['tag_ids']){
  853. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,8);
  854. if($task_rs === false){
  855. Db::rollback();
  856. $this->error('完成任务赠送奖励失败');
  857. }
  858. }
  859. Db::commit();*/
  860. $this->success();
  861. }
  862. /*
  863. * 修改用户的坐标
  864. * */
  865. public function change_longlat(){
  866. $longitude = input_post('longitude');
  867. $latitude = input_post('latitude');
  868. $cityname = input_post('cityname');
  869. if(empty($longitude) || empty($latitude) || empty($cityname)){
  870. $this->error();
  871. }
  872. $data = [
  873. 'longitude' => $longitude,
  874. 'latitude' => $latitude,
  875. 'cityname' => $cityname,
  876. ];
  877. Db::name('user')->where('id',$this->auth->id)->update($data);
  878. $this->success();
  879. }
  880. /**
  881. * 修改手机号
  882. *
  883. * @ApiMethod (POST)
  884. * @param string $mobile 手机号
  885. * @param string $captcha 验证码
  886. */
  887. public function changemobile()
  888. {
  889. $user = $this->auth->getUser();
  890. $oldcaptcha = $this->request->request('oldcaptcha');
  891. $mobile = $this->request->request('mobile');
  892. $captcha = $this->request->request('captcha');
  893. if (!$oldcaptcha || !$mobile || !$captcha) {
  894. $this->error(__('Invalid parameters'));
  895. }
  896. if (!Validate::regex($mobile, "^1\d{10}$")) {
  897. $this->error(__('Mobile is incorrect'));
  898. }
  899. if($user->mobile == $mobile){
  900. $this->error('新手机号不能与旧手机号相同');
  901. }
  902. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  903. $this->error(__('Mobile already exist'));
  904. }
  905. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  906. if (!$result) {
  907. $this->error(__('Captcha is incorrect'));
  908. }
  909. $result = Sms::check($mobile, $captcha, 'changemobile');
  910. if (!$result) {
  911. $this->error(__('Captcha is incorrect'));
  912. }
  913. $verification = $user->verification;
  914. $verification->mobile = 1;
  915. $user->verification = $verification;
  916. $user->mobile = $mobile;
  917. $user->save();
  918. Sms::flush($user->mobile, 'changemobile');
  919. Sms::flush($mobile, 'changemobile');
  920. $this->success();
  921. }
  922. /**
  923. * 微信注册来的,绑定手机号
  924. *
  925. * @ApiMethod (POST)
  926. * @param string $mobile 手机号
  927. * @param string $captcha 验证码
  928. */
  929. public function bindmobile()
  930. {
  931. $user = $this->auth->getUser();
  932. $mobile = $this->request->request('mobile');
  933. $captcha = $this->request->request('captcha');
  934. if(!empty($this->auth->mobile)){
  935. $this->error('已经绑定了手机号');
  936. }
  937. if (!$mobile || !$captcha) {
  938. $this->error(__('Invalid parameters'));
  939. }
  940. if (!Validate::regex($mobile, "^1\d{10}$")) {
  941. $this->error(__('Mobile is incorrect'));
  942. }
  943. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  944. $this->error('该手机号已被其他用户绑定');
  945. }
  946. $result = Sms::check($mobile, $captcha, 'changemobile');
  947. if (!$result) {
  948. $this->error(__('Captcha is incorrect'));
  949. }
  950. $verification = $user->verification;
  951. $verification->mobile = 1;
  952. $user->verification = $verification;
  953. $user->mobile = $mobile;
  954. $user->save();
  955. Sms::flush($mobile, 'changemobile');
  956. //手机号奖励
  957. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
  958. if($task_rs === false){
  959. Db::rollback();
  960. return false;
  961. }
  962. $this->success('success',$this->userInfo('return'));
  963. }
  964. /**
  965. * 手机号注册来的,绑定微信
  966. *
  967. * @ApiMethod (POST)
  968. * @param string wechat_openid 微信openid
  969. */
  970. public function bindopenid()
  971. {
  972. $user = $this->auth->getUser();
  973. $wechat_openid = $this->request->request('wechat_openid');
  974. if(!empty($this->auth->wechat_openid)){
  975. $this->error('已经绑定了微信号');
  976. }
  977. if (!$wechat_openid) {
  978. $this->error(__('Invalid parameters'));
  979. }
  980. if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
  981. $this->error('该微信号已被其他用户绑定');
  982. }
  983. $user->wechat_openid = $wechat_openid;
  984. $user->save();
  985. $this->success('success',$this->userInfo('return'));
  986. }
  987. /**
  988. * 重置密码
  989. *
  990. * @ApiMethod (POST)
  991. * @param string $mobile 手机号
  992. * @param string $newpassword 新密码
  993. * @param string $captcha 验证码
  994. */
  995. public function resetpwd()
  996. {
  997. //$type = input("type");
  998. $type = 'mobile';
  999. $mobile = input("mobile");
  1000. $email = input("email");
  1001. $newpassword = input("newpassword");
  1002. $captcha = input("captcha");
  1003. if (!$newpassword || !$captcha) {
  1004. $this->error(__('Invalid parameters'));
  1005. }
  1006. if ($type == 'mobile') {
  1007. if (!Validate::regex($mobile, "^1\d{10}$")) {
  1008. $this->error(__('Mobile is incorrect'));
  1009. }
  1010. $user = \app\common\model\User::getByMobile($mobile);
  1011. if (!$user) {
  1012. $this->error(__('User not found'));
  1013. }
  1014. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  1015. if (!$ret) {
  1016. $this->error(__('Captcha is incorrect'));
  1017. }
  1018. Sms::flush($mobile, 'resetpwd');
  1019. } else {
  1020. if (!Validate::is($email, "email")) {
  1021. $this->error(__('Email is incorrect'));
  1022. }
  1023. $user = \app\common\model\User::getByEmail($email);
  1024. if (!$user) {
  1025. $this->error(__('User not found'));
  1026. }
  1027. $ret = Ems::check($email, $captcha, 'resetpwd');
  1028. if (!$ret) {
  1029. $this->error(__('Captcha is incorrect'));
  1030. }
  1031. Ems::flush($email, 'resetpwd');
  1032. }
  1033. //模拟一次登录
  1034. $this->auth->direct($user->id);
  1035. $ret = $this->auth->changepwd($newpassword, '', true);
  1036. if ($ret) {
  1037. $this->success(__('Reset password successful'));
  1038. } else {
  1039. $this->error($this->auth->getError());
  1040. }
  1041. }
  1042. /**
  1043. * 修改密码
  1044. *
  1045. * @ApiMethod (POST)
  1046. * @param string $newpassword 新密码
  1047. * @param string $oldpassword 旧密码
  1048. */
  1049. public function changepwd(){
  1050. $newpassword = input('newpassword');
  1051. $oldpassword = input('oldpassword','');
  1052. if (!$newpassword) {
  1053. $this->error(__('Invalid parameters'));
  1054. }
  1055. if($this->auth->password && empty($oldpassword)){
  1056. $this->error('原密码必填');
  1057. }
  1058. if(empty($this->auth->password)){
  1059. $ret = $this->auth->changepwd($newpassword, '', true);
  1060. }else{
  1061. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  1062. }
  1063. if ($ret) {
  1064. $this->success(__('Reset password successful'));
  1065. } else {
  1066. $this->error($this->auth->getError());
  1067. }
  1068. }
  1069. /**
  1070. * 记录当前登陆的设备ID,设备信息,IP等
  1071. */
  1072. public function changeDeviceIp()
  1073. {
  1074. // 接口防并发
  1075. if (!$this->apiLimit(1, 5)) {
  1076. return ;
  1077. }
  1078. $user = $this->auth->getUser();
  1079. $ip = request()->ip();
  1080. $deviceId = $this->request->request('device_id','');
  1081. $phoneModel = $this->request->request('phone_model','');
  1082. $brand = $this->request->request('brand','');
  1083. $apiVersion = $this->request->request('api_version','');
  1084. $deviceOs = $this->request->request('device_os','');
  1085. if ($ip !== $user->loginip){
  1086. $update = [];
  1087. $update['id'] = $user->id;
  1088. $update['loginip'] = $ip;
  1089. \app\common\model\User::update($update);
  1090. }
  1091. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  1092. if (empty($userDeviceInfo)){
  1093. $userDeviceInfo = new UserDeviceInfo();
  1094. $userDeviceInfo->user_id = $user->u_id;
  1095. }
  1096. $userDeviceInfo->device_os = $deviceOs;
  1097. $userDeviceInfo->device_id = $deviceId;
  1098. $userDeviceInfo->phone_model = $phoneModel;
  1099. $userDeviceInfo->brand = $brand;
  1100. $userDeviceInfo->api_version = $apiVersion;
  1101. $userDeviceInfo->save();
  1102. //首页接口调用,这里不反回信息
  1103. // $this->success("更新成功!");
  1104. }
  1105. //假注销
  1106. public function cancleUser(){
  1107. if (!$this->request->isPost()) {
  1108. $this->error(__('Invalid parameters'));
  1109. }
  1110. //退出im
  1111. $tenIm = new Tenim();
  1112. $tenIm->loginoutim($this->auth->id);
  1113. Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
  1114. $this->auth->logout();
  1115. $this->success('注销成功');
  1116. }
  1117. //修改用户活跃1
  1118. public function useractive(){
  1119. $this->success('success');
  1120. }
  1121. //公众号获取openid
  1122. public function getUserOpenid_gzh(){
  1123. $configValue = Service::getConfig('wechat');
  1124. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1125. $rs = $wechat->getOpenid();
  1126. $this->success('success',$rs);
  1127. }
  1128. /**
  1129. * 微信内H5-JSAPI支付
  1130. */
  1131. public function jssdkBuildConfig() {
  1132. $url = $this->request->request("url");
  1133. $configValue = Service::getConfig('wechat');
  1134. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1135. $sign = $wechat->getSignPackage(urldecode($url));
  1136. $this->success("获取成功!",$sign);
  1137. }
  1138. //苹果账号登录
  1139. public function ioslogin(){
  1140. $ios_openid = input('ios_openid','');
  1141. if (!$ios_openid) {
  1142. $this->error(__('Invalid parameters'));
  1143. }
  1144. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1145. /*if (!$user) {
  1146. $this->success('选择性别', ['code' => 5]);
  1147. }*/
  1148. if ($user) {
  1149. if (!in_array($user->status,[1,2])) {
  1150. $this->error(__('Account is locked'));
  1151. }
  1152. if ($user->frozentime > time()) {
  1153. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  1154. }
  1155. //如果已经有账号则直接登录
  1156. $ret = $this->auth->direct($user->id);
  1157. } else {
  1158. $reg_data = [
  1159. 'register_from' => input('register_from',''),
  1160. 'gender' => -1
  1161. ];
  1162. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1163. }
  1164. if ($ret) {
  1165. $data = $this->userInfo('return');
  1166. $this->success(__('Logged in successful'), $data);
  1167. } else {
  1168. $this->error($this->auth->getError());
  1169. }
  1170. }
  1171. //苹果账号注册
  1172. public function iosregiter(){
  1173. $ios_openid = input('ios_openid', '', 'trim');
  1174. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1175. if (!$ios_openid) {
  1176. $this->error(__('Invalid parameters'));
  1177. }
  1178. if (!in_array($gender, [1, 0])) {
  1179. $this->error('性别错误');
  1180. }
  1181. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1182. if ($user) {
  1183. $this->error('账号已经存在,请直接登录');
  1184. }
  1185. $reg_data = [
  1186. 'register_from' => input('register_from',''),
  1187. 'gender' => $gender
  1188. ];
  1189. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1190. if ($ret) {
  1191. $data = $this->userInfo('return');
  1192. $this->success(__('Logged in successful'), $data);
  1193. } else {
  1194. $this->error($this->auth->getError());
  1195. }
  1196. }
  1197. //注册完善资料
  1198. public function perfect_info() {
  1199. $avatar = input('avatar', '', 'trim'); //头像
  1200. $nickname = input('nickname', '', 'trim'); //昵称
  1201. $birthday = input('birthday', '', 'strtotime'); //生日
  1202. $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
  1203. $job_id = input('job_id', '', 'trim'); //职业id
  1204. $character_id = input('character_id', '', 'trim'); //性格id
  1205. $introcode = input('introcode', '', 'trim'); //邀请码
  1206. $data = [];
  1207. if ($avatar) {
  1208. $data['avatar'] = $avatar;
  1209. }
  1210. if ($nickname !== '') {
  1211. if (iconv_strlen($nickname, 'utf-8') > 10) {
  1212. $this->error('昵称最多10个字~');
  1213. }
  1214. $data['nickname'] = $nickname;
  1215. }
  1216. if ($birthday) {
  1217. $data['birthday'] = $birthday;
  1218. }
  1219. if ($hometown_cityid) {
  1220. $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
  1221. if (!$count) {
  1222. $this->error('城市不存在');
  1223. }
  1224. $data['hometown_cityid'] = $hometown_cityid;
  1225. }
  1226. if ($job_id) {
  1227. $count = Db::name('enum_job')->where('id', $job_id)->count('id');
  1228. if (!$count) {
  1229. $this->error('职业不存在');
  1230. }
  1231. $data['job_id'] = $job_id;
  1232. }
  1233. if ($character_id) {
  1234. $count = Db::name('enum_character')->where('id', $character_id)->count('id');
  1235. if (!$count) {
  1236. $this->error('性格不存在');
  1237. }
  1238. $data['character_id'] = $character_id;
  1239. }
  1240. if ($introcode && !$this->auth->intro_uid) {
  1241. /*if ($this->auth->intro_uid) {
  1242. $this->error('您已经填写过邀请人啦');
  1243. }
  1244. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1245. if(!$intro_user){
  1246. $this->error('不存在的邀请人');
  1247. }
  1248. if ($intro_user['id'] == $this->auth->id) {
  1249. $this->error('不能填写自己邀请码');
  1250. }
  1251. if ($intro_user['intro_uid'] == $this->auth->id) {
  1252. $this->error('不能填写下级邀请码');
  1253. }
  1254. $data['intro_uid'] = $intro_user['id'];
  1255. $data['invite_time'] = time();*/
  1256. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1257. if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
  1258. $data['intro_uid'] = $intro_user['id'];
  1259. $data['invite_time'] = time();
  1260. }
  1261. }
  1262. // if (!$data) {
  1263. // $this->error('请输入要修改的信息');
  1264. // }
  1265. //开启事务
  1266. Db::startTrans();
  1267. $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
  1268. if($update_rs === false){
  1269. Db::rollback();
  1270. $this->error('修改失败');
  1271. }
  1272. /*if (isset($data['intro_uid'])) { //邀请人获得金币
  1273. $intro_gold = config('site.intro_gold');
  1274. if ($intro_gold > 0) {
  1275. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],$this->auth->id,'gold',$intro_gold,64,'邀请注册奖励','user', $this->auth->id);
  1276. if($wallet_rs['status'] === false){
  1277. Db::rollback();
  1278. $this->error($wallet_rs['msg']);
  1279. }
  1280. }
  1281. }*/
  1282. //上传头像加5金币
  1283. if(isset($data['avatar'])){
  1284. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  1285. if($task_rs === false){
  1286. Db::rollback();
  1287. $this->error('完成任务赠送奖励失败');
  1288. }
  1289. }
  1290. if (isset($data['birthday'])) {
  1291. //完成设置生日 +5金币
  1292. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  1293. if($task_rs === false){
  1294. Db::rollback();
  1295. $this->error('完成任务赠送奖励失败');
  1296. }
  1297. }
  1298. Db::commit();
  1299. $this->success('修改成功');
  1300. }
  1301. //实名认证
  1302. public function idcard_auth() {
  1303. $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
  1304. // if ($info && $info['status'] == 0) {
  1305. // $this->error('您已经提交信息了,请进行人脸认证!');
  1306. // }
  1307. if ($info && $info['status'] == 1) {
  1308. $this->error('您已通过审核!');
  1309. }
  1310. $nickname = input('nickname', '', 'trim'); // 姓名
  1311. $idcard = input('idcard', '', 'trim'); // 身份证号
  1312. if ($nickname === '') {
  1313. $this->error('请输入姓名');
  1314. }
  1315. if (iconv_strlen($nickname, 'utf-8') > 50) {
  1316. $this->error('请输入正确姓名');
  1317. }
  1318. if ($idcard === '') {
  1319. $this->error('请输入身份证号');
  1320. }
  1321. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1322. $this->error('请输入正确身份证号');
  1323. }
  1324. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  1325. if ($count) {
  1326. $this->error('身份证号已存在');
  1327. }
  1328. $data = [];
  1329. $data['truename'] = $nickname;
  1330. $data['idcard'] = $idcard;
  1331. //腾讯云身份证二要素认证
  1332. $auth_restult = $this->userauth_tencent($idcard, $nickname);
  1333. if ($auth_restult) {
  1334. $data['status'] = 1; //通过
  1335. $msg = '认证通过';
  1336. } else {
  1337. $data['status'] = 2; //不通过
  1338. $msg = '认证不通过';
  1339. }
  1340. //开启事务
  1341. Db::startTrans();
  1342. if (!$info) { //未认证
  1343. $data["user_id"] = $this->auth->id;
  1344. $data["createtime"] = time();
  1345. $res = Db::name('user_idconfirm')->insertGetId($data);
  1346. } else { //认证被拒绝过
  1347. $data['updatetime'] = time();
  1348. $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
  1349. }
  1350. if (!$res) {
  1351. Db::rollback();
  1352. $this->error('认证失败');
  1353. }
  1354. $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
  1355. if ($rt === false) {
  1356. Db::rollback();
  1357. $this->error('认证失败');
  1358. }
  1359. if ($data['status'] == 1) {
  1360. //完成实名认证 +20金币
  1361. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
  1362. if($task_rs === false){
  1363. Db::rollback();
  1364. $this->error('完成任务赠送奖励失败');
  1365. }
  1366. //系统消息
  1367. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  1368. } else {
  1369. //系统消息
  1370. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
  1371. }
  1372. Db::commit();
  1373. $this->success($msg);
  1374. }
  1375. //腾讯云身份证二要素认证
  1376. public function userauth_tencent($idcard = '', $nickname = '') {
  1377. // require_once 'vendor/autoload.php';
  1378. try {
  1379. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1380. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1381. $config = config('tencent_im');
  1382. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1383. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1384. $httpProfile = new HttpProfile();
  1385. $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
  1386. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1387. $clientProfile = new ClientProfile();
  1388. $clientProfile->setHttpProfile($httpProfile);
  1389. // 实例化要请求产品的client对象,clientProfile是可选的
  1390. $client = new FaceidClient($cred, "", $clientProfile);
  1391. // 实例化一个请求对象,每个接口都会对应一个request对象
  1392. $req = new IdCardVerificationRequest();
  1393. $params = array(
  1394. "IdCard" => $idcard,
  1395. "Name" => $nickname
  1396. );
  1397. $req->fromJsonString(json_encode($params));
  1398. // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
  1399. $resp = $client->IdCardVerification($req);
  1400. // 输出json格式的字符串回包
  1401. // print_r($resp->toJsonString());
  1402. $result = json_decode($resp->toJsonString(), true);
  1403. if (isset($result['Result']) && $result['Result'] == 0) {
  1404. return 1; //通过
  1405. } else {
  1406. return 0;
  1407. }
  1408. }
  1409. catch(TencentCloudSDKException $e) {
  1410. // echo $e;
  1411. return 0;
  1412. }
  1413. }
  1414. //绑定支付宝
  1415. public function addalipayaccount() {
  1416. $id = input('id', 0, 'intval'); //账号id
  1417. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1418. // $type = 1;
  1419. $realname = input('realname', '', 'trim'); //账户真实姓名
  1420. $banknumber = input('banknumber', '', 'trim'); //卡号或账号
  1421. $bankname = input('bankname', '', 'trim'); //银行名称
  1422. // if ($id) {
  1423. // $this->error('您已经拥有该类型账号,请联系后台解绑');
  1424. // }
  1425. if (!in_array($type, [1, 2])) {
  1426. $this->error('参数错误');
  1427. }
  1428. /*if ($type == 1) {
  1429. $this->error('暂不支持绑定支付宝');
  1430. }*/
  1431. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1432. $this->error('账号姓名1-30位');
  1433. }
  1434. if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
  1435. $this->error('账号1-50位');
  1436. }
  1437. if ($type == 1) {
  1438. if (iconv_strlen($bankname, 'utf-8') != 18) {
  1439. $this->error('请输入正确身份证号');
  1440. }
  1441. }
  1442. if ($type == 2) {
  1443. if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
  1444. $this->error('开户行名称1-50位');
  1445. }
  1446. }
  1447. $user_bank = Db::name('user_bank');
  1448. if ($id) {
  1449. //编辑
  1450. //查询账号是否存在
  1451. $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1452. if (!$info) {
  1453. $this->error('账号不存在');
  1454. }
  1455. if ($info['type'] != $type) {
  1456. $this->error('账号类型错误');
  1457. }
  1458. //查询是否未通过提现记录
  1459. $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
  1460. if ($count) {
  1461. $this->error('该账户有未审核的提现记录,暂不可修改');
  1462. }
  1463. $data['realname'] = $realname;
  1464. $data['banknumber'] = $banknumber;
  1465. $data['updatetime'] = time();
  1466. // if ($type == 2) {
  1467. $data['bankname'] = $bankname;
  1468. // }
  1469. $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
  1470. if ($rs === false) {
  1471. $this->error('修改失败');
  1472. }
  1473. $this->success('修改成功');
  1474. } else {
  1475. //添加
  1476. //查询是否已经拥有该类型账号
  1477. $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1478. if ($count) {
  1479. $this->error('您已经拥有该类型账号,请联系后台解绑');
  1480. }
  1481. $data['user_id'] = $this->auth->id;
  1482. $data['type'] = $type;
  1483. $data['realname'] = $realname;
  1484. $data['banknumber'] = $banknumber;
  1485. // if ($type == 2) {
  1486. $data['bankname'] = $bankname;
  1487. // }
  1488. $data['createtime'] = time();
  1489. $rs = $user_bank->insertGetId($data);
  1490. if (!$rs) {
  1491. $this->error('添加失败');
  1492. }
  1493. $this->success('添加成功');
  1494. }
  1495. }
  1496. //查询支付宝/银行卡信息
  1497. public function alipayinfo() {
  1498. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1499. $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  1500. if (!$info) {
  1501. $info = (object)[];
  1502. }
  1503. $this->success('success', $info);
  1504. }
  1505. //申请真人认证
  1506. public function realauth() {
  1507. if ($this->auth->real_status == 1) {
  1508. $this->error('您已经真人认证过了~');
  1509. }
  1510. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  1511. $this->error('请先上传真人头像~');
  1512. }
  1513. //获取token
  1514. $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';
  1515. $token_result = file_get_contents($token_url);
  1516. if (!$token_result) {
  1517. $this->error('您的网络开小差啦1~');
  1518. }
  1519. $token_result = json_decode($token_result, true);
  1520. if ($token_result['code'] != 0) {
  1521. $this->error('您的网络开小差啦2~');
  1522. }
  1523. $token = $token_result['access_token'];
  1524. //获取签名鉴权参数ticket
  1525. $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';
  1526. $ticket_result = file_get_contents($ticket_url);
  1527. if (!$ticket_result) {
  1528. $this->error('您的网络开小差啦3~');
  1529. }
  1530. $ticket_result = json_decode($ticket_result, true);
  1531. if ($ticket_result['code'] != 0) {
  1532. $this->error('您的网络开小差啦4~');
  1533. }
  1534. $ticket = $ticket_result['tickets'][0]['value'];
  1535. //获取签名
  1536. $sign_data = [
  1537. 'wbappid' => config('tencent_yun')['secret_id'],
  1538. 'userId' => (string)$this->auth->id,
  1539. 'version' => '1.0.0',
  1540. 'ticket' => $ticket,
  1541. 'nonce' => Random::alnum(32)
  1542. ];//p($sign_data);
  1543. asort($sign_data); //p($sign_data);//排序
  1544. $sign_string = join('', $sign_data);//p($sign_string);
  1545. $sign = sha1($sign_string);//p($sign);
  1546. //上传身份信息
  1547. $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
  1548. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  1549. $avatar = one_domain_image($this->auth->avatar);
  1550. $avatar = str_replace('https', 'http', $avatar);
  1551. $img = file_get_contents($avatar);
  1552. $img = str_replace('data:image/jpg;base64', '', $img);
  1553. $img = str_replace('\n', '', $img);
  1554. $sourcePhotoStr = base64_encode($img);
  1555. $data = [
  1556. 'webankAppId' => config('tencent_yun')['secret_id'],
  1557. 'orderNo' => $orderNo,
  1558. 'userId' => (string)$this->auth->id,
  1559. 'sourcePhotoStr' => $sourcePhotoStr,
  1560. 'sourcePhotoType' => 2,
  1561. 'version' => '1.0.0',
  1562. 'sign' => $sign,
  1563. 'nonce' => $sign_data['nonce']
  1564. ];
  1565. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1566. if (!$rs) {
  1567. $this->error('您的网络开小差啦5~');
  1568. }
  1569. $rs = json_decode($rs, true);
  1570. if (!$rs || $rs['code'] != 0) {
  1571. $this->error('您的网络开小差啦6~');
  1572. }
  1573. $user_auth = [
  1574. 'user_id' => $this->auth->id,
  1575. 'certify_id' => $rs['result']['faceId'],
  1576. 'out_trade_no' => $data['orderNo'],
  1577. 'status' => 0,
  1578. 'createtime' => time(),
  1579. 'updatetime' => time()
  1580. ];
  1581. //开启事务
  1582. Db::startTrans();
  1583. //查询是否认证过
  1584. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1585. if ($info) {
  1586. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  1587. } else {
  1588. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  1589. }
  1590. if (!$auth_rs) {
  1591. Db::rollback();
  1592. $this->error('您的网络开小差啦7~');
  1593. }
  1594. //修改用户表认证状态
  1595. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  1596. if ($user_rs === false) {
  1597. Db::rollback();
  1598. $this->error('您的网络开小差啦8~');
  1599. }
  1600. Db::commit();
  1601. $return_data = [
  1602. 'face_id' => $user_auth['certify_id'],
  1603. 'order_no' => $user_auth['out_trade_no'],
  1604. 'user_id' => (string)$this->auth->id,
  1605. 'nonce' => $sign_data['nonce'],
  1606. 'sign' => $sign
  1607. ];
  1608. $this->success('success', $return_data);
  1609. }
  1610. //查询真人认证结果
  1611. public function getrealauthresult() {
  1612. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1613. if (!$user_auth) {
  1614. $this->success('尚未认证');
  1615. }
  1616. if ($user_auth['status'] == 1) {
  1617. $this->success('真人认证通过');
  1618. }
  1619. if (!$user_auth['certify_id']) {
  1620. $this->success('请先进行真人认证');
  1621. }
  1622. //获取token
  1623. $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';
  1624. $token_result = file_get_contents($token_url);
  1625. if (!$token_result) {
  1626. $this->error('您的网络开小差啦1~');
  1627. }
  1628. $token_result = json_decode($token_result, true);
  1629. if ($token_result['code'] != 0) {
  1630. $this->error('您的网络开小差啦2~');
  1631. }
  1632. $token = $token_result['access_token'];
  1633. //获取签名鉴权参数ticket
  1634. $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';
  1635. $ticket_result = file_get_contents($ticket_url);
  1636. if (!$ticket_result) {
  1637. $this->error('您的网络开小差啦3~');
  1638. }
  1639. $ticket_result = json_decode($ticket_result, true);
  1640. if ($ticket_result['code'] != 0) {
  1641. $this->error('您的网络开小差啦4~');
  1642. }
  1643. $ticket = $ticket_result['tickets'][0]['value'];
  1644. //获取签名
  1645. $sign_data = [
  1646. 'wbappid' => config('tencent_yun')['secret_id'],
  1647. 'orderNo' => $user_auth['out_trade_no'],
  1648. 'version' => '1.0.0',
  1649. 'ticket' => $ticket,
  1650. 'nonce' => Random::alnum(32)
  1651. ];//p($sign_data);
  1652. asort($sign_data); //p($sign_data);//排序
  1653. $sign_string = join('', $sign_data);//p($sign_string);
  1654. $sign = sha1($sign_string);//p($sign);
  1655. //人脸核身结果查询
  1656. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1657. $data = [
  1658. 'appId' => config('tencent_yun')['secret_id'],
  1659. 'version' => '1.0.0',
  1660. 'nonce' => $sign_data['nonce'],
  1661. 'orderNo' => $user_auth['out_trade_no'],
  1662. 'sign' => $sign
  1663. ];
  1664. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1665. if (!$rs) {
  1666. $this->error('您的网络开小差啦5~');
  1667. }
  1668. $rs = json_decode($rs, true);
  1669. if (!$rs || $rs['code'] != 0) {
  1670. $this->error($rs['msg']);
  1671. }
  1672. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1673. $edit_data['status'] = 1;
  1674. $msg = '真人认证成功';
  1675. } else {
  1676. $edit_data['status'] = 2;
  1677. $edit_data['certify_id'] = '';
  1678. $edit_data['out_trade_no'] = '';
  1679. $msg = '真人认证失败';
  1680. }
  1681. $edit_data['updatetime'] = time();
  1682. //开启事务
  1683. Db::startTrans();
  1684. //修改认证信息
  1685. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1686. if (!$result) {
  1687. Db::rollback();
  1688. $this->error('查询认证结果失败2');
  1689. }
  1690. //修改用户信息
  1691. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  1692. if (!$rs) {
  1693. Db::rollback();
  1694. $this->error('查询认证结果失败3');
  1695. }
  1696. if ($edit_data['status'] == 1) { //通过
  1697. //tag任务赠送金币
  1698. //真人认证奖励
  1699. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1700. if($task_rs === false){
  1701. Db::rollback();
  1702. $this->error('完成任务赠送奖励失败');
  1703. }
  1704. //系统消息
  1705. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1706. } else {
  1707. //系统消息
  1708. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1709. }
  1710. Db::commit();
  1711. $this->success($msg);
  1712. }
  1713. //客服
  1714. public function kefu() {
  1715. $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
  1716. if (!in_array($type, [0, 1])) {
  1717. $this->error('您的网络开小差啦~');
  1718. }
  1719. if ($type == 0) {
  1720. $user_id = config('site.customer_service_id') ? : 0; //指定客服id
  1721. } else {
  1722. $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
  1723. }
  1724. $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
  1725. if (!$list) {
  1726. $this->success('success', $list);
  1727. }
  1728. foreach ($list as $k => &$v) {
  1729. $v['nickname'] = '客服' . ($k + 1);
  1730. $v['avatar'] = config('avatar_girl');
  1731. }
  1732. $this->success('success', $list);
  1733. }
  1734. //海报背景图
  1735. public function posterlist() {
  1736. $list = config('site.intro_images');
  1737. if (!$list) {
  1738. $this->success('success', (object)[]);
  1739. }
  1740. foreach ($list as &$v) {
  1741. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  1742. }
  1743. $this->success('success', $list);
  1744. }
  1745. //生成海报
  1746. public function createposter($image = '') {
  1747. // $image = input('image', '', 'trim');
  1748. // if (!$image) {
  1749. // $this->error('您的网络开小差啦~');
  1750. // }
  1751. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  1752. return $haibao;
  1753. // $this->success('success', $haibao);
  1754. }
  1755. //注册设置性别
  1756. public function setgender() {
  1757. $user_id = $this->auth->id;
  1758. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1759. if (!in_array($gender, [1, 0])) {
  1760. $this->error('性别错误');
  1761. }
  1762. $edit_data['gender'] = $gender;
  1763. $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
  1764. $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
  1765. if (!$rs) {
  1766. $this->error('您的网络开小差啦~');
  1767. }
  1768. $data = $this->userInfo('return');
  1769. $data['gender'] = $edit_data['gender'];
  1770. $data['avatar'] = $edit_data['avatar'];
  1771. // $this->success('success', $data);
  1772. // 如果是女用户,则停止账户使用
  1773. /*if ($gender == 0){
  1774. Db::name('user')->where('id',$user_id)->update(['status'=>0,'is_closed'=>1]);//金庸
  1775. Db::name('user_token')->where('user_id',$user_id)->delete();//金庸
  1776. }*/
  1777. //领取任务奖励
  1778. $task_id = 22; // 任务ID
  1779. // 查询任务信息
  1780. $taskInfo = $this->taskModel->where(["id"=>$task_id])->find();
  1781. if(!$taskInfo) {
  1782. // $this->error("任务信息未找到!");
  1783. $this->success('success', $data);
  1784. }
  1785. // 查询用户完成情况
  1786. $where = [];
  1787. $where["user_id"] = $user_id;
  1788. $where["task_id"] = $task_id;
  1789. $where["is_finish"] = 1;
  1790. if($taskInfo["type_id"] == 2){
  1791. $where["finish_date"] = date("Ymd");
  1792. }
  1793. $tasklogInfo = $this->tasklogModel->where($where)->find();
  1794. if(!$tasklogInfo) {
  1795. // $this->error("任务还未完成哦!");
  1796. $this->success('success', $data);
  1797. }
  1798. if($tasklogInfo["is_reward"] == 1) {
  1799. // $this->error("任务奖励已领取,请勿重复领取!");
  1800. $this->success('success', $data);
  1801. }
  1802. Db::startTrans();
  1803. // 增加用户经验值
  1804. //$res1 = \app\common\model\User::addEmpirical($user_id,$taskInfo["exp"]);
  1805. $res1['status'] = true;
  1806. if ($gender == 1) {
  1807. //男用户获得金币
  1808. $res1 = model('wallet')->lockChangeAccountRemain($user_id,0, 'gold', $taskInfo["exp"], 61, '完成' . $taskInfo['name'] . '任务', 'task_log', $tasklogInfo['id']);
  1809. if ($res1['status'] === false) {
  1810. Db::rollback();
  1811. // $this->error($res1['msg']);
  1812. $this->success('success', $data);
  1813. }
  1814. } elseif ($gender == 0) {
  1815. $bili = config('site.money_to_gold'); //钱和金币兑换比例
  1816. if ($bili > 0) {
  1817. //女用户获得钱
  1818. $money = bcdiv($taskInfo['exp'], $bili, 2);
  1819. if ($money > 0) {
  1820. $res1 = model('wallet')->lockChangeAccountRemain($user_id,0, 'money', $money, 67, '完成' .$taskInfo['name'] . '任务', 'task_log', $tasklogInfo['id']);
  1821. if ($res1['status'] === false) {
  1822. Db::rollback();
  1823. // $this->error($res1['msg']);
  1824. $this->success('success', $data);
  1825. }
  1826. }
  1827. }
  1828. }
  1829. // 更新奖励领取状态
  1830. $res2 = $this->tasklogModel->update(["is_reward"=>1],["task_id"=>$task_id,"user_id"=>$user_id]);
  1831. //系统消息
  1832. $msg_id = \app\common\model\Message::addMessage($user_id,'任务奖励','完成' . $taskInfo['name'] . '任务,获得任务奖励');
  1833. if($res1['status'] === true && $res2) {
  1834. Db::commit();
  1835. // $this->success("领取成功!");
  1836. $this->success('success', $data);
  1837. } else {
  1838. Db::rollback();
  1839. // $this->error("领取失败!");
  1840. $this->success('success', $data);
  1841. }
  1842. }
  1843. //真人认证后修改头像前比对
  1844. public function realavatar_auit() {
  1845. if ($this->auth->real_status != 1) {
  1846. $this->error('尚未通过真人认证');
  1847. }
  1848. $avatar = input('avatar', '', 'trim'); //头像地址
  1849. if ($avatar === '') {
  1850. $this->error('参数缺失');
  1851. }
  1852. $avatar = one_domain_image($avatar);
  1853. $now_avatar = one_domain_image($this->auth->avatar);
  1854. if ($avatar == $now_avatar) {
  1855. $this->error('头像未改变');
  1856. }
  1857. //腾讯云人脸识别
  1858. $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1859. $this->success('结果', $result);
  1860. }
  1861. //真人认证后修改头像
  1862. public function editrealavatar() {
  1863. if ($this->auth->real_status != 1) {
  1864. $this->error('尚未通过真人认证');
  1865. }
  1866. $avatar = input('avatar', '', 'trim'); //头像地址
  1867. if ($avatar === '') {
  1868. $this->error('参数缺失');
  1869. }
  1870. $avatar = one_domain_image($avatar);
  1871. $now_avatar = one_domain_image($this->auth->avatar);
  1872. if ($avatar == $now_avatar) {
  1873. $this->error('头像未改变');
  1874. }
  1875. //腾讯云人脸识别
  1876. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1877. if ($auit_result != 1) {
  1878. $this->success('提示', ['code' => 2]);
  1879. }
  1880. $data['avatar'] = $avatar;
  1881. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1882. if (!$user_result) {
  1883. $this->error('修改失败');
  1884. }
  1885. $this->success('修改成功');
  1886. }
  1887. //真人认证后修改头像并取消真人认证
  1888. public function editrealavatarcancelauit() {
  1889. if ($this->auth->real_status != 1) {
  1890. $this->error('尚未通过真人认证');
  1891. }
  1892. $avatar = input('avatar', '', 'trim'); //头像地址
  1893. if ($avatar === '') {
  1894. $this->error('参数缺失');
  1895. }
  1896. $avatar = one_domain_image($avatar);
  1897. $now_avatar = one_domain_image($this->auth->avatar);
  1898. if ($avatar == $now_avatar) {
  1899. $this->error('头像未改变');
  1900. }
  1901. $data['avatar'] = $avatar;
  1902. $data['real_status'] = -1;
  1903. //开启事务
  1904. Db::startTrans();
  1905. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1906. if (!$user_result) {
  1907. Db::rollback();
  1908. $this->error('修改失败');
  1909. }
  1910. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  1911. if (!$user_auth_result) {
  1912. Db::rollback();
  1913. $this->error('修改失败');
  1914. }
  1915. Db::commit();
  1916. $this->success('修改成功');
  1917. }
  1918. //腾讯云人脸识别
  1919. public function face_tencent($urla = '', $urlb = '') {
  1920. // require_once 'vendor/autoload.php';
  1921. try {
  1922. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1923. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1924. $config = config('tencent_im');
  1925. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1926. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1927. $httpProfile = new HttpProfile();
  1928. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  1929. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1930. $clientProfile = new ClientProfile();
  1931. $clientProfile->setHttpProfile($httpProfile);
  1932. // 实例化要请求产品的client对象,clientProfile是可选的
  1933. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  1934. // 实例化一个请求对象,每个接口都会对应一个request对象
  1935. $req = new CompareFaceRequest();
  1936. $params = array(
  1937. "UrlA" => $urla,
  1938. "UrlB" => $urlb,
  1939. "FaceModelVersion" => "3.0"
  1940. );
  1941. $req->fromJsonString(json_encode($params));
  1942. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  1943. $resp = $client->CompareFace($req);
  1944. // 输出json格式的字符串回包
  1945. // print_r($resp->toJsonString());
  1946. $result = json_decode($resp->toJsonString(), true);
  1947. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  1948. if (isset($result['Score']) && $result['Score'] >= 60) {
  1949. return 1; //通过
  1950. } else {
  1951. return 0;
  1952. }
  1953. }
  1954. catch(TencentCloudSDKException $e) {
  1955. // echo $e;
  1956. return 0;
  1957. }
  1958. }
  1959. //修改城市
  1960. public function editcity() {
  1961. $name = input('name', '', 'trim'); //城市名
  1962. if ($name === '') {
  1963. $this->error('参数缺失');
  1964. }
  1965. $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
  1966. if (!$hometown_cityid) {
  1967. $this->success('修改成功');
  1968. }
  1969. Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
  1970. $this->success('修改成功');
  1971. }
  1972. //搜索用户
  1973. public function searchuser() {
  1974. $keyword = input('keyword', '', 'trim'); //昵称或ID
  1975. if ($keyword === '') {
  1976. $this->error('请输入关键字');
  1977. }
  1978. $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
  1979. $id = $id ? : 0;
  1980. $this->success('用户', $id);
  1981. }
  1982. //绑定支付宝账号信息
  1983. public function bindalipayaccount() {
  1984. $mt_user_bank = Db::name('user_bank');
  1985. $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
  1986. if ($count) {
  1987. $this->error('您已绑定支付宝啦');
  1988. }
  1989. $auth_code = input('auth_code', '', 'trim');
  1990. if (!$auth_code) {
  1991. $this->error('授权码缺失');
  1992. }
  1993. //获取支付宝用户信息
  1994. $rs = getAlipayInfo($auth_code);
  1995. if ($rs['status'] == 0) {
  1996. $this->error($rs['info']);
  1997. }
  1998. $rs = $rs['data'];
  1999. /*
  2000. * Array(
  2001. [alipay_user_info_share_response] => Array
  2002. (
  2003. [code] => 10000
  2004. [msg] => Success
  2005. [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
  2006. [city] => 临沂市 市名称。
  2007. [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
  2008. [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
  2009. [is_student_certified] => F 是否是学生 T是 F否
  2010. [nick_name] => 风的追求 用户昵称
  2011. [province] => 山东省 省份名称
  2012. [user_id] => 2088902918001020 支付宝用户的userId
  2013. [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
  2014. [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
  2015. )
  2016. )
  2017. */
  2018. $data['banknumber'] = $rs['user_id']; //支付宝用户id
  2019. if (!$data['banknumber']) {
  2020. $this->error('获取用户信息失败');
  2021. }
  2022. $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
  2023. if ($bank_number_count) {
  2024. $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
  2025. }
  2026. if (isset($rs['nick_name'])) {
  2027. $data['realname'] = $rs['nick_name']; //支付宝用户昵称
  2028. }
  2029. $data['user_id'] = $this->auth->id;
  2030. $data['createtime'] = time();
  2031. $data['type'] = 1;
  2032. $rt = $mt_user_bank->insertGetId($data);
  2033. if (!$rt) {
  2034. $this->error('绑定失败');
  2035. }
  2036. $this->success('绑定成功');
  2037. }
  2038. //添加打招呼内容,女性使用
  2039. public function addgreetcontent() {
  2040. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  2041. $title = input('title', '', 'trim'); //标题(type=1必传)
  2042. $content = input('content', '', 'trim'); //内容
  2043. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  2044. if (!in_array($type, [0, 1, 2])) {
  2045. $this->error('您的网络开小差了');
  2046. }
  2047. if ($content === '') {
  2048. $this->error('请设置打招呼内容');
  2049. }
  2050. if (iconv_strlen($content, 'utf-8') > 255) {
  2051. $this->error('打招呼内容最多255位');
  2052. }
  2053. if ($type == 1) {
  2054. if ($title === '') {
  2055. $this->error('请输入语音名称');
  2056. }
  2057. if (iconv_strlen($title, 'utf-8') > 50) {
  2058. $this->error('语音名称最多50字');
  2059. }
  2060. if (!$duration) {
  2061. $this->error('参数缺失');
  2062. }
  2063. }
  2064. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  2065. if ($count > 10) {
  2066. $this->error('同一类型打招呼最多设置10条');
  2067. }
  2068. $data['user_id'] = $this->auth->id;
  2069. $data['type'] = $type;
  2070. $data['content'] = $content;
  2071. if ($type == 1) {
  2072. $data['title'] = $title;
  2073. $data['duration'] = $duration;
  2074. }
  2075. $data['createtime'] = time();
  2076. //查询是否有默认打招呼内容
  2077. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  2078. if (!$default_greet_count) {
  2079. $data['is_default'] = 1;
  2080. }
  2081. $rs = Db::name('user_greet_content')->insertGetId($data);
  2082. if (!$rs) {
  2083. $this->error('您的网络开小差了');
  2084. }
  2085. $this->success('设置成功');
  2086. }
  2087. //查询打招呼内容,女性使用
  2088. public function getgreetcontent() {
  2089. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  2090. if (!in_array($type, [0, 1, 2, 3])) {
  2091. $this->error('您的网络开小差了');
  2092. }
  2093. if ($type == 3) {
  2094. $list = Db::name('user_greet_content')->where(function ($query) {
  2095. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  2096. })->whereOr(function ($query) {
  2097. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  2098. })->select();
  2099. } else {
  2100. $where['user_id'] = $this->auth->id;
  2101. $where['type'] = $type;
  2102. $list = Db::name('user_greet_content')->where($where)->select();
  2103. }
  2104. if ($list) {
  2105. foreach ($list as &$v) {
  2106. if ($v['type'] != 0) {
  2107. $v['content'] = one_domain_image($v['content']);
  2108. }
  2109. }
  2110. }
  2111. $this->success('打招呼内容', $list);
  2112. }
  2113. //设置默认打招呼内容,女性使用
  2114. public function setdefaultgreet() {
  2115. $id = input('id', 0, 'intval'); //打招呼id
  2116. if (!$id) {
  2117. $this->error('您的网络开小差了');
  2118. }
  2119. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  2120. if (!$count) {
  2121. $this->error('您的网络开小差了');
  2122. }
  2123. //开启事务
  2124. Db::startTrans();
  2125. //清除之前默认
  2126. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  2127. if ($rs === false) {
  2128. Db::rollback();
  2129. $this->error('您的网络开小差了');
  2130. }
  2131. //设置
  2132. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  2133. if ($rt === false) {
  2134. Db::rollback();
  2135. $this->error('您的网络开小差了');
  2136. }
  2137. Db::commit();
  2138. $this->success('设置成功');
  2139. }
  2140. //删除打招呼内容,女性使用
  2141. public function deldefaultgreet() {
  2142. $id = input('id', 0, 'intval'); //打招呼id
  2143. if (!$id) {
  2144. $this->error('您的网络开小差了');
  2145. }
  2146. $mt_user_greet_content = Db::name('user_greet_content');
  2147. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  2148. if (!$info) {
  2149. $this->error('您的网络开小差了');
  2150. }
  2151. //开启事务
  2152. Db::startTrans();
  2153. //删除
  2154. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  2155. if ($rs === false) {
  2156. Db::rollback();
  2157. $this->error('您的网络开小差了');
  2158. }
  2159. //若为默认打招呼内容则重新设置一条
  2160. if ($info['is_default'] == 1) {
  2161. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  2162. if ($first_greet) {
  2163. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  2164. if ($rt === false) {
  2165. Db::rollback();
  2166. $this->error('您的网络开小差了');
  2167. }
  2168. }
  2169. }
  2170. Db::commit();
  2171. $this->success('删除成功');
  2172. }
  2173. }