User.php 75 KB

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