User.php 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621
  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. * 退出登录
  700. * @ApiMethod (POST)
  701. */
  702. public function logout()
  703. {
  704. if (!$this->request->isPost()) {
  705. $this->error(__('Invalid parameters'));
  706. }
  707. //退出im
  708. $tenIm = new Tenim();
  709. $tenIm->loginoutim($this->auth->id);
  710. //修改用户活跃0
  711. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
  712. $this->auth->logout();
  713. $this->success(__('Logout successful'));
  714. }
  715. /**
  716. * 修改会员个人信息
  717. *
  718. * @ApiMethod (POST)
  719. * @param string $avatar 头像地址
  720. * @param string $username 用户名
  721. * @param string $nickname 昵称
  722. * @param string $bio 个人简介
  723. */
  724. public function profile()
  725. {
  726. $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'];
  727. $data = [];
  728. foreach($field_array as $key => $field){
  729. if(!input('?'.$field)){
  730. continue;
  731. }
  732. $newone = input($field);
  733. if($field == 'avatar'){
  734. // if ($this->auth->real_status == 1) {
  735. //$this->error('您已经真人认证不能修改头像~');
  736. // die;
  737. // }
  738. $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
  739. }
  740. if($field == 'photo_images'){
  741. $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
  742. }
  743. $data[$field] = $newone;
  744. }
  745. if(isset($data['birthday'])){
  746. $data['birthday'] = strtotime($data['birthday']);
  747. }
  748. if(isset($data['avatar'])){
  749. //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
  750. }
  751. if(isset($data['hobby_ids'])){
  752. $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
  753. }
  754. if(isset($data['tag_ids'])){
  755. $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
  756. }
  757. if(isset($data['introcode'])){
  758. if ($this->auth->intro_uid != 0) {
  759. $this->error('邀请人不可修改~');
  760. }
  761. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
  762. if(!$intro_user){
  763. $this->error('不存在的邀请人');
  764. }
  765. if ($intro_user['id'] == $this->auth->id) {
  766. $this->error('不能填写自己邀请码');
  767. }
  768. if ($intro_user['intro_uid'] == $this->auth->id) {
  769. $this->error('不能填写下级邀请码');
  770. }
  771. unset($data['introcode']);//别人的邀请码,不能改了自己的
  772. $data['intro_uid'] = $intro_user['id'];
  773. $data['invite_time'] = time();
  774. }
  775. //dump($data);
  776. if(empty($data)){
  777. $this->error('没有任何改变');
  778. }
  779. Db::startTrans();
  780. $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
  781. if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {//隐藏
  782. $boyAvatar = config('avatar_boy');
  783. $girlAvatar = config('avatar_girl');
  784. if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
  785. $data['status'] = 1;//更新为正常
  786. } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
  787. $data['status'] = 1;//更新为正常
  788. }
  789. }
  790. $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
  791. if($update_rs === false){
  792. Db::rollback();
  793. $this->error('修改资料失败');
  794. }
  795. //tag任务赠送金币
  796. //上传头像加5金币
  797. if(isset($data['avatar'])){
  798. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  799. if($task_rs === false){
  800. Db::rollback();
  801. $this->error('完成任务赠送奖励失败');
  802. }
  803. }
  804. //上传生日 +5金币
  805. if (isset($data['birthday'])) {
  806. //完成设置生日 +5金币
  807. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  808. if($task_rs === false){
  809. Db::rollback();
  810. $this->error('完成任务赠送奖励失败');
  811. }
  812. }
  813. //上传个性签名 5金币
  814. if(isset($data['audio_bio'])){
  815. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
  816. if($task_rs === false){
  817. Db::rollback();
  818. $this->error('完成任务赠送奖励失败');
  819. }
  820. }
  821. //上传本人语音介绍 10金币
  822. if(isset($data['audio_bio'])){
  823. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
  824. if($task_rs === false){
  825. Db::rollback();
  826. $this->error('完成任务赠送奖励失败');
  827. }
  828. }
  829. //上传本人五张照片 10金币
  830. if(isset($data['photo_images'])){
  831. $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
  832. if ($photo_images_num >= 5) {
  833. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
  834. if ($task_rs === false) {
  835. Db::rollback();
  836. $this->error('完成任务赠送奖励失败');
  837. }
  838. }
  839. }
  840. /*if (isset($data['intro_uid'])) { //邀请人获得金币
  841. $intro_gold = config('site.intro_gold');
  842. if ($intro_gold > 0) {
  843. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],$this->auth->id,'gold',$intro_gold,64,'邀请注册奖励','user', $this->auth->id);
  844. if($wallet_rs['status'] === false){
  845. Db::rollback();
  846. $this->error($wallet_rs['msg']);
  847. }
  848. }
  849. }*/
  850. Db::commit();
  851. /*//开启事务
  852. Db::startTrans();
  853. //所有基本资料完成
  854. $user_info = Db::name('user')->where('id',$this->auth->id)->find();
  855. 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']){
  856. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,6);
  857. if($task_rs === false){
  858. Db::rollback();
  859. $this->error('完成任务赠送奖励失败');
  860. }
  861. }
  862. //兴趣爱好
  863. if($user_info['hobby_ids']){
  864. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,7);
  865. if($task_rs === false){
  866. Db::rollback();
  867. $this->error('完成任务赠送奖励失败');
  868. }
  869. }
  870. //个人标签
  871. if($user_info['tag_ids']){
  872. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,8);
  873. if($task_rs === false){
  874. Db::rollback();
  875. $this->error('完成任务赠送奖励失败');
  876. }
  877. }
  878. Db::commit();*/
  879. $this->success();
  880. }
  881. public function set_status_switch(){
  882. }
  883. /*
  884. * 修改用户的坐标
  885. * */
  886. public function change_longlat(){
  887. $longitude = input_post('longitude');
  888. $latitude = input_post('latitude');
  889. $cityname = input_post('cityname');
  890. if(empty($longitude) || empty($latitude) || empty($cityname)){
  891. $this->error();
  892. }
  893. $data = [
  894. 'longitude' => $longitude,
  895. 'latitude' => $latitude,
  896. 'cityname' => $cityname,
  897. ];
  898. Db::name('user')->where('id',$this->auth->id)->update($data);
  899. $this->success();
  900. }
  901. /**
  902. * 修改邮箱
  903. *
  904. * @ApiMethod (POST)
  905. * @param string $email 邮箱
  906. * @param string $captcha 验证码
  907. */
  908. /*public function changeemail()
  909. {
  910. $user = $this->auth->getUser();
  911. $email = $this->request->post('email');
  912. $captcha = $this->request->post('captcha');
  913. if (!$email || !$captcha) {
  914. $this->error(__('Invalid parameters'));
  915. }
  916. if (!Validate::is($email, "email")) {
  917. $this->error(__('Email is incorrect'));
  918. }
  919. if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
  920. $this->error(__('Email already exists'));
  921. }
  922. $result = Ems::check($email, $captcha, 'changeemail');
  923. if (!$result) {
  924. $this->error(__('Captcha is incorrect'));
  925. }
  926. $verification = $user->verification;
  927. $verification->email = 1;
  928. $user->verification = $verification;
  929. $user->email = $email;
  930. $user->save();
  931. Ems::flush($email, 'changeemail');
  932. $this->success();
  933. }*/
  934. /**
  935. * 修改手机号
  936. *
  937. * @ApiMethod (POST)
  938. * @param string $mobile 手机号
  939. * @param string $captcha 验证码
  940. */
  941. public function changemobile()
  942. {
  943. $user = $this->auth->getUser();
  944. $oldcaptcha = $this->request->request('oldcaptcha');
  945. $mobile = $this->request->request('mobile');
  946. $captcha = $this->request->request('captcha');
  947. if (!$oldcaptcha || !$mobile || !$captcha) {
  948. $this->error(__('Invalid parameters'));
  949. }
  950. if (!Validate::regex($mobile, "^1\d{10}$")) {
  951. $this->error(__('Mobile is incorrect'));
  952. }
  953. if($user->mobile == $mobile){
  954. $this->error('新手机号不能与旧手机号相同');
  955. }
  956. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  957. $this->error(__('Mobile already exist'));
  958. }
  959. $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
  960. if (!$result) {
  961. $this->error(__('Captcha is incorrect'));
  962. }
  963. $result = Sms::check($mobile, $captcha, 'changemobile');
  964. if (!$result) {
  965. $this->error(__('Captcha is incorrect'));
  966. }
  967. $verification = $user->verification;
  968. $verification->mobile = 1;
  969. $user->verification = $verification;
  970. $user->mobile = $mobile;
  971. $user->save();
  972. Sms::flush($user->mobile, 'changemobile');
  973. Sms::flush($mobile, 'changemobile');
  974. $this->success();
  975. }
  976. /**
  977. * 微信注册来的,绑定手机号
  978. *
  979. * @ApiMethod (POST)
  980. * @param string $mobile 手机号
  981. * @param string $captcha 验证码
  982. */
  983. public function bindmobile()
  984. {
  985. $user = $this->auth->getUser();
  986. $mobile = $this->request->request('mobile');
  987. $captcha = $this->request->request('captcha');
  988. if(!empty($this->auth->mobile)){
  989. $this->error('已经绑定了手机号');
  990. }
  991. if (!$mobile || !$captcha) {
  992. $this->error(__('Invalid parameters'));
  993. }
  994. if (!Validate::regex($mobile, "^1\d{10}$")) {
  995. $this->error(__('Mobile is incorrect'));
  996. }
  997. if (\app\common\model\User::where('mobile', $mobile)->find()) {
  998. $this->error('该手机号已被其他用户绑定');
  999. }
  1000. $result = Sms::check($mobile, $captcha, 'changemobile');
  1001. if (!$result) {
  1002. $this->error(__('Captcha is incorrect'));
  1003. }
  1004. $verification = $user->verification;
  1005. $verification->mobile = 1;
  1006. $user->verification = $verification;
  1007. $user->mobile = $mobile;
  1008. $user->save();
  1009. Sms::flush($mobile, 'changemobile');
  1010. //手机号奖励
  1011. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
  1012. if($task_rs === false){
  1013. Db::rollback();
  1014. return false;
  1015. }
  1016. $this->success('success',$this->userInfo('return'));
  1017. }
  1018. /**
  1019. * 手机号注册来的,绑定微信
  1020. *
  1021. * @ApiMethod (POST)
  1022. * @param string wechat_openid 微信openid
  1023. */
  1024. public function bindopenid()
  1025. {
  1026. $user = $this->auth->getUser();
  1027. $wechat_openid = $this->request->request('wechat_openid');
  1028. if(!empty($this->auth->wechat_openid)){
  1029. $this->error('已经绑定了微信号');
  1030. }
  1031. if (!$wechat_openid) {
  1032. $this->error(__('Invalid parameters'));
  1033. }
  1034. if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
  1035. $this->error('该微信号已被其他用户绑定');
  1036. }
  1037. $user->wechat_openid = $wechat_openid;
  1038. $user->save();
  1039. $this->success('success',$this->userInfo('return'));
  1040. }
  1041. /**
  1042. * 第三方登录
  1043. *
  1044. * @ApiMethod (POST)
  1045. * @param string $platform 平台名称
  1046. * @param string $code Code码
  1047. */
  1048. /*public function third()
  1049. {
  1050. $url = url('user/index');
  1051. // $platform = $this->request->post("platform");
  1052. $platform = 'wechat';
  1053. $code = $this->request->post("code");
  1054. $config = get_addon_config('third');
  1055. if (!$config || !isset($config[$platform])) {
  1056. $this->error(__('Invalid parameters'));
  1057. }
  1058. $app = new \addons\third\library\Application($config);
  1059. //通过code换access_token和绑定会员
  1060. $result = $app->{$platform}->getUserInfo(['code' => $code]);
  1061. if ($result) {
  1062. $loginret = \addons\third\library\Service::connect($platform, $result);
  1063. if ($loginret) {
  1064. $data = [
  1065. 'userinfo' => $this->auth->getUserinfo(),
  1066. 'thirdinfo' => $result
  1067. ];
  1068. $this->success(__('Logged in successful'), $data);
  1069. }
  1070. }
  1071. $this->error(__('Operation failed'), $url);
  1072. }*/
  1073. /**
  1074. * 重置密码
  1075. *
  1076. * @ApiMethod (POST)
  1077. * @param string $mobile 手机号
  1078. * @param string $newpassword 新密码
  1079. * @param string $captcha 验证码
  1080. */
  1081. public function resetpwd()
  1082. {
  1083. //$type = input("type");
  1084. $type = 'mobile';
  1085. $mobile = input("mobile");
  1086. $email = input("email");
  1087. $newpassword = input("newpassword");
  1088. $captcha = input("captcha");
  1089. if (!$newpassword || !$captcha) {
  1090. $this->error(__('Invalid parameters'));
  1091. }
  1092. if ($type == 'mobile') {
  1093. if (!Validate::regex($mobile, "^1\d{10}$")) {
  1094. $this->error(__('Mobile is incorrect'));
  1095. }
  1096. $user = \app\common\model\User::getByMobile($mobile);
  1097. if (!$user) {
  1098. $this->error(__('User not found'));
  1099. }
  1100. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  1101. if (!$ret) {
  1102. $this->error(__('Captcha is incorrect'));
  1103. }
  1104. Sms::flush($mobile, 'resetpwd');
  1105. } else {
  1106. if (!Validate::is($email, "email")) {
  1107. $this->error(__('Email is incorrect'));
  1108. }
  1109. $user = \app\common\model\User::getByEmail($email);
  1110. if (!$user) {
  1111. $this->error(__('User not found'));
  1112. }
  1113. $ret = Ems::check($email, $captcha, 'resetpwd');
  1114. if (!$ret) {
  1115. $this->error(__('Captcha is incorrect'));
  1116. }
  1117. Ems::flush($email, 'resetpwd');
  1118. }
  1119. //模拟一次登录
  1120. $this->auth->direct($user->id);
  1121. $ret = $this->auth->changepwd($newpassword, '', true);
  1122. if ($ret) {
  1123. $this->success(__('Reset password successful'));
  1124. } else {
  1125. $this->error($this->auth->getError());
  1126. }
  1127. }
  1128. /**
  1129. * 修改密码
  1130. *
  1131. * @ApiMethod (POST)
  1132. * @param string $newpassword 新密码
  1133. * @param string $oldpassword 旧密码
  1134. */
  1135. public function changepwd(){
  1136. $newpassword = input('newpassword');
  1137. $oldpassword = input('oldpassword','');
  1138. if (!$newpassword) {
  1139. $this->error(__('Invalid parameters'));
  1140. }
  1141. if($this->auth->password && empty($oldpassword)){
  1142. $this->error('原密码必填');
  1143. }
  1144. if(empty($this->auth->password)){
  1145. $ret = $this->auth->changepwd($newpassword, '', true);
  1146. }else{
  1147. $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
  1148. }
  1149. if ($ret) {
  1150. $this->success(__('Reset password successful'));
  1151. } else {
  1152. $this->error($this->auth->getError());
  1153. }
  1154. }
  1155. /**
  1156. * 记录当前登陆的设备ID,设备信息,IP等
  1157. */
  1158. public function changeDeviceIp()
  1159. {
  1160. // 接口防并发
  1161. if (!$this->apiLimit(1, 5000)) {
  1162. return ;
  1163. }
  1164. $user = $this->auth->getUser();
  1165. $ip = request()->ip();
  1166. $deviceId = $this->request->request('device_id','');
  1167. $phoneModel = $this->request->request('phone_model','');
  1168. $brand = $this->request->request('brand','');
  1169. $apiVersion = $this->request->request('api_version','');
  1170. $deviceOs = $this->request->request('device_os','');
  1171. if ($ip !== $user->loginip){
  1172. $update = [];
  1173. $update['id'] = $user->id;
  1174. $update['loginip'] = $ip;
  1175. \app\common\model\User::update($update);
  1176. }
  1177. $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
  1178. if (empty($userDeviceInfo)){
  1179. $userDeviceInfo = new UserDeviceInfo();
  1180. $userDeviceInfo->user_id = $user->u_id;
  1181. }
  1182. $userDeviceInfo->device_os = $deviceOs;
  1183. $userDeviceInfo->device_id = $deviceId;
  1184. $userDeviceInfo->phone_model = $phoneModel;
  1185. $userDeviceInfo->brand = $brand;
  1186. $userDeviceInfo->api_version = $apiVersion;
  1187. $userDeviceInfo->save();
  1188. //首页接口调用,这里不反回信息
  1189. // $this->success("更新成功!");
  1190. }
  1191. //假注销
  1192. public function cancleUser(){
  1193. if (!$this->request->isPost()) {
  1194. $this->error(__('Invalid parameters'));
  1195. }
  1196. //退出im
  1197. $tenIm = new Tenim();
  1198. $tenIm->loginoutim($this->auth->id);
  1199. Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
  1200. $this->auth->logout();
  1201. $this->success('注销成功');
  1202. }
  1203. //修改用户活跃1
  1204. public function useractive(){
  1205. Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 1,'active_time' => time()]);
  1206. $this->success('success');
  1207. }
  1208. //APP 转化数据统计方案(即:APP 上报对接方案): 广告主上报激活数据,亿米平台搭建服务系统关联点击&下载数据和广告主提供的所有激活数据,将激活数据归因到对应广告。
  1209. public function yimi_advert(){
  1210. //http://trail.e.mi.com/global/log?appId={appid}&info={data}&conv_type={convType}&customer_id={customerId}
  1211. $api_url = 'http://trail.e.mi.com/global/log?';
  1212. $api_url_test = 'http://trail.e.mi.com/global/test?';
  1213. //应用id 1453045
  1214. //秘钥A(encrypt_key):ZxdIaVHvFqSQYzWD
  1215. //秘钥B(sign_key):uaeWeunykLRnkyLw
  1216. $sign_key = 'uaeWeunykLRnkyLw'; //真的
  1217. $encrypt_key = 'ZxdIaVHvFqSQYzWD';//真的
  1218. $appid = '1453045';
  1219. $conv_type = 'APP_REGISTER';
  1220. $customer_id = '292232';
  1221. //推荐模式
  1222. /*$imei = md5('imei');
  1223. $data = [
  1224. 'imei' => '91b9185dba1772851dd02b276a6c969e',
  1225. 'oaid' => '5fb96f268628810c',
  1226. 'conv_time' => '1504687208890',
  1227. 'client_ip' => '127.0.0.1',
  1228. 'ua' => 'Dalvik/2.1.0 (Linux; U; Android 11; M2012K11AC Build/RKQ1.200826.002)',
  1229. ];*/
  1230. //采用模式4
  1231. /*
  1232. $ua = input('ua','','trim');
  1233. if(empty($ua)){
  1234. return true;
  1235. }
  1236. $data = [
  1237. 'conv_time' => time().substr(microtime(),2,3),
  1238. 'client_ip' => request()->ip(),
  1239. 'ua' => $ua,
  1240. ];
  1241. */
  1242. //采用模式3
  1243. $oaid = input('oaid','','trim');
  1244. if(empty($oaid)){
  1245. return true;
  1246. }
  1247. $data = [
  1248. 'oaid' => $oaid,
  1249. 'conv_time' => time().substr(microtime(),2,3),
  1250. 'client_ip' => request()->ip(),
  1251. ];
  1252. $data_query = http_build_query($data);
  1253. //dump($data_query);
  1254. $property = $sign_key.'&'.urlencode($data_query);
  1255. //dump($property);
  1256. $signature = md5($property);
  1257. //dump($signature);
  1258. $base_data = $data_query .'&sign='.urlencode($signature);
  1259. //echo $base_data;
  1260. $info = urlencode(base64_encode($this->xor_enc($base_data, $encrypt_key)));
  1261. //dump($info);
  1262. $request_url = $api_url.'appId='.$appid.'&info='.$info.'&customer_id='.$customer_id.'&conv_type='.$conv_type;
  1263. //echo $request_url;
  1264. $result = curl_get($request_url);
  1265. //dump($result);
  1266. //日志
  1267. $log = [
  1268. 'param' => $base_data,
  1269. 'url' => $request_url,
  1270. 'result'=> $result,
  1271. 'createtime' => time(),
  1272. ];
  1273. Db::name('yimi_advert')->insertGetId($log);
  1274. return true;
  1275. }
  1276. //亿米 异或加密,解密
  1277. public function xor_enc($str,$key)
  1278. {
  1279. $crytxt = '';
  1280. $keylen = strlen($key);
  1281. for($i=0;$i<strlen($str);$i++)
  1282. {
  1283. $k = $i%$keylen;
  1284. $crytxt .= $str[$i] ^ $key[$k];
  1285. }
  1286. return $crytxt;
  1287. }
  1288. //公众号获取openid
  1289. public function getUserOpenid_gzh(){
  1290. $configValue = Service::getConfig('wechat');
  1291. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1292. $rs = $wechat->getOpenid();
  1293. $this->success('success',$rs);
  1294. }
  1295. /**
  1296. * 微信内H5-JSAPI支付
  1297. */
  1298. public function jssdkBuildConfig() {
  1299. $url = $this->request->request("url");
  1300. $configValue = Service::getConfig('wechat');
  1301. $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
  1302. $sign = $wechat->getSignPackage(urldecode($url));
  1303. $this->success("获取成功!",$sign);
  1304. }
  1305. //苹果账号登录
  1306. public function ioslogin(){
  1307. $ios_openid = input('ios_openid','');
  1308. if (!$ios_openid) {
  1309. $this->error(__('Invalid parameters'));
  1310. }
  1311. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1312. /*if (!$user) {
  1313. $this->success('选择性别', ['code' => 5]);
  1314. }*/
  1315. if ($user) {
  1316. if (!in_array($user->status,[1,2])) {
  1317. $this->error(__('Account is locked'));
  1318. }
  1319. if ($user->frozentime > time()) {
  1320. $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
  1321. }
  1322. //如果已经有账号则直接登录
  1323. $ret = $this->auth->direct($user->id);
  1324. } else {
  1325. $reg_data = [
  1326. 'register_from' => input('register_from',''),
  1327. 'gender' => -1
  1328. ];
  1329. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1330. }
  1331. if ($ret) {
  1332. $data = $this->userInfo('return');
  1333. $this->success(__('Logged in successful'), $data);
  1334. } else {
  1335. $this->error($this->auth->getError());
  1336. }
  1337. }
  1338. //苹果账号注册
  1339. public function iosregiter(){
  1340. $ios_openid = input('ios_openid', '', 'trim');
  1341. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1342. if (!$ios_openid) {
  1343. $this->error(__('Invalid parameters'));
  1344. }
  1345. if (!in_array($gender, [1, 0])) {
  1346. $this->error('性别错误');
  1347. }
  1348. $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
  1349. if ($user) {
  1350. $this->error('账号已经存在,请直接登录');
  1351. }
  1352. $reg_data = [
  1353. 'register_from' => input('register_from',''),
  1354. 'gender' => $gender
  1355. ];
  1356. $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
  1357. if ($ret) {
  1358. $data = $this->userInfo('return');
  1359. $this->success(__('Logged in successful'), $data);
  1360. } else {
  1361. $this->error($this->auth->getError());
  1362. }
  1363. }
  1364. //注册完善资料
  1365. public function perfect_info() {
  1366. $avatar = input('avatar', '', 'trim'); //头像
  1367. $nickname = input('nickname', '', 'trim'); //昵称
  1368. $birthday = input('birthday', '', 'strtotime'); //生日
  1369. $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
  1370. $job_id = input('job_id', '', 'trim'); //职业id
  1371. $character_id = input('character_id', '', 'trim'); //性格id
  1372. $introcode = input('introcode', '', 'trim'); //邀请码
  1373. $data = [];
  1374. if ($avatar) {
  1375. $data['avatar'] = $avatar;
  1376. }
  1377. if ($nickname !== '') {
  1378. if (iconv_strlen($nickname, 'utf-8') > 10) {
  1379. $this->error('昵称最多10个字~');
  1380. }
  1381. $data['nickname'] = $nickname;
  1382. }
  1383. if ($birthday) {
  1384. $data['birthday'] = $birthday;
  1385. }
  1386. if ($hometown_cityid) {
  1387. $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
  1388. if (!$count) {
  1389. $this->error('城市不存在');
  1390. }
  1391. $data['hometown_cityid'] = $hometown_cityid;
  1392. }
  1393. if ($job_id) {
  1394. $count = Db::name('enum_job')->where('id', $job_id)->count('id');
  1395. if (!$count) {
  1396. $this->error('职业不存在');
  1397. }
  1398. $data['job_id'] = $job_id;
  1399. }
  1400. if ($character_id) {
  1401. $count = Db::name('enum_character')->where('id', $character_id)->count('id');
  1402. if (!$count) {
  1403. $this->error('性格不存在');
  1404. }
  1405. $data['character_id'] = $character_id;
  1406. }
  1407. if ($introcode && !$this->auth->intro_uid) {
  1408. /*if ($this->auth->intro_uid) {
  1409. $this->error('您已经填写过邀请人啦');
  1410. }
  1411. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1412. if(!$intro_user){
  1413. $this->error('不存在的邀请人');
  1414. }
  1415. if ($intro_user['id'] == $this->auth->id) {
  1416. $this->error('不能填写自己邀请码');
  1417. }
  1418. if ($intro_user['intro_uid'] == $this->auth->id) {
  1419. $this->error('不能填写下级邀请码');
  1420. }
  1421. $data['intro_uid'] = $intro_user['id'];
  1422. $data['invite_time'] = time();*/
  1423. $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
  1424. if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
  1425. $data['intro_uid'] = $intro_user['id'];
  1426. $data['invite_time'] = time();
  1427. }
  1428. }
  1429. // if (!$data) {
  1430. // $this->error('请输入要修改的信息');
  1431. // }
  1432. //开启事务
  1433. Db::startTrans();
  1434. $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
  1435. if($update_rs === false){
  1436. Db::rollback();
  1437. $this->error('修改失败');
  1438. }
  1439. /*if (isset($data['intro_uid'])) { //邀请人获得金币
  1440. $intro_gold = config('site.intro_gold');
  1441. if ($intro_gold > 0) {
  1442. $wallet_rs = model('wallet')->lockChangeAccountRemain($data['intro_uid'],$this->auth->id,'gold',$intro_gold,64,'邀请注册奖励','user', $this->auth->id);
  1443. if($wallet_rs['status'] === false){
  1444. Db::rollback();
  1445. $this->error($wallet_rs['msg']);
  1446. }
  1447. }
  1448. }*/
  1449. //上传头像加5金币
  1450. if(isset($data['avatar'])){
  1451. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
  1452. if($task_rs === false){
  1453. Db::rollback();
  1454. $this->error('完成任务赠送奖励失败');
  1455. }
  1456. }
  1457. if (isset($data['birthday'])) {
  1458. //完成设置生日 +5金币
  1459. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
  1460. if($task_rs === false){
  1461. Db::rollback();
  1462. $this->error('完成任务赠送奖励失败');
  1463. }
  1464. }
  1465. Db::commit();
  1466. $this->success('修改成功');
  1467. }
  1468. //实名认证
  1469. public function idcard_auth() {
  1470. $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
  1471. // if ($info && $info['status'] == 0) {
  1472. // $this->error('您已经提交信息了,请进行人脸认证!');
  1473. // }
  1474. if ($info && $info['status'] == 1) {
  1475. $this->error('您已通过审核!');
  1476. }
  1477. $nickname = input('nickname', '', 'trim'); // 姓名
  1478. $idcard = input('idcard', '', 'trim'); // 身份证号
  1479. if ($nickname === '') {
  1480. $this->error('请输入姓名');
  1481. }
  1482. if (iconv_strlen($nickname, 'utf-8') > 50) {
  1483. $this->error('请输入正确姓名');
  1484. }
  1485. if ($idcard === '') {
  1486. $this->error('请输入身份证号');
  1487. }
  1488. if (iconv_strlen($idcard, 'utf-8') != 18) {
  1489. $this->error('请输入正确身份证号');
  1490. }
  1491. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  1492. if ($count) {
  1493. $this->error('身份证号已存在');
  1494. }
  1495. $data = [];
  1496. $data['truename'] = $nickname;
  1497. $data['idcard'] = $idcard;
  1498. //腾讯云身份证二要素认证
  1499. $auth_restult = $this->userauth_tencent($idcard, $nickname);
  1500. if ($auth_restult) {
  1501. $data['status'] = 1; //通过
  1502. $msg = '认证通过';
  1503. } else {
  1504. $data['status'] = 2; //不通过
  1505. $msg = '认证不通过';
  1506. }
  1507. //开启事务
  1508. Db::startTrans();
  1509. if (!$info) { //未认证
  1510. $data["user_id"] = $this->auth->id;
  1511. $data["createtime"] = time();
  1512. $res = Db::name('user_idconfirm')->insertGetId($data);
  1513. } else { //认证被拒绝过
  1514. $data['updatetime'] = time();
  1515. $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
  1516. }
  1517. if (!$res) {
  1518. Db::rollback();
  1519. $this->error('认证失败');
  1520. }
  1521. $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
  1522. if ($rt === false) {
  1523. Db::rollback();
  1524. $this->error('认证失败');
  1525. }
  1526. if ($data['status'] == 1) {
  1527. //完成实名认证 +20金币
  1528. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
  1529. if($task_rs === false){
  1530. Db::rollback();
  1531. $this->error('完成任务赠送奖励失败');
  1532. }
  1533. //系统消息
  1534. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  1535. } else {
  1536. //系统消息
  1537. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
  1538. }
  1539. Db::commit();
  1540. $this->success($msg);
  1541. }
  1542. //腾讯云身份证二要素认证
  1543. public function userauth_tencent($idcard = '', $nickname = '') {
  1544. // require_once 'vendor/autoload.php';
  1545. try {
  1546. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  1547. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  1548. $config = config('tencent_im');
  1549. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  1550. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  1551. $httpProfile = new HttpProfile();
  1552. $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
  1553. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  1554. $clientProfile = new ClientProfile();
  1555. $clientProfile->setHttpProfile($httpProfile);
  1556. // 实例化要请求产品的client对象,clientProfile是可选的
  1557. $client = new FaceidClient($cred, "", $clientProfile);
  1558. // 实例化一个请求对象,每个接口都会对应一个request对象
  1559. $req = new IdCardVerificationRequest();
  1560. $params = array(
  1561. "IdCard" => $idcard,
  1562. "Name" => $nickname
  1563. );
  1564. $req->fromJsonString(json_encode($params));
  1565. // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
  1566. $resp = $client->IdCardVerification($req);
  1567. // 输出json格式的字符串回包
  1568. // print_r($resp->toJsonString());
  1569. $result = json_decode($resp->toJsonString(), true);
  1570. if (isset($result['Result']) && $result['Result'] == 0) {
  1571. return 1; //通过
  1572. } else {
  1573. return 0;
  1574. }
  1575. }
  1576. catch(TencentCloudSDKException $e) {
  1577. // echo $e;
  1578. return 0;
  1579. }
  1580. }
  1581. //绑定支付宝
  1582. public function addalipayaccount() {
  1583. $id = input('id', 0, 'intval'); //账号id
  1584. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1585. // $type = 1;
  1586. $realname = input('realname', '', 'trim'); //账户真实姓名
  1587. $banknumber = input('banknumber', '', 'trim'); //卡号或账号
  1588. $bankname = input('bankname', '', 'trim'); //银行名称
  1589. // if ($id) {
  1590. // $this->error('您已经拥有该类型账号,请联系后台解绑');
  1591. // }
  1592. if (!in_array($type, [1, 2])) {
  1593. $this->error('参数错误');
  1594. }
  1595. /*if ($type == 1) {
  1596. $this->error('暂不支持绑定支付宝');
  1597. }*/
  1598. if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
  1599. $this->error('账号姓名1-30位');
  1600. }
  1601. if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
  1602. $this->error('账号1-50位');
  1603. }
  1604. if ($type == 1) {
  1605. if (iconv_strlen($bankname, 'utf-8') != 18) {
  1606. $this->error('请输入正确身份证号');
  1607. }
  1608. }
  1609. if ($type == 2) {
  1610. if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
  1611. $this->error('开户行名称1-50位');
  1612. }
  1613. }
  1614. $user_bank = Db::name('user_bank');
  1615. if ($id) {
  1616. //编辑
  1617. //查询账号是否存在
  1618. $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  1619. if (!$info) {
  1620. $this->error('账号不存在');
  1621. }
  1622. if ($info['type'] != $type) {
  1623. $this->error('账号类型错误');
  1624. }
  1625. //查询是否未通过提现记录
  1626. $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
  1627. if ($count) {
  1628. $this->error('该账户有未审核的提现记录,暂不可修改');
  1629. }
  1630. $data['realname'] = $realname;
  1631. $data['banknumber'] = $banknumber;
  1632. $data['updatetime'] = time();
  1633. // if ($type == 2) {
  1634. $data['bankname'] = $bankname;
  1635. // }
  1636. $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
  1637. if ($rs === false) {
  1638. $this->error('修改失败');
  1639. }
  1640. $this->success('修改成功');
  1641. } else {
  1642. //添加
  1643. //查询是否已经拥有该类型账号
  1644. $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  1645. if ($count) {
  1646. $this->error('您已经拥有该类型账号,请联系后台解绑');
  1647. }
  1648. $data['user_id'] = $this->auth->id;
  1649. $data['type'] = $type;
  1650. $data['realname'] = $realname;
  1651. $data['banknumber'] = $banknumber;
  1652. // if ($type == 2) {
  1653. $data['bankname'] = $bankname;
  1654. // }
  1655. $data['createtime'] = time();
  1656. $rs = $user_bank->insertGetId($data);
  1657. if (!$rs) {
  1658. $this->error('添加失败');
  1659. }
  1660. $this->success('添加成功');
  1661. }
  1662. }
  1663. //查询支付宝/银行卡信息
  1664. public function alipayinfo() {
  1665. $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
  1666. $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
  1667. if (!$info) {
  1668. $info = (object)[];
  1669. }
  1670. $this->success('success', $info);
  1671. }
  1672. //申请真人认证
  1673. public function realauth() {
  1674. if ($this->auth->real_status == 1) {
  1675. $this->error('您已经真人认证过了~');
  1676. }
  1677. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  1678. $this->error('请先上传真人头像~');
  1679. }
  1680. //获取token
  1681. $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';
  1682. $token_result = file_get_contents($token_url);
  1683. if (!$token_result) {
  1684. $this->error('您的网络开小差啦1~');
  1685. }
  1686. $token_result = json_decode($token_result, true);
  1687. if ($token_result['code'] != 0) {
  1688. $this->error('您的网络开小差啦2~');
  1689. }
  1690. $token = $token_result['access_token'];
  1691. //获取签名鉴权参数ticket
  1692. $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';
  1693. $ticket_result = file_get_contents($ticket_url);
  1694. if (!$ticket_result) {
  1695. $this->error('您的网络开小差啦3~');
  1696. }
  1697. $ticket_result = json_decode($ticket_result, true);
  1698. if ($ticket_result['code'] != 0) {
  1699. $this->error('您的网络开小差啦4~');
  1700. }
  1701. $ticket = $ticket_result['tickets'][0]['value'];
  1702. //获取签名
  1703. $sign_data = [
  1704. 'wbappid' => config('tencent_yun')['secret_id'],
  1705. 'userId' => (string)$this->auth->id,
  1706. 'version' => '1.0.0',
  1707. 'ticket' => $ticket,
  1708. 'nonce' => Random::alnum(32)
  1709. ];//p($sign_data);
  1710. asort($sign_data); //p($sign_data);//排序
  1711. $sign_string = join('', $sign_data);//p($sign_string);
  1712. $sign = sha1($sign_string);//p($sign);
  1713. //上传身份信息
  1714. $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
  1715. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  1716. $avatar = one_domain_image($this->auth->avatar);
  1717. $avatar = str_replace('https', 'http', $avatar);
  1718. $img = file_get_contents($avatar);
  1719. $img = str_replace('data:image/jpg;base64', '', $img);
  1720. $img = str_replace('\n', '', $img);
  1721. $sourcePhotoStr = base64_encode($img);
  1722. $data = [
  1723. 'webankAppId' => config('tencent_yun')['secret_id'],
  1724. 'orderNo' => $orderNo,
  1725. 'userId' => (string)$this->auth->id,
  1726. 'sourcePhotoStr' => $sourcePhotoStr,
  1727. 'sourcePhotoType' => 2,
  1728. 'version' => '1.0.0',
  1729. 'sign' => $sign,
  1730. 'nonce' => $sign_data['nonce']
  1731. ];
  1732. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1733. if (!$rs) {
  1734. $this->error('您的网络开小差啦5~');
  1735. }
  1736. $rs = json_decode($rs, true);
  1737. if (!$rs || $rs['code'] != 0) {
  1738. $this->error('您的网络开小差啦6~');
  1739. }
  1740. $user_auth = [
  1741. 'user_id' => $this->auth->id,
  1742. 'certify_id' => $rs['result']['faceId'],
  1743. 'out_trade_no' => $data['orderNo'],
  1744. 'status' => 0,
  1745. 'createtime' => time(),
  1746. 'updatetime' => time()
  1747. ];
  1748. //开启事务
  1749. Db::startTrans();
  1750. //查询是否认证过
  1751. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1752. if ($info) {
  1753. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  1754. } else {
  1755. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  1756. }
  1757. if (!$auth_rs) {
  1758. Db::rollback();
  1759. $this->error('您的网络开小差啦7~');
  1760. }
  1761. //修改用户表认证状态
  1762. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  1763. if ($user_rs === false) {
  1764. Db::rollback();
  1765. $this->error('您的网络开小差啦8~');
  1766. }
  1767. Db::commit();
  1768. $return_data = [
  1769. 'face_id' => $user_auth['certify_id'],
  1770. 'order_no' => $user_auth['out_trade_no'],
  1771. 'user_id' => (string)$this->auth->id,
  1772. 'nonce' => $sign_data['nonce'],
  1773. 'sign' => $sign
  1774. ];
  1775. $this->success('success', $return_data);
  1776. }
  1777. //查询真人认证结果
  1778. public function getrealauthresult() {
  1779. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  1780. if (!$user_auth) {
  1781. $this->success('尚未认证');
  1782. }
  1783. if ($user_auth['status'] == 1) {
  1784. $this->success('真人认证通过');
  1785. }
  1786. if (!$user_auth['certify_id']) {
  1787. $this->success('请先进行真人认证');
  1788. }
  1789. //获取token
  1790. $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';
  1791. $token_result = file_get_contents($token_url);
  1792. if (!$token_result) {
  1793. $this->error('您的网络开小差啦1~');
  1794. }
  1795. $token_result = json_decode($token_result, true);
  1796. if ($token_result['code'] != 0) {
  1797. $this->error('您的网络开小差啦2~');
  1798. }
  1799. $token = $token_result['access_token'];
  1800. //获取签名鉴权参数ticket
  1801. $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';
  1802. $ticket_result = file_get_contents($ticket_url);
  1803. if (!$ticket_result) {
  1804. $this->error('您的网络开小差啦3~');
  1805. }
  1806. $ticket_result = json_decode($ticket_result, true);
  1807. if ($ticket_result['code'] != 0) {
  1808. $this->error('您的网络开小差啦4~');
  1809. }
  1810. $ticket = $ticket_result['tickets'][0]['value'];
  1811. //获取签名
  1812. $sign_data = [
  1813. 'wbappid' => config('tencent_yun')['secret_id'],
  1814. 'orderNo' => $user_auth['out_trade_no'],
  1815. 'version' => '1.0.0',
  1816. 'ticket' => $ticket,
  1817. 'nonce' => Random::alnum(32)
  1818. ];//p($sign_data);
  1819. asort($sign_data); //p($sign_data);//排序
  1820. $sign_string = join('', $sign_data);//p($sign_string);
  1821. $sign = sha1($sign_string);//p($sign);
  1822. //人脸核身结果查询
  1823. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  1824. $data = [
  1825. 'appId' => config('tencent_yun')['secret_id'],
  1826. 'version' => '1.0.0',
  1827. 'nonce' => $sign_data['nonce'],
  1828. 'orderNo' => $user_auth['out_trade_no'],
  1829. 'sign' => $sign
  1830. ];
  1831. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  1832. if (!$rs) {
  1833. $this->error('您的网络开小差啦5~');
  1834. }
  1835. $rs = json_decode($rs, true);
  1836. if (!$rs || $rs['code'] != 0) {
  1837. $this->error($rs['msg']);
  1838. }
  1839. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  1840. $edit_data['status'] = 1;
  1841. $msg = '真人认证成功';
  1842. } else {
  1843. $edit_data['status'] = 2;
  1844. $edit_data['certify_id'] = '';
  1845. $edit_data['out_trade_no'] = '';
  1846. $msg = '真人认证失败';
  1847. }
  1848. $edit_data['updatetime'] = time();
  1849. //开启事务
  1850. Db::startTrans();
  1851. //修改认证信息
  1852. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  1853. if (!$result) {
  1854. Db::rollback();
  1855. $this->error('查询认证结果失败2');
  1856. }
  1857. //修改用户信息
  1858. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  1859. if (!$rs) {
  1860. Db::rollback();
  1861. $this->error('查询认证结果失败3');
  1862. }
  1863. if ($edit_data['status'] == 1) { //通过
  1864. //tag任务赠送金币
  1865. //真人认证奖励
  1866. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
  1867. if($task_rs === false){
  1868. Db::rollback();
  1869. $this->error('完成任务赠送奖励失败');
  1870. }
  1871. //系统消息
  1872. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  1873. } else {
  1874. //系统消息
  1875. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  1876. }
  1877. Db::commit();
  1878. $this->success($msg);
  1879. }
  1880. //客服
  1881. public function kefu() {
  1882. $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
  1883. if (!in_array($type, [0, 1])) {
  1884. $this->error('您的网络开小差啦~');
  1885. }
  1886. if ($type == 0) {
  1887. $user_id = config('site.customer_service_id') ? : 0; //指定客服id
  1888. } else {
  1889. $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
  1890. }
  1891. $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
  1892. if (!$list) {
  1893. $this->success('success', $list);
  1894. }
  1895. foreach ($list as $k => &$v) {
  1896. $v['nickname'] = '客服' . ($k + 1);
  1897. $v['avatar'] = config('avatar_girl');
  1898. }
  1899. $this->success('success', $list);
  1900. }
  1901. //海报背景图
  1902. public function posterlist() {
  1903. $list = config('site.intro_images');
  1904. if (!$list) {
  1905. $this->success('success', (object)[]);
  1906. }
  1907. foreach ($list as &$v) {
  1908. $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
  1909. }
  1910. $this->success('success', $list);
  1911. }
  1912. //生成海报
  1913. public function createposter($image = '') {
  1914. // $image = input('image', '', 'trim');
  1915. // if (!$image) {
  1916. // $this->error('您的网络开小差啦~');
  1917. // }
  1918. $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
  1919. return $haibao;
  1920. // $this->success('success', $haibao);
  1921. }
  1922. //注册设置性别
  1923. public function setgender() {
  1924. $user_id = $this->auth->id;
  1925. /*if (in_array($user_id, [0, 1])) {
  1926. $this->error('性别不能修改~');
  1927. }*/
  1928. $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
  1929. if (!in_array($gender, [1, 0])) {
  1930. $this->error('性别错误');
  1931. }
  1932. $edit_data['gender'] = $gender;
  1933. $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
  1934. $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
  1935. if (!$rs) {
  1936. $this->error('您的网络开小差啦~');
  1937. }
  1938. $data = $this->userInfo('return');
  1939. $data['gender'] = $edit_data['gender'];
  1940. $data['avatar'] = $edit_data['avatar'];
  1941. // $this->success('success', $data);
  1942. // 如果是女用户,则停止账户使用
  1943. if ($gender == 0){
  1944. Db::name('user')->where('id',$user_id)->update(['status'=>0,'is_closed'=>1]);//金庸
  1945. Db::name('user_token')->where('user_id',$user_id)->delete();//金庸
  1946. }
  1947. //领取任务奖励
  1948. $task_id = 22; // 任务ID
  1949. // 查询任务信息
  1950. $taskInfo = $this->taskModel->where(["id"=>$task_id])->find();
  1951. if(!$taskInfo) {
  1952. // $this->error("任务信息未找到!");
  1953. $this->success('success', $data);
  1954. }
  1955. // 查询用户完成情况
  1956. $where = [];
  1957. $where["user_id"] = $user_id;
  1958. $where["task_id"] = $task_id;
  1959. $where["is_finish"] = 1;
  1960. if($taskInfo["type_id"] == 2){
  1961. $where["finish_date"] = date("Ymd");
  1962. }
  1963. $tasklogInfo = $this->tasklogModel->where($where)->find();
  1964. if(!$tasklogInfo) {
  1965. // $this->error("任务还未完成哦!");
  1966. $this->success('success', $data);
  1967. }
  1968. if($tasklogInfo["is_reward"] == 1) {
  1969. // $this->error("任务奖励已领取,请勿重复领取!");
  1970. $this->success('success', $data);
  1971. }
  1972. Db::startTrans();
  1973. // 增加用户经验值
  1974. //$res1 = \app\common\model\User::addEmpirical($user_id,$taskInfo["exp"]);
  1975. $res1['status'] = true;
  1976. if ($gender == 1) {
  1977. //男用户获得金币
  1978. $res1 = model('wallet')->lockChangeAccountRemain($user_id,0, 'gold', $taskInfo["exp"], 61, '完成' . $taskInfo['name'] . '任务', 'task_log', $tasklogInfo['id']);
  1979. if ($res1['status'] === false) {
  1980. Db::rollback();
  1981. // $this->error($res1['msg']);
  1982. $this->success('success', $data);
  1983. }
  1984. } elseif ($gender == 0) {
  1985. $bili = config('site.money_to_gold'); //钱和金币兑换比例
  1986. if ($bili > 0) {
  1987. //女用户获得钱
  1988. $money = bcdiv($taskInfo['exp'], $bili, 2);
  1989. if ($money > 0) {
  1990. $res1 = model('wallet')->lockChangeAccountRemain($user_id,0, 'money', $money, 67, '完成' .$taskInfo['name'] . '任务', 'task_log', $tasklogInfo['id']);
  1991. if ($res1['status'] === false) {
  1992. Db::rollback();
  1993. // $this->error($res1['msg']);
  1994. $this->success('success', $data);
  1995. }
  1996. }
  1997. }
  1998. }
  1999. // 更新奖励领取状态
  2000. $res2 = $this->tasklogModel->update(["is_reward"=>1],["task_id"=>$task_id,"user_id"=>$user_id]);
  2001. //系统消息
  2002. $msg_id = \app\common\model\Message::addMessage($user_id,'任务奖励','完成' . $taskInfo['name'] . '任务,获得任务奖励');
  2003. if($res1['status'] === true && $res2) {
  2004. Db::commit();
  2005. // $this->success("领取成功!");
  2006. $this->success('success', $data);
  2007. } else {
  2008. Db::rollback();
  2009. // $this->error("领取失败!");
  2010. $this->success('success', $data);
  2011. }
  2012. }
  2013. //真人认证后修改头像前比对
  2014. public function realavatar_auit() {
  2015. if ($this->auth->real_status != 1) {
  2016. $this->error('尚未通过真人认证');
  2017. }
  2018. $avatar = input('avatar', '', 'trim'); //头像地址
  2019. if ($avatar === '') {
  2020. $this->error('参数缺失');
  2021. }
  2022. $avatar = one_domain_image($avatar);
  2023. $now_avatar = one_domain_image($this->auth->avatar);
  2024. if ($avatar == $now_avatar) {
  2025. $this->error('头像未改变');
  2026. }
  2027. //腾讯云人脸识别
  2028. $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  2029. $this->success('结果', $result);
  2030. }
  2031. //真人认证后修改头像
  2032. public function editrealavatar() {
  2033. if ($this->auth->real_status != 1) {
  2034. $this->error('尚未通过真人认证');
  2035. }
  2036. $avatar = input('avatar', '', 'trim'); //头像地址
  2037. if ($avatar === '') {
  2038. $this->error('参数缺失');
  2039. }
  2040. $avatar = one_domain_image($avatar);
  2041. $now_avatar = one_domain_image($this->auth->avatar);
  2042. if ($avatar == $now_avatar) {
  2043. $this->error('头像未改变');
  2044. }
  2045. //腾讯云人脸识别
  2046. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  2047. if ($auit_result != 1) {
  2048. $this->success('提示', ['code' => 2]);
  2049. }
  2050. $data['avatar'] = $avatar;
  2051. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  2052. if (!$user_result) {
  2053. $this->error('修改失败');
  2054. }
  2055. $this->success('修改成功');
  2056. }
  2057. //真人认证后修改头像并取消真人认证
  2058. public function editrealavatarcancelauit() {
  2059. if ($this->auth->real_status != 1) {
  2060. $this->error('尚未通过真人认证');
  2061. }
  2062. $avatar = input('avatar', '', 'trim'); //头像地址
  2063. if ($avatar === '') {
  2064. $this->error('参数缺失');
  2065. }
  2066. $avatar = one_domain_image($avatar);
  2067. $now_avatar = one_domain_image($this->auth->avatar);
  2068. if ($avatar == $now_avatar) {
  2069. $this->error('头像未改变');
  2070. }
  2071. $data['avatar'] = $avatar;
  2072. $data['real_status'] = -1;
  2073. //开启事务
  2074. Db::startTrans();
  2075. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  2076. if (!$user_result) {
  2077. Db::rollback();
  2078. $this->error('修改失败');
  2079. }
  2080. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  2081. if (!$user_auth_result) {
  2082. Db::rollback();
  2083. $this->error('修改失败');
  2084. }
  2085. Db::commit();
  2086. $this->success('修改成功');
  2087. }
  2088. //腾讯云人脸识别
  2089. public function face_tencent($urla = '', $urlb = '') {
  2090. // require_once 'vendor/autoload.php';
  2091. try {
  2092. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  2093. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  2094. $config = config('tencent_im');
  2095. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  2096. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  2097. $httpProfile = new HttpProfile();
  2098. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  2099. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  2100. $clientProfile = new ClientProfile();
  2101. $clientProfile->setHttpProfile($httpProfile);
  2102. // 实例化要请求产品的client对象,clientProfile是可选的
  2103. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  2104. // 实例化一个请求对象,每个接口都会对应一个request对象
  2105. $req = new CompareFaceRequest();
  2106. $params = array(
  2107. "UrlA" => $urla,
  2108. "UrlB" => $urlb,
  2109. "FaceModelVersion" => "3.0"
  2110. );
  2111. $req->fromJsonString(json_encode($params));
  2112. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  2113. $resp = $client->CompareFace($req);
  2114. // 输出json格式的字符串回包
  2115. // print_r($resp->toJsonString());
  2116. $result = json_decode($resp->toJsonString(), true);
  2117. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  2118. if (isset($result['Score']) && $result['Score'] >= 60) {
  2119. return 1; //通过
  2120. } else {
  2121. return 0;
  2122. }
  2123. }
  2124. catch(TencentCloudSDKException $e) {
  2125. // echo $e;
  2126. return 0;
  2127. }
  2128. }
  2129. //修改城市
  2130. public function editcity() {
  2131. $name = input('name', '', 'trim'); //城市名
  2132. if ($name === '') {
  2133. $this->error('参数缺失');
  2134. }
  2135. $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
  2136. if (!$hometown_cityid) {
  2137. $this->success('修改成功');
  2138. }
  2139. Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
  2140. $this->success('修改成功');
  2141. }
  2142. //搜索用户
  2143. public function searchuser() {
  2144. $keyword = input('keyword', '', 'trim'); //昵称或ID
  2145. if ($keyword === '') {
  2146. $this->error('请输入关键字');
  2147. }
  2148. $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
  2149. $id = $id ? : 0;
  2150. $this->success('用户', $id);
  2151. }
  2152. //绑定支付宝账号信息
  2153. public function bindalipayaccount() {
  2154. $mt_user_bank = Db::name('user_bank');
  2155. $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
  2156. if ($count) {
  2157. $this->error('您已绑定支付宝啦');
  2158. }
  2159. $auth_code = input('auth_code', '', 'trim');
  2160. if (!$auth_code) {
  2161. $this->error('授权码缺失');
  2162. }
  2163. //获取支付宝用户信息
  2164. $rs = getAlipayInfo($auth_code);
  2165. if ($rs['status'] == 0) {
  2166. $this->error($rs['info']);
  2167. }
  2168. $rs = $rs['data'];
  2169. /*
  2170. * Array(
  2171. [alipay_user_info_share_response] => Array
  2172. (
  2173. [code] => 10000
  2174. [msg] => Success
  2175. [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
  2176. [city] => 临沂市 市名称。
  2177. [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
  2178. [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
  2179. [is_student_certified] => F 是否是学生 T是 F否
  2180. [nick_name] => 风的追求 用户昵称
  2181. [province] => 山东省 省份名称
  2182. [user_id] => 2088902918001020 支付宝用户的userId
  2183. [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
  2184. [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
  2185. )
  2186. )
  2187. */
  2188. $data['banknumber'] = $rs['user_id']; //支付宝用户id
  2189. if (!$data['banknumber']) {
  2190. $this->error('获取用户信息失败');
  2191. }
  2192. $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
  2193. if ($bank_number_count) {
  2194. $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
  2195. }
  2196. if (isset($rs['nick_name'])) {
  2197. $data['realname'] = $rs['nick_name']; //支付宝用户昵称
  2198. }
  2199. $data['user_id'] = $this->auth->id;
  2200. $data['createtime'] = time();
  2201. $data['type'] = 1;
  2202. $rt = $mt_user_bank->insertGetId($data);
  2203. if (!$rt) {
  2204. $this->error('绑定失败');
  2205. }
  2206. $this->success('绑定成功');
  2207. }
  2208. //添加打招呼内容
  2209. public function addgreetcontent() {
  2210. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
  2211. $title = input('title', '', 'trim'); //标题(type=1必传)
  2212. $content = input('content', '', 'trim'); //内容
  2213. $duration = input('duration', 0, 'intval'); //时长(type=1必传)
  2214. if (!in_array($type, [0, 1, 2])) {
  2215. $this->error('您的网络开小差了');
  2216. }
  2217. if ($content === '') {
  2218. $this->error('请设置打招呼内容');
  2219. }
  2220. if (iconv_strlen($content, 'utf-8') > 255) {
  2221. $this->error('打招呼内容最多255位');
  2222. }
  2223. if ($type == 1) {
  2224. if ($title === '') {
  2225. $this->error('请输入语音名称');
  2226. }
  2227. if (iconv_strlen($title, 'utf-8') > 50) {
  2228. $this->error('语音名称最多50字');
  2229. }
  2230. if (!$duration) {
  2231. $this->error('参数缺失');
  2232. }
  2233. }
  2234. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
  2235. if ($count > 10) {
  2236. $this->error('同一类型打招呼最多设置10条');
  2237. }
  2238. $data['user_id'] = $this->auth->id;
  2239. $data['type'] = $type;
  2240. $data['content'] = $content;
  2241. if ($type == 1) {
  2242. $data['title'] = $title;
  2243. $data['duration'] = $duration;
  2244. }
  2245. $data['createtime'] = time();
  2246. //查询是否有默认打招呼内容
  2247. $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
  2248. if (!$default_greet_count) {
  2249. $data['is_default'] = 1;
  2250. }
  2251. $rs = Db::name('user_greet_content')->insertGetId($data);
  2252. if (!$rs) {
  2253. $this->error('您的网络开小差了');
  2254. }
  2255. $this->success('设置成功');
  2256. }
  2257. //查询打招呼内容
  2258. public function getgreetcontent() {
  2259. $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
  2260. if (!in_array($type, [0, 1, 2, 3])) {
  2261. $this->error('您的网络开小差了');
  2262. }
  2263. if ($type == 3) {
  2264. $list = Db::name('user_greet_content')->where(function ($query) {
  2265. $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
  2266. })->whereOr(function ($query) {
  2267. $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
  2268. })->select();
  2269. } else {
  2270. $where['user_id'] = $this->auth->id;
  2271. $where['type'] = $type;
  2272. $list = Db::name('user_greet_content')->where($where)->select();
  2273. }
  2274. if ($list) {
  2275. foreach ($list as &$v) {
  2276. if ($v['type'] != 0) {
  2277. $v['content'] = one_domain_image($v['content']);
  2278. }
  2279. }
  2280. }
  2281. $this->success('打招呼内容', $list);
  2282. }
  2283. //设置默认打招呼内容
  2284. public function setdefaultgreet() {
  2285. $id = input('id', 0, 'intval'); //打招呼id
  2286. if (!$id) {
  2287. $this->error('您的网络开小差了');
  2288. }
  2289. $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
  2290. if (!$count) {
  2291. $this->error('您的网络开小差了');
  2292. }
  2293. //开启事务
  2294. Db::startTrans();
  2295. //清除之前默认
  2296. $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
  2297. if ($rs === false) {
  2298. Db::rollback();
  2299. $this->error('您的网络开小差了');
  2300. }
  2301. //设置
  2302. $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
  2303. if ($rt === false) {
  2304. Db::rollback();
  2305. $this->error('您的网络开小差了');
  2306. }
  2307. Db::commit();
  2308. $this->success('设置成功');
  2309. }
  2310. //删除打招呼内容
  2311. public function deldefaultgreet() {
  2312. $id = input('id', 0, 'intval'); //打招呼id
  2313. if (!$id) {
  2314. $this->error('您的网络开小差了');
  2315. }
  2316. $mt_user_greet_content = Db::name('user_greet_content');
  2317. $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
  2318. if (!$info) {
  2319. $this->error('您的网络开小差了');
  2320. }
  2321. //开启事务
  2322. Db::startTrans();
  2323. //删除
  2324. $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
  2325. if ($rs === false) {
  2326. Db::rollback();
  2327. $this->error('您的网络开小差了');
  2328. }
  2329. //若为默认打招呼内容则重新设置一条
  2330. if ($info['is_default'] == 1) {
  2331. $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
  2332. if ($first_greet) {
  2333. $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
  2334. if ($rt === false) {
  2335. Db::rollback();
  2336. $this->error('您的网络开小差了');
  2337. }
  2338. }
  2339. }
  2340. Db::commit();
  2341. $this->success('删除成功');
  2342. }
  2343. }