User.php 77 KB

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