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