User.php 86 KB

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