User.php 77 KB

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