User.php 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437
  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. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 1,'active_time' => time()]);
  1120. $this->success('success');
  1121. }
  1122. //公众号获取openid
  1123. public function getUserOpenid_gzh(){
  1124. $configValue = Service::getConfig('wechat');
  1125. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1126. $rs = $wechat->getOpenid();
  1127. $this->success('success',$rs);
  1128. }
  1129. /**
  1130. * 微信内H5-JSAPI支付
  1131. */
  1132. public function jssdkBuildConfig() {
  1133. $url = $this->request->request("url");
  1134. $configValue = Service::getConfig('wechat');
  1135. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1136. $sign = $wechat->getSignPackage(urldecode($url));
  1137. $this->success("获取成功!",$sign);
  1138. }
  1139. //苹果账号登录
  1140. public function ioslogin(){
  1141. $ios_openid = input('ios_openid','');
  1142. if (!$ios_openid) {
  1143. $this->error(__('Invalid parameters'));
  1144. }
  1145. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1146. /*if (!$user) {
  1147. $this->success('选择性别', ['code' => 5]);
  1148. }*/
  1149. if ($user) {
  1150. if (!in_array($user->status,[1,2])) {
  1151. $this->error(__('Account is locked'));
  1152. }
  1153. if ($user->frozentime > time()) {
  1154. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  1155. }
  1156. //如果已经有账号则直接登录
  1157. $ret = $this->auth->direct($user->id);
  1158. } else {
  1159. $reg_data = [
  1160. 'register_from' => input('register_from',''),
  1161. 'gender' => -1
  1162. ];
  1163. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1164. }
  1165. if ($ret) {
  1166. $data = $this->userInfo('return');
  1167. $this->success(__('Logged in successful'), $data);
  1168. } else {
  1169. $this->error($this->auth->getError());
  1170. }
  1171. }
  1172. //苹果账号注册
  1173. public function iosregiter(){
  1174. $ios_openid = input('ios_openid', '', 'trim');
  1175. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1176. if (!$ios_openid) {
  1177. $this->error(__('Invalid parameters'));
  1178. }
  1179. if (!in_array($gender, [1, 0])) {
  1180. $this->error('性别错误');
  1181. }
  1182. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1183. if ($user) {
  1184. $this->error('账号已经存在,请直接登录');
  1185. }
  1186. $reg_data = [
  1187. 'register_from' => input('register_from',''),
  1188. 'gender' => $gender
  1189. ];
  1190. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1191. if ($ret) {
  1192. $data = $this->userInfo('return');
  1193. $this->success(__('Logged in successful'), $data);
  1194. } else {
  1195. $this->error($this->auth->getError());
  1196. }
  1197. }
  1198. //注册完善资料
  1199. public function perfect_info() {
  1200. $avatar = input('avatar', '', 'trim'); //头像
  1201. $nickname = input('nickname', '', 'trim'); //昵称
  1202. $birthday = input('birthday', '', 'strtotime'); //生日
  1203. $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
  1204. $job_id = input('job_id', '', 'trim'); //职业id
  1205. $character_id = input('character_id', '', 'trim'); //性格id
  1206. $introcode = input('introcode', '', 'trim'); //邀请码
  1207. $data = [];
  1208. if ($avatar) {
  1209. $data['avatar'] = $avatar;
  1210. }
  1211. if ($nickname !== '') {
  1212. if (iconv_strlen($nickname, 'utf-8') > 10) {
  1213. $this->error('昵称最多10个字~');
  1214. }
  1215. $data['nickname'] = $nickname;
  1216. }
  1217. if ($birthday) {
  1218. $data['birthday'] = $birthday;
  1219. }
  1220. if ($hometown_cityid) {
  1221. $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
  1222. if (!$count) {
  1223. $this->error('城市不存在');
  1224. }
  1225. $data['hometown_cityid'] = $hometown_cityid;
  1226. }
  1227. if ($job_id) {
  1228. $count = Db::name('enum_job')->where('id', $job_id)->count('id');
  1229. if (!$count) {
  1230. $this->error('职业不存在');
  1231. }
  1232. $data['job_id'] = $job_id;
  1233. }
  1234. if ($character_id) {
  1235. $count = Db::name('enum_character')->where('id', $character_id)->count('id');
  1236. if (!$count) {
  1237. $this->error('性格不存在');
  1238. }
  1239. $data['character_id'] = $character_id;
  1240. }
  1241. if ($introcode && !$this->auth->intro_uid) {
  1242. /*if ($this->auth->intro_uid) {
  1243. $this->error('您已经填写过邀请人啦');
  1244. }
  1245. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1246. if(!$intro_user){
  1247. $this->error('不存在的邀请人');
  1248. }
  1249. if ($intro_user['id'] == $this->auth->id) {
  1250. $this->error('不能填写自己邀请码');
  1251. }
  1252. if ($intro_user['intro_uid'] == $this->auth->id) {
  1253. $this->error('不能填写下级邀请码');
  1254. }
  1255. $data['intro_uid'] = $intro_user['id'];
  1256. $data['invite_time'] = time();*/
  1257. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1258. if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
  1259. $data['intro_uid'] = $intro_user['id'];
  1260. $data['invite_time'] = time();
  1261. }
  1262. }
  1263. // if (!$data) {
  1264. // $this->error('请输入要修改的信息');
  1265. // }
  1266. //开启事务
  1267. Db::startTrans();
  1268. $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
  1269. if($update_rs === false){
  1270. Db::rollback();
  1271. $this->error('修改失败');
  1272. }
  1273. /*if (isset($data['intro_uid'])) { //邀请人获得金币
  1274. $intro_gold = config('site.intro_gold');
  1275. if ($intro_gold > 0) {
  1276. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],$this->auth->id,'gold',$intro_gold,64,'邀请注册奖励','user', $this->auth->id);
  1277. if($wallet_rs['status'] === false){
  1278. Db::rollback();
  1279. $this->error($wallet_rs['msg']);
  1280. }
  1281. }
  1282. }*/
  1283. //上传头像加5金币
  1284. if(isset($data['avatar'])){
  1285. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  1286. if($task_rs === false){
  1287. Db::rollback();
  1288. $this->error('完成任务赠送奖励失败');
  1289. }
  1290. }
  1291. if (isset($data['birthday'])) {
  1292. //完成设置生日 +5金币
  1293. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  1294. if($task_rs === false){
  1295. Db::rollback();
  1296. $this->error('完成任务赠送奖励失败');
  1297. }
  1298. }
  1299. Db::commit();
  1300. $this->success('修改成功');
  1301. }
  1302. //实名认证
  1303. public function idcard_auth() {
  1304. $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
  1305. // if ($info && $info['status'] == 0) {
  1306. // $this->error('您已经提交信息了,请进行人脸认证!');
  1307. // }
  1308. if ($info && $info['status'] == 1) {
  1309. $this->error('您已通过审核!');
  1310. }
  1311. $nickname = input('nickname', '', 'trim'); // 姓名
  1312. $idcard = input('idcard', '', 'trim'); // 身份证号
  1313. if ($nickname === '') {
  1314. $this->error('请输入姓名');
  1315. }
  1316. if (iconv_strlen($nickname, 'utf-8') > 50) {
  1317. $this->error('请输入正确姓名');
  1318. }
  1319. if ($idcard === '') {
  1320. $this->error('请输入身份证号');
  1321. }
  1322. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1323. $this->error('请输入正确身份证号');
  1324. }
  1325. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  1326. if ($count) {
  1327. $this->error('身份证号已存在');
  1328. }
  1329. $data = [];
  1330. $data['truename'] = $nickname;
  1331. $data['idcard'] = $idcard;
  1332. //腾讯云身份证二要素认证
  1333. $auth_restult = $this->userauth_tencent($idcard, $nickname);
  1334. if ($auth_restult) {
  1335. $data['status'] = 1; //通过
  1336. $msg = '认证通过';
  1337. } else {
  1338. $data['status'] = 2; //不通过
  1339. $msg = '认证不通过';
  1340. }
  1341. //开启事务
  1342. Db::startTrans();
  1343. if (!$info) { //未认证
  1344. $data["user_id"] = $this->auth->id;
  1345. $data["createtime"] = time();
  1346. $res = Db::name('user_idconfirm')->insertGetId($data);
  1347. } else { //认证被拒绝过
  1348. $data['updatetime'] = time();
  1349. $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
  1350. }
  1351. if (!$res) {
  1352. Db::rollback();
  1353. $this->error('认证失败');
  1354. }
  1355. $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
  1356. if ($rt === false) {
  1357. Db::rollback();
  1358. $this->error('认证失败');
  1359. }
  1360. if ($data['status'] == 1) {
  1361. //完成实名认证 +20金币
  1362. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
  1363. if($task_rs === false){
  1364. Db::rollback();
  1365. $this->error('完成任务赠送奖励失败');
  1366. }
  1367. //系统消息
  1368. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  1369. } else {
  1370. //系统消息
  1371. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
  1372. }
  1373. Db::commit();
  1374. $this->success($msg);
  1375. }
  1376. //腾讯云身份证二要素认证
  1377. public function userauth_tencent($idcard = '', $nickname = '') {
  1378. // require_once 'vendor/autoload.php';
  1379. try {
  1380. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1381. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1382. $config = config('tencent_im');
  1383. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1384. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1385. $httpProfile = new HttpProfile();
  1386. $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
  1387. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1388. $clientProfile = new ClientProfile();
  1389. $clientProfile->setHttpProfile($httpProfile);
  1390. // 实例化要请求产品的client对象,clientProfile是可选的
  1391. $client = new FaceidClient($cred, "", $clientProfile);
  1392. // 实例化一个请求对象,每个接口都会对应一个request对象
  1393. $req = new IdCardVerificationRequest();
  1394. $params = array(
  1395. "IdCard" => $idcard,
  1396. "Name" => $nickname
  1397. );
  1398. $req->fromJsonString(json_encode($params));
  1399. // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
  1400. $resp = $client->IdCardVerification($req);
  1401. // 输出json格式的字符串回包
  1402. // print_r($resp->toJsonString());
  1403. $result = json_decode($resp->toJsonString(), true);
  1404. if (isset($result['Result']) && $result['Result'] == 0) {
  1405. return 1; //通过
  1406. } else {
  1407. return 0;
  1408. }
  1409. }
  1410. catch(TencentCloudSDKException $e) {
  1411. // echo $e;
  1412. return 0;
  1413. }
  1414. }
  1415. //绑定支付宝
  1416. public function addalipayaccount() {
  1417. $id = input('id', 0, 'intval'); //账号id
  1418. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1419. // $type = 1;
  1420. $realname = input('realname', '', 'trim'); //账户真实姓名
  1421. $banknumber = input('banknumber', '', 'trim'); //卡号或账号
  1422. $bankname = input('bankname', '', 'trim'); //银行名称
  1423. // if ($id) {
  1424. // $this->error('您已经拥有该类型账号,请联系后台解绑');
  1425. // }
  1426. if (!in_array($type, [1, 2])) {
  1427. $this->error('参数错误');
  1428. }
  1429. /*if ($type == 1) {
  1430. $this->error('暂不支持绑定支付宝');
  1431. }*/
  1432. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1433. $this->error('账号姓名1-30位');
  1434. }
  1435. if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
  1436. $this->error('账号1-50位');
  1437. }
  1438. if ($type == 1) {
  1439. if (iconv_strlen($bankname, 'utf-8') != 18) {
  1440. $this->error('请输入正确身份证号');
  1441. }
  1442. }
  1443. if ($type == 2) {
  1444. if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
  1445. $this->error('开户行名称1-50位');
  1446. }
  1447. }
  1448. $user_bank = Db::name('user_bank');
  1449. if ($id) {
  1450. //编辑
  1451. //查询账号是否存在
  1452. $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1453. if (!$info) {
  1454. $this->error('账号不存在');
  1455. }
  1456. if ($info['type'] != $type) {
  1457. $this->error('账号类型错误');
  1458. }
  1459. //查询是否未通过提现记录
  1460. $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
  1461. if ($count) {
  1462. $this->error('该账户有未审核的提现记录,暂不可修改');
  1463. }
  1464. $data['realname'] = $realname;
  1465. $data['banknumber'] = $banknumber;
  1466. $data['updatetime'] = time();
  1467. // if ($type == 2) {
  1468. $data['bankname'] = $bankname;
  1469. // }
  1470. $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
  1471. if ($rs === false) {
  1472. $this->error('修改失败');
  1473. }
  1474. $this->success('修改成功');
  1475. } else {
  1476. //添加
  1477. //查询是否已经拥有该类型账号
  1478. $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1479. if ($count) {
  1480. $this->error('您已经拥有该类型账号,请联系后台解绑');
  1481. }
  1482. $data['user_id'] = $this->auth->id;
  1483. $data['type'] = $type;
  1484. $data['realname'] = $realname;
  1485. $data['banknumber'] = $banknumber;
  1486. // if ($type == 2) {
  1487. $data['bankname'] = $bankname;
  1488. // }
  1489. $data['createtime'] = time();
  1490. $rs = $user_bank->insertGetId($data);
  1491. if (!$rs) {
  1492. $this->error('添加失败');
  1493. }
  1494. $this->success('添加成功');
  1495. }
  1496. }
  1497. //查询支付宝/银行卡信息
  1498. public function alipayinfo() {
  1499. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1500. $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  1501. if (!$info) {
  1502. $info = (object)[];
  1503. }
  1504. $this->success('success', $info);
  1505. }
  1506. //申请真人认证
  1507. public function realauth() {
  1508. if ($this->auth->real_status == 1) {
  1509. $this->error('您已经真人认证过了~');
  1510. }
  1511. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  1512. $this->error('请先上传真人头像~');
  1513. }
  1514. //获取token
  1515. $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';
  1516. $token_result = file_get_contents($token_url);
  1517. if (!$token_result) {
  1518. $this->error('您的网络开小差啦1~');
  1519. }
  1520. $token_result = json_decode($token_result, true);
  1521. if ($token_result['code'] != 0) {
  1522. $this->error('您的网络开小差啦2~');
  1523. }
  1524. $token = $token_result['access_token'];
  1525. //获取签名鉴权参数ticket
  1526. $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';
  1527. $ticket_result = file_get_contents($ticket_url);
  1528. if (!$ticket_result) {
  1529. $this->error('您的网络开小差啦3~');
  1530. }
  1531. $ticket_result = json_decode($ticket_result, true);
  1532. if ($ticket_result['code'] != 0) {
  1533. $this->error('您的网络开小差啦4~');
  1534. }
  1535. $ticket = $ticket_result['tickets'][0]['value'];
  1536. //获取签名
  1537. $sign_data = [
  1538. 'wbappid' => config('tencent_yun')['secret_id'],
  1539. 'userId' => (string)$this->auth->id,
  1540. 'version' => '1.0.0',
  1541. 'ticket' => $ticket,
  1542. 'nonce' => Random::alnum(32)
  1543. ];//p($sign_data);
  1544. asort($sign_data); //p($sign_data);//排序
  1545. $sign_string = join('', $sign_data);//p($sign_string);
  1546. $sign = sha1($sign_string);//p($sign);
  1547. //上传身份信息
  1548. $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
  1549. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  1550. $avatar = one_domain_image($this->auth->avatar);
  1551. $avatar = str_replace('https', 'http', $avatar);
  1552. $img = file_get_contents($avatar);
  1553. $img = str_replace('data:image/jpg;base64', '', $img);
  1554. $img = str_replace('\n', '', $img);
  1555. $sourcePhotoStr = base64_encode($img);
  1556. $data = [
  1557. 'webankAppId' => config('tencent_yun')['secret_id'],
  1558. 'orderNo' => $orderNo,
  1559. 'userId' => (string)$this->auth->id,
  1560. 'sourcePhotoStr' => $sourcePhotoStr,
  1561. 'sourcePhotoType' => 2,
  1562. 'version' => '1.0.0',
  1563. 'sign' => $sign,
  1564. 'nonce' => $sign_data['nonce']
  1565. ];
  1566. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1567. if (!$rs) {
  1568. $this->error('您的网络开小差啦5~');
  1569. }
  1570. $rs = json_decode($rs, true);
  1571. if (!$rs || $rs['code'] != 0) {
  1572. $this->error('您的网络开小差啦6~');
  1573. }
  1574. $user_auth = [
  1575. 'user_id' => $this->auth->id,
  1576. 'certify_id' => $rs['result']['faceId'],
  1577. 'out_trade_no' => $data['orderNo'],
  1578. 'status' => 0,
  1579. 'createtime' => time(),
  1580. 'updatetime' => time()
  1581. ];
  1582. //开启事务
  1583. Db::startTrans();
  1584. //查询是否认证过
  1585. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1586. if ($info) {
  1587. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  1588. } else {
  1589. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  1590. }
  1591. if (!$auth_rs) {
  1592. Db::rollback();
  1593. $this->error('您的网络开小差啦7~');
  1594. }
  1595. //修改用户表认证状态
  1596. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  1597. if ($user_rs === false) {
  1598. Db::rollback();
  1599. $this->error('您的网络开小差啦8~');
  1600. }
  1601. Db::commit();
  1602. $return_data = [
  1603. 'face_id' => $user_auth['certify_id'],
  1604. 'order_no' => $user_auth['out_trade_no'],
  1605. 'user_id' => (string)$this->auth->id,
  1606. 'nonce' => $sign_data['nonce'],
  1607. 'sign' => $sign
  1608. ];
  1609. $this->success('success', $return_data);
  1610. }
  1611. //查询真人认证结果
  1612. public function getrealauthresult() {
  1613. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1614. if (!$user_auth) {
  1615. $this->success('尚未认证');
  1616. }
  1617. if ($user_auth['status'] == 1) {
  1618. $this->success('真人认证通过');
  1619. }
  1620. if (!$user_auth['certify_id']) {
  1621. $this->success('请先进行真人认证');
  1622. }
  1623. //获取token
  1624. $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';
  1625. $token_result = file_get_contents($token_url);
  1626. if (!$token_result) {
  1627. $this->error('您的网络开小差啦1~');
  1628. }
  1629. $token_result = json_decode($token_result, true);
  1630. if ($token_result['code'] != 0) {
  1631. $this->error('您的网络开小差啦2~');
  1632. }
  1633. $token = $token_result['access_token'];
  1634. //获取签名鉴权参数ticket
  1635. $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';
  1636. $ticket_result = file_get_contents($ticket_url);
  1637. if (!$ticket_result) {
  1638. $this->error('您的网络开小差啦3~');
  1639. }
  1640. $ticket_result = json_decode($ticket_result, true);
  1641. if ($ticket_result['code'] != 0) {
  1642. $this->error('您的网络开小差啦4~');
  1643. }
  1644. $ticket = $ticket_result['tickets'][0]['value'];
  1645. //获取签名
  1646. $sign_data = [
  1647. 'wbappid' => config('tencent_yun')['secret_id'],
  1648. 'orderNo' => $user_auth['out_trade_no'],
  1649. 'version' => '1.0.0',
  1650. 'ticket' => $ticket,
  1651. 'nonce' => Random::alnum(32)
  1652. ];//p($sign_data);
  1653. asort($sign_data); //p($sign_data);//排序
  1654. $sign_string = join('', $sign_data);//p($sign_string);
  1655. $sign = sha1($sign_string);//p($sign);
  1656. //人脸核身结果查询
  1657. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1658. $data = [
  1659. 'appId' => config('tencent_yun')['secret_id'],
  1660. 'version' => '1.0.0',
  1661. 'nonce' => $sign_data['nonce'],
  1662. 'orderNo' => $user_auth['out_trade_no'],
  1663. 'sign' => $sign
  1664. ];
  1665. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1666. if (!$rs) {
  1667. $this->error('您的网络开小差啦5~');
  1668. }
  1669. $rs = json_decode($rs, true);
  1670. if (!$rs || $rs['code'] != 0) {
  1671. $this->error($rs['msg']);
  1672. }
  1673. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1674. $edit_data['status'] = 1;
  1675. $msg = '真人认证成功';
  1676. } else {
  1677. $edit_data['status'] = 2;
  1678. $edit_data['certify_id'] = '';
  1679. $edit_data['out_trade_no'] = '';
  1680. $msg = '真人认证失败';
  1681. }
  1682. $edit_data['updatetime'] = time();
  1683. //开启事务
  1684. Db::startTrans();
  1685. //修改认证信息
  1686. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1687. if (!$result) {
  1688. Db::rollback();
  1689. $this->error('查询认证结果失败2');
  1690. }
  1691. //修改用户信息
  1692. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  1693. if (!$rs) {
  1694. Db::rollback();
  1695. $this->error('查询认证结果失败3');
  1696. }
  1697. if ($edit_data['status'] == 1) { //通过
  1698. //tag任务赠送金币
  1699. //真人认证奖励
  1700. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1701. if($task_rs === false){
  1702. Db::rollback();
  1703. $this->error('完成任务赠送奖励失败');
  1704. }
  1705. //系统消息
  1706. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1707. } else {
  1708. //系统消息
  1709. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1710. }
  1711. Db::commit();
  1712. $this->success($msg);
  1713. }
  1714. //客服
  1715. public function kefu() {
  1716. $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
  1717. if (!in_array($type, [0, 1])) {
  1718. $this->error('您的网络开小差啦~');
  1719. }
  1720. if ($type == 0) {
  1721. $user_id = config('site.customer_service_id') ? : 0; //指定客服id
  1722. } else {
  1723. $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
  1724. }
  1725. $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
  1726. if (!$list) {
  1727. $this->success('success', $list);
  1728. }
  1729. foreach ($list as $k => &$v) {
  1730. $v['nickname'] = '客服' . ($k + 1);
  1731. $v['avatar'] = config('avatar_girl');
  1732. }
  1733. $this->success('success', $list);
  1734. }
  1735. //海报背景图
  1736. public function posterlist() {
  1737. $list = config('site.intro_images');
  1738. if (!$list) {
  1739. $this->success('success', (object)[]);
  1740. }
  1741. foreach ($list as &$v) {
  1742. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  1743. }
  1744. $this->success('success', $list);
  1745. }
  1746. //生成海报
  1747. public function createposter($image = '') {
  1748. // $image = input('image', '', 'trim');
  1749. // if (!$image) {
  1750. // $this->error('您的网络开小差啦~');
  1751. // }
  1752. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  1753. return $haibao;
  1754. // $this->success('success', $haibao);
  1755. }
  1756. //注册设置性别
  1757. public function setgender() {
  1758. $user_id = $this->auth->id;
  1759. /*if (in_array($user_id, [0, 1])) {
  1760. $this->error('性别不能修改~');
  1761. }*/
  1762. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1763. if (!in_array($gender, [1, 0])) {
  1764. $this->error('性别错误');
  1765. }
  1766. $edit_data['gender'] = $gender;
  1767. $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
  1768. $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
  1769. if (!$rs) {
  1770. $this->error('您的网络开小差啦~');
  1771. }
  1772. $data = $this->userInfo('return');
  1773. $data['gender'] = $edit_data['gender'];
  1774. $data['avatar'] = $edit_data['avatar'];
  1775. // $this->success('success', $data);
  1776. // 如果是女用户,则停止账户使用
  1777. if ($gender == 0){
  1778. Db::name('user')->where('id',$user_id)->update(['status'=>0,'is_closed'=>1]);//金庸
  1779. Db::name('user_token')->where('user_id',$user_id)->delete();//金庸
  1780. }
  1781. //领取任务奖励
  1782. $task_id = 22; // 任务ID
  1783. // 查询任务信息
  1784. $taskInfo = $this->taskModel->where(["id"=>$task_id])->find();
  1785. if(!$taskInfo) {
  1786. // $this->error("任务信息未找到!");
  1787. $this->success('success', $data);
  1788. }
  1789. // 查询用户完成情况
  1790. $where = [];
  1791. $where["user_id"] = $user_id;
  1792. $where["task_id"] = $task_id;
  1793. $where["is_finish"] = 1;
  1794. if($taskInfo["type_id"] == 2){
  1795. $where["finish_date"] = date("Ymd");
  1796. }
  1797. $tasklogInfo = $this->tasklogModel->where($where)->find();
  1798. if(!$tasklogInfo) {
  1799. // $this->error("任务还未完成哦!");
  1800. $this->success('success', $data);
  1801. }
  1802. if($tasklogInfo["is_reward"] == 1) {
  1803. // $this->error("任务奖励已领取,请勿重复领取!");
  1804. $this->success('success', $data);
  1805. }
  1806. Db::startTrans();
  1807. // 增加用户经验值
  1808. //$res1 = \app\common\model\User::addEmpirical($user_id,$taskInfo["exp"]);
  1809. $res1['status'] = true;
  1810. if ($gender == 1) {
  1811. //男用户获得金币
  1812. $res1 = model('wallet')->lockChangeAccountRemain($user_id,0, 'gold', $taskInfo["exp"], 61, '完成' . $taskInfo['name'] . '任务', 'task_log', $tasklogInfo['id']);
  1813. if ($res1['status'] === false) {
  1814. Db::rollback();
  1815. // $this->error($res1['msg']);
  1816. $this->success('success', $data);
  1817. }
  1818. } elseif ($gender == 0) {
  1819. $bili = config('site.money_to_gold'); //钱和金币兑换比例
  1820. if ($bili > 0) {
  1821. //女用户获得钱
  1822. $money = bcdiv($taskInfo['exp'], $bili, 2);
  1823. if ($money > 0) {
  1824. $res1 = model('wallet')->lockChangeAccountRemain($user_id,0, 'money', $money, 67, '完成' .$taskInfo['name'] . '任务', 'task_log', $tasklogInfo['id']);
  1825. if ($res1['status'] === false) {
  1826. Db::rollback();
  1827. // $this->error($res1['msg']);
  1828. $this->success('success', $data);
  1829. }
  1830. }
  1831. }
  1832. }
  1833. // 更新奖励领取状态
  1834. $res2 = $this->tasklogModel->update(["is_reward"=>1],["task_id"=>$task_id,"user_id"=>$user_id]);
  1835. //系统消息
  1836. $msg_id = \app\common\model\Message::addMessage($user_id,'任务奖励','完成' . $taskInfo['name'] . '任务,获得任务奖励');
  1837. if($res1['status'] === true && $res2) {
  1838. Db::commit();
  1839. // $this->success("领取成功!");
  1840. $this->success('success', $data);
  1841. } else {
  1842. Db::rollback();
  1843. // $this->error("领取失败!");
  1844. $this->success('success', $data);
  1845. }
  1846. }
  1847. //真人认证后修改头像前比对
  1848. public function realavatar_auit() {
  1849. if ($this->auth->real_status != 1) {
  1850. $this->error('尚未通过真人认证');
  1851. }
  1852. $avatar = input('avatar', '', 'trim'); //头像地址
  1853. if ($avatar === '') {
  1854. $this->error('参数缺失');
  1855. }
  1856. $avatar = one_domain_image($avatar);
  1857. $now_avatar = one_domain_image($this->auth->avatar);
  1858. if ($avatar == $now_avatar) {
  1859. $this->error('头像未改变');
  1860. }
  1861. //腾讯云人脸识别
  1862. $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1863. $this->success('结果', $result);
  1864. }
  1865. //真人认证后修改头像
  1866. public function editrealavatar() {
  1867. if ($this->auth->real_status != 1) {
  1868. $this->error('尚未通过真人认证');
  1869. }
  1870. $avatar = input('avatar', '', 'trim'); //头像地址
  1871. if ($avatar === '') {
  1872. $this->error('参数缺失');
  1873. }
  1874. $avatar = one_domain_image($avatar);
  1875. $now_avatar = one_domain_image($this->auth->avatar);
  1876. if ($avatar == $now_avatar) {
  1877. $this->error('头像未改变');
  1878. }
  1879. //腾讯云人脸识别
  1880. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  1881. if ($auit_result != 1) {
  1882. $this->success('提示', ['code' => 2]);
  1883. }
  1884. $data['avatar'] = $avatar;
  1885. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1886. if (!$user_result) {
  1887. $this->error('修改失败');
  1888. }
  1889. $this->success('修改成功');
  1890. }
  1891. //真人认证后修改头像并取消真人认证
  1892. public function editrealavatarcancelauit() {
  1893. if ($this->auth->real_status != 1) {
  1894. $this->error('尚未通过真人认证');
  1895. }
  1896. $avatar = input('avatar', '', 'trim'); //头像地址
  1897. if ($avatar === '') {
  1898. $this->error('参数缺失');
  1899. }
  1900. $avatar = one_domain_image($avatar);
  1901. $now_avatar = one_domain_image($this->auth->avatar);
  1902. if ($avatar == $now_avatar) {
  1903. $this->error('头像未改变');
  1904. }
  1905. $data['avatar'] = $avatar;
  1906. $data['real_status'] = -1;
  1907. //开启事务
  1908. Db::startTrans();
  1909. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  1910. if (!$user_result) {
  1911. Db::rollback();
  1912. $this->error('修改失败');
  1913. }
  1914. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  1915. if (!$user_auth_result) {
  1916. Db::rollback();
  1917. $this->error('修改失败');
  1918. }
  1919. Db::commit();
  1920. $this->success('修改成功');
  1921. }
  1922. //腾讯云人脸识别
  1923. public function face_tencent($urla = '', $urlb = '') {
  1924. // require_once 'vendor/autoload.php';
  1925. try {
  1926. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1927. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1928. $config = config('tencent_im');
  1929. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1930. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1931. $httpProfile = new HttpProfile();
  1932. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  1933. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1934. $clientProfile = new ClientProfile();
  1935. $clientProfile->setHttpProfile($httpProfile);
  1936. // 实例化要请求产品的client对象,clientProfile是可选的
  1937. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  1938. // 实例化一个请求对象,每个接口都会对应一个request对象
  1939. $req = new CompareFaceRequest();
  1940. $params = array(
  1941. "UrlA" => $urla,
  1942. "UrlB" => $urlb,
  1943. "FaceModelVersion" => "3.0"
  1944. );
  1945. $req->fromJsonString(json_encode($params));
  1946. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  1947. $resp = $client->CompareFace($req);
  1948. // 输出json格式的字符串回包
  1949. // print_r($resp->toJsonString());
  1950. $result = json_decode($resp->toJsonString(), true);
  1951. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  1952. if (isset($result['Score']) && $result['Score'] >= 60) {
  1953. return 1; //通过
  1954. } else {
  1955. return 0;
  1956. }
  1957. }
  1958. catch(TencentCloudSDKException $e) {
  1959. // echo $e;
  1960. return 0;
  1961. }
  1962. }
  1963. //修改城市
  1964. public function editcity() {
  1965. $name = input('name', '', 'trim'); //城市名
  1966. if ($name === '') {
  1967. $this->error('参数缺失');
  1968. }
  1969. $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
  1970. if (!$hometown_cityid) {
  1971. $this->success('修改成功');
  1972. }
  1973. Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
  1974. $this->success('修改成功');
  1975. }
  1976. //搜索用户
  1977. public function searchuser() {
  1978. $keyword = input('keyword', '', 'trim'); //昵称或ID
  1979. if ($keyword === '') {
  1980. $this->error('请输入关键字');
  1981. }
  1982. $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
  1983. $id = $id ? : 0;
  1984. $this->success('用户', $id);
  1985. }
  1986. //绑定支付宝账号信息
  1987. public function bindalipayaccount() {
  1988. $mt_user_bank = Db::name('user_bank');
  1989. $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
  1990. if ($count) {
  1991. $this->error('您已绑定支付宝啦');
  1992. }
  1993. $auth_code = input('auth_code', '', 'trim');
  1994. if (!$auth_code) {
  1995. $this->error('授权码缺失');
  1996. }
  1997. //获取支付宝用户信息
  1998. $rs = getAlipayInfo($auth_code);
  1999. if ($rs['status'] == 0) {
  2000. $this->error($rs['info']);
  2001. }
  2002. $rs = $rs['data'];
  2003. /*
  2004. * Array(
  2005. [alipay_user_info_share_response] => Array
  2006. (
  2007. [code] => 10000
  2008. [msg] => Success
  2009. [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
  2010. [city] => 临沂市 市名称。
  2011. [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
  2012. [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
  2013. [is_student_certified] => F 是否是学生 T是 F否
  2014. [nick_name] => 风的追求 用户昵称
  2015. [province] => 山东省 省份名称
  2016. [user_id] => 2088902918001020 支付宝用户的userId
  2017. [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
  2018. [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
  2019. )
  2020. )
  2021. */
  2022. $data['banknumber'] = $rs['user_id']; //支付宝用户id
  2023. if (!$data['banknumber']) {
  2024. $this->error('获取用户信息失败');
  2025. }
  2026. $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
  2027. if ($bank_number_count) {
  2028. $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
  2029. }
  2030. if (isset($rs['nick_name'])) {
  2031. $data['realname'] = $rs['nick_name']; //支付宝用户昵称
  2032. }
  2033. $data['user_id'] = $this->auth->id;
  2034. $data['createtime'] = time();
  2035. $data['type'] = 1;
  2036. $rt = $mt_user_bank->insertGetId($data);
  2037. if (!$rt) {
  2038. $this->error('绑定失败');
  2039. }
  2040. $this->success('绑定成功');
  2041. }
  2042. //添加打招呼内容,女性使用
  2043. public function addgreetcontent() {
  2044. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  2045. $title = input('title', '', 'trim'); //标题(type=1必传)
  2046. $content = input('content', '', 'trim'); //内容
  2047. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  2048. if (!in_array($type, [0, 1, 2])) {
  2049. $this->error('您的网络开小差了');
  2050. }
  2051. if ($content === '') {
  2052. $this->error('请设置打招呼内容');
  2053. }
  2054. if (iconv_strlen($content, 'utf-8') > 255) {
  2055. $this->error('打招呼内容最多255位');
  2056. }
  2057. if ($type == 1) {
  2058. if ($title === '') {
  2059. $this->error('请输入语音名称');
  2060. }
  2061. if (iconv_strlen($title, 'utf-8') > 50) {
  2062. $this->error('语音名称最多50字');
  2063. }
  2064. if (!$duration) {
  2065. $this->error('参数缺失');
  2066. }
  2067. }
  2068. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  2069. if ($count > 10) {
  2070. $this->error('同一类型打招呼最多设置10条');
  2071. }
  2072. $data['user_id'] = $this->auth->id;
  2073. $data['type'] = $type;
  2074. $data['content'] = $content;
  2075. if ($type == 1) {
  2076. $data['title'] = $title;
  2077. $data['duration'] = $duration;
  2078. }
  2079. $data['createtime'] = time();
  2080. //查询是否有默认打招呼内容
  2081. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  2082. if (!$default_greet_count) {
  2083. $data['is_default'] = 1;
  2084. }
  2085. $rs = Db::name('user_greet_content')->insertGetId($data);
  2086. if (!$rs) {
  2087. $this->error('您的网络开小差了');
  2088. }
  2089. $this->success('设置成功');
  2090. }
  2091. //查询打招呼内容,女性使用
  2092. public function getgreetcontent() {
  2093. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  2094. if (!in_array($type, [0, 1, 2, 3])) {
  2095. $this->error('您的网络开小差了');
  2096. }
  2097. if ($type == 3) {
  2098. $list = Db::name('user_greet_content')->where(function ($query) {
  2099. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  2100. })->whereOr(function ($query) {
  2101. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  2102. })->select();
  2103. } else {
  2104. $where['user_id'] = $this->auth->id;
  2105. $where['type'] = $type;
  2106. $list = Db::name('user_greet_content')->where($where)->select();
  2107. }
  2108. if ($list) {
  2109. foreach ($list as &$v) {
  2110. if ($v['type'] != 0) {
  2111. $v['content'] = one_domain_image($v['content']);
  2112. }
  2113. }
  2114. }
  2115. $this->success('打招呼内容', $list);
  2116. }
  2117. //设置默认打招呼内容,女性使用
  2118. public function setdefaultgreet() {
  2119. $id = input('id', 0, 'intval'); //打招呼id
  2120. if (!$id) {
  2121. $this->error('您的网络开小差了');
  2122. }
  2123. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  2124. if (!$count) {
  2125. $this->error('您的网络开小差了');
  2126. }
  2127. //开启事务
  2128. Db::startTrans();
  2129. //清除之前默认
  2130. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  2131. if ($rs === false) {
  2132. Db::rollback();
  2133. $this->error('您的网络开小差了');
  2134. }
  2135. //设置
  2136. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  2137. if ($rt === false) {
  2138. Db::rollback();
  2139. $this->error('您的网络开小差了');
  2140. }
  2141. Db::commit();
  2142. $this->success('设置成功');
  2143. }
  2144. //删除打招呼内容,女性使用
  2145. public function deldefaultgreet() {
  2146. $id = input('id', 0, 'intval'); //打招呼id
  2147. if (!$id) {
  2148. $this->error('您的网络开小差了');
  2149. }
  2150. $mt_user_greet_content = Db::name('user_greet_content');
  2151. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  2152. if (!$info) {
  2153. $this->error('您的网络开小差了');
  2154. }
  2155. //开启事务
  2156. Db::startTrans();
  2157. //删除
  2158. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  2159. if ($rs === false) {
  2160. Db::rollback();
  2161. $this->error('您的网络开小差了');
  2162. }
  2163. //若为默认打招呼内容则重新设置一条
  2164. if ($info['is_default'] == 1) {
  2165. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  2166. if ($first_greet) {
  2167. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  2168. if ($rt === false) {
  2169. Db::rollback();
  2170. $this->error('您的网络开小差了');
  2171. }
  2172. }
  2173. }
  2174. Db::commit();
  2175. $this->success('删除成功');
  2176. }
  2177. }