User.php 94 KB

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