User.php 96 KB

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