123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use fast\Random;
- use think\Config;
- use think\Validate;
- use app\common\library\Token;
- use think\Db;
- use app\common\model\UserDeviceInfo;
- use onlogin\onlogin;
- use addons\epay\library\Service;
- use app\common\library\Wechat;
- use TencentCloud\Common\Credential;
- use TencentCloud\Common\Profile\ClientProfile;
- use TencentCloud\Common\Profile\HttpProfile;
- use TencentCloud\Common\Exception\TencentCloudSDKException;
- use TencentCloud\Faceid\V20180301\FaceidClient;
- use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
- use TencentCloud\Iai\V20200303\IaiClient;
- use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin','wechatbindmobile', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig', 'mobileregister', 'mobilecheck', 'wechatregiter', 'onregister', 'ioslogin', 'iosregiter'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- if (!Config::get('fastadmin.usercenter')) {
- $this->error(__('User center already closed'));
- }
- }
-
- public function index()
- {
- $this->success('', ['welcome' => $this->auth->nickname]);
- }
-
- public function getmeiyan()
- {
- $code = Db::name('Config')->where(['name'=>'meiyan'])->value('value');
- $rs['code'] = $code;
- $this->success('请求成功',$code);
- }
-
- public function login()
- {
- $account = input('account');
- $password = input('password');
- if (!$account || !$password) {
- $this->error(__('Invalid parameters'));
- }
- $ret = $this->auth->login($account, $password);
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function mobilelogin()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == -1) {
- $this->error('账户已注销');
- }
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
-
- $ret = $this->auth->direct($user->id);
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function mobilecheck()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $this->success('验证通过');
- }
-
- public function mobileregister()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- $gender = input('gender', -1, 'intval');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- if ($user->status == -1) {
- $this->error('账户已注销');
- }
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
-
- $ret = $this->auth->direct($user->id);
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => $gender
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function onLogin()
- {
- $accessToken = input('accessToken');
- $token = input('tokenT');
- if (!$accessToken || !$token) {
- $this->error("参数获取失败!");
- }
- $params = array(
-
- "accessToken" => $accessToken,
-
- "token" => $token
- );
-
- $configInfo = config("onLogin");
- $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
- $onret = $onlogin->check($params);
- if ($onret["code"] == 200) {
- $mobile = $onret["data"]["phone"];
- if (empty($mobile)) {
-
- $this->error("取号登录失败,请用验证码方式登录!");
- } else {
-
-
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
-
- $ret = $this->auth->direct($user->id);
- $is_register = 0;
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- $is_register = 1;
- }
- if ($ret) {
- $this->success(__('Logged in successful'), $this->auth->getUserinfo());
- } else {
- $this->error($this->auth->getError());
- }
-
- }
- } else {
- $this->error("登录失败,请用验证码方式登录!");
- }
- }
-
- public function onregister()
- {
- $accessToken = input('accessToken');
- $token = input('tokenT');
- $gender = input('gender', -1, 'intval');
- if (!$accessToken || !$token) {
- $this->error("参数获取失败!");
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $params = array(
-
- "accessToken" => $accessToken,
-
- "token" => $token
- );
-
- $configInfo = config("onLogin");
- $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
- $onret = $onlogin->check($params);
- if ($onret["code"] == 200) {
- $mobile = $onret["data"]["phone"];
- if (empty($mobile)) {
-
- $this->error("取号登录失败,请用验证码方式登录!");
- } else {
-
-
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
-
- $ret = $this->auth->direct($user->id);
- $is_register = 0;
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => $gender
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- $is_register = 1;
- }
-
- if ($ret) {
- $this->success(__('Logged in successful'), $this->auth->getUserinfo());
- } else {
- $this->error($this->auth->getError());
- }
-
- }
- } else {
- $this->error("登录失败,请用验证码方式登录!");
- }
- }
-
- public function userInfo($type = 1){
- $info = $this->auth->getUserinfo();
- if($type == 'return'){
- return $info;
- }
- $this->success(__('success'),$info);
- }
-
- public function wechatlogin(){
- $code = input('code','');
- if(!$code){
- $this->error(__('Invalid parameters'));
- }
-
- $wechat = new Wechat();
- $wxuserinfo = $wechat->getAccessToken($code);
- if(!$wxuserinfo){
- $this->error('openid获取失败');
- }
- if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
- $this->error('openid获取失败');
- }
- $openid = $wxuserinfo['openid'];
-
- $user = Db::name('user')->where('wechat_openid',$openid)->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
-
- $ret = $this->auth->direct($user['id']);
- if ($ret) {
- $userInfo = $this->auth->getUserinfo();
- $userInfo['is_register'] = 0;
- $userInfo['code'] = $code;
- $this->success(__('Logged in successful'), $userInfo);
- } else {
- $this->error($this->auth->getError());
- }
- } else {
-
- $wechatCodeData = [
- 'code' => $code,
- 'openid' => $openid,
- 'createtime' => time(),
- ];
- $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
- if (empty($wechatCode)) {
- Db::name('wechat_code')->insertGetId($wechatCodeData);
- } else {
- Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
- }
-
- $userInfo = [];
- $userInfo['is_register'] = 1;
- $userInfo['code'] = $code;
- $this->success('获取信息成功', $userInfo);
- }
- }
-
- public function wechatbindmobile()
- {
- $mobile = $this->request->param('mobile');
- $captcha = $this->request->param('captcha');
- $code = $this->request->param('code');
- if (!$mobile || !$captcha || !$code) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $wechatCodeWhere['code'] = $code;
- $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
- if (empty($wechatCode)) {
- $this->error('请先微信登录');
- }
-
- $user = Db::name('user')->where('wechat_openid',$wechatCode['openid'])->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
-
- $ret = $this->auth->direct($user['id']);
- $this->success('success',$this->auth->getUserinfo());
- }
-
- $where = [];
- $where['mobile'] = $mobile;
- $userData = Db::name('user')->where($where)->find();
- if (!empty($userData)) {
- if (empty($userData['wechat_openid'])) {
- Db::name('user')->where('id',$userData['id'])->update(['wechat_openid' => $wechatCode['openid']]);
- } else {
- if ($userData['wechat_openid'] != $wechatCode['openid']) {
- $this->error('该手机号已被其他用户绑定');
- }
- }
- $ret = $this->auth->direct($userData['id']);
- } else {
- $extend = [
- 'wechat_openid' => $wechatCode['openid'],
- ];
- $ret = $this->auth->register('', '','', $mobile, $extend);
- }
- if (!$ret) {
- $this->error($this->auth->getError());
- }
- $this->success('success',$this->auth->getUserinfo());
- }
-
- public function testhaibao(){
- $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
- $this->success('success', $haibao);
- }
-
- public function haibao($player_id,$data){
-
- $params = [
- 'text' => config('site.domain_name').'?code=' . $data['introcode'],
- 'size' => 90,
- 'logo' => false,
- 'label' => false,
- 'padding' => 0,
- ];
- $qrCode = \addons\qrcode\library\Service::qrcode($params);
- $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
- mk_dir($qrcode_path);
- $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
- $qrCode->writeFile($download_qrcode);
-
- $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
- return $haibao;
- }
-
- public function createhaibao($download_qrcode,$player_id,$sub_data){
-
- $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
- $data = [
- [
- "left" => "15px",
- "top" => "296px",
- "type" => "img",
- "width" => "58px",
- "height" => "58px",
- "src" => one_domain_image($this->auth->avatar)
- ],
- [
- "left" => "81px",
- "top" => "300px",
- "type" => "nickname",
- "width" => "80px",
- "height" => "24px",
- "size" => "12px",
- "color" => "#000",
- "content" => $this->auth->nickname
- ],
- [
- "left" => "81px",
- "top" => "327px",
- "type" => "nickname",
- "width" => "80px",
- "height" => "24px",
- "size" => "12px",
- "color" => "#000",
- "content" => $this->auth->introcode
- ],
- [
- "left" => "227px",
- "top" => "283px",
- "type" => "img",
- "width" => "80px",
- "height" => "80px",
- "src" => $download_qrcode
- ]
- ];
- $data = json_encode($data, 320);
- $poster = [
- 'id' => 1,
- 'title' => '测试2',
- 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
- 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
- 'data' => $data,
- 'status' => 'normal',
- 'weigh' => 0,
- 'createtime' => 1653993709,
- 'updatetime' => 1653994259,
- ];
- $image = new \addons\poster\library\Image();
- $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
- if (!$imgurl) {
- $this->error('生成海报出错');
- }
- return '/' . $imgurl;
- }
-
- public function idcard_confirm_info(){
- $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
- if (!$check) {
- $check = (object)[];
- }
- $this->success('success',$check);
- }
-
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $tenIm = new Tenim();
- $tenIm->loginoutim($this->auth->id);
-
- Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
-
- public function profile()
- {
- $field_array = ['nickname','introcode','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'];
- $data = [];
- foreach($field_array as $key => $field){
- if(!input('?'.$field)){
- continue;
- }
- $newone = input($field);
- if($field == 'avatar'){
-
-
-
-
- $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
- }
- if($field == 'photo_images'){
- $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
- }
- $data[$field] = $newone;
- }
- if(isset($data['birthday'])){
- $data['birthday'] = strtotime($data['birthday']);
- }
- if(isset($data['avatar'])){
-
- }
- if(isset($data['hobby_ids'])){
- $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
- }
- if(isset($data['tag_ids'])){
- $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
- }
- if(isset($data['introcode'])){
- if ($this->auth->intro_uid != 0) {
- $this->error('邀请人不可修改~');
- }
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
- if(!$intro_user){
- $this->error('不存在的邀请人');
- }
- if ($intro_user['id'] == $this->auth->id) {
- $this->error('不能填写自己邀请码');
- }
- if ($intro_user['intro_uid'] == $this->auth->id) {
- $this->error('不能填写下级邀请码');
- }
- unset($data['introcode']);
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();
- }
-
- if(empty($data)){
- $this->error('没有任何改变');
- }
- Db::startTrans();
- $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
- if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {
- $boyAvatar = config('avatar_boy');
- $girlAvatar = config('avatar_girl');
- if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
- $data['status'] = 1;
- } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
- $data['status'] = 1;
- }
- }
- $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改资料失败');
- }
-
- if(isset($data['intro_uid'])){
- $intro_jewel = config('site.new_user_intro_jewel');
- if($intro_jewel > 0){
- $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
- if($rs_wallet['status'] === false){
- Db::rollback();
- $this->error('邀请新人奖励赠送失败');
- }
- }
- }
-
-
- if(isset($data['avatar'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if (isset($data['birthday'])) {
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if(isset($data['audio_bio'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if(isset($data['audio_bio'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if(isset($data['photo_images'])){
- $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
- if ($photo_images_num >= 5) {
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
- if ($task_rs === false) {
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- }
- Db::commit();
- $this->success();
- }
-
- public function change_longlat(){
- $longitude = input_post('longitude');
- $latitude = input_post('latitude');
- $cityname = input_post('cityname');
- if(empty($longitude) || empty($latitude) || empty($cityname)){
- $this->error();
- }
- $data = [
- 'longitude' => $longitude,
- 'latitude' => $latitude,
- 'cityname' => $cityname,
- ];
- Db::name('user')->where('id',$this->auth->id)->update($data);
- $this->success();
- }
-
- public function changemobile()
- {
- $user = $this->auth->getUser();
- $oldcaptcha = $this->request->request('oldcaptcha');
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- if (!$oldcaptcha || !$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if($user->mobile == $mobile){
- $this->error('新手机号不能与旧手机号相同');
- }
- if (\app\common\model\User::where('mobile', $mobile)->find()) {
- $this->error(__('Mobile already exist'));
- }
- $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $verification = $user->verification;
- $verification->mobile = 1;
- $user->verification = $verification;
- $user->mobile = $mobile;
- $user->save();
- Sms::flush($user->mobile, 'changemobile');
- Sms::flush($mobile, 'changemobile');
- $this->success();
- }
-
- public function bindmobile()
- {
- $user = $this->auth->getUser();
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- if(!empty($this->auth->mobile)){
- $this->error('已经绑定了手机号');
- }
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (\app\common\model\User::where('mobile', $mobile)->find()) {
- $this->error('该手机号已被其他用户绑定');
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $verification = $user->verification;
- $verification->mobile = 1;
- $user->verification = $verification;
- $user->mobile = $mobile;
- $user->save();
- Sms::flush($mobile, 'changemobile');
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
- if($task_rs === false){
- Db::rollback();
- return false;
- }
- $this->success('success',$this->userInfo('return'));
- }
-
- public function bindopenid()
- {
- $user = $this->auth->getUser();
- $wechat_openid = $this->request->request('wechat_openid');
- if(!empty($this->auth->wechat_openid)){
- $this->error('已经绑定了微信号');
- }
- if (!$wechat_openid) {
- $this->error(__('Invalid parameters'));
- }
- if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
- $this->error('该微信号已被其他用户绑定');
- }
- $user->wechat_openid = $wechat_openid;
- $user->save();
- $this->success('success',$this->userInfo('return'));
- }
-
- public function resetpwd()
- {
-
- $type = 'mobile';
- $mobile = input("mobile");
- $email = input("email");
- $newpassword = input("newpassword");
- $captcha = input("captcha");
- if (!$newpassword || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if ($type == 'mobile') {
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if (!$user) {
- $this->error(__('User not found'));
- }
- $ret = Sms::check($mobile, $captcha, 'resetpwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- Sms::flush($mobile, 'resetpwd');
- } else {
- if (!Validate::is($email, "email")) {
- $this->error(__('Email is incorrect'));
- }
- $user = \app\common\model\User::getByEmail($email);
- if (!$user) {
- $this->error(__('User not found'));
- }
- $ret = Ems::check($email, $captcha, 'resetpwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- Ems::flush($email, 'resetpwd');
- }
-
- $this->auth->direct($user->id);
- $ret = $this->auth->changepwd($newpassword, '', true);
- if ($ret) {
- $this->success(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function changepwd(){
- $newpassword = input('newpassword');
- $oldpassword = input('oldpassword','');
- if (!$newpassword) {
- $this->error(__('Invalid parameters'));
- }
- if($this->auth->password && empty($oldpassword)){
- $this->error('原密码必填');
- }
- if(empty($this->auth->password)){
- $ret = $this->auth->changepwd($newpassword, '', true);
- }else{
- $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
- }
- if ($ret) {
- $this->success(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function changeDeviceIp()
- {
-
- if (!$this->apiLimit(1, 5)) {
- return ;
- }
- $user = $this->auth->getUser();
- $ip = request()->ip();
- $deviceId = $this->request->request('device_id','');
- $phoneModel = $this->request->request('phone_model','');
- $brand = $this->request->request('brand','');
- $apiVersion = $this->request->request('api_version','');
- $deviceOs = $this->request->request('device_os','');
- if ($ip !== $user->loginip){
- $update = [];
- $update['id'] = $user->id;
- $update['loginip'] = $ip;
- \app\common\model\User::update($update);
- }
- $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
- if (empty($userDeviceInfo)){
- $userDeviceInfo = new UserDeviceInfo();
- $userDeviceInfo->user_id = $user->u_id;
- }
- $userDeviceInfo->device_os = $deviceOs;
- $userDeviceInfo->device_id = $deviceId;
- $userDeviceInfo->phone_model = $phoneModel;
- $userDeviceInfo->brand = $brand;
- $userDeviceInfo->api_version = $apiVersion;
- $userDeviceInfo->save();
-
- }
-
- public function cancleUser(){
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $tenIm = new Tenim();
- $tenIm->loginoutim($this->auth->id);
- $data = [
- 'status' => -1,
- 'mobile' => 'close_'.$this->auth->mobile,
- 'wechat_openid' => 'close_'.$this->auth->wechat_openid,
- ];
- Db::name('user')->where('id',$this->auth->id)->update($data);
- $this->auth->logout();
- $this->success('注销成功');
- }
-
- public function useractive(){
- $this->success('success');
- }
-
- public function getUserOpenid_gzh(){
- $configValue = Service::getConfig('wechat');
- $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
- $rs = $wechat->getOpenid();
- $this->success('success',$rs);
- }
-
- public function jssdkBuildConfig() {
- $url = $this->request->request("url");
- $configValue = Service::getConfig('wechat');
- $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
- $sign = $wechat->getSignPackage(urldecode($url));
- $this->success("获取成功!",$sign);
- }
-
- public function ioslogin(){
- $ios_openid = input('ios_openid','');
- if (!$ios_openid) {
- $this->error(__('Invalid parameters'));
- }
- $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
-
- if ($user) {
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
-
- $ret = $this->auth->direct($user->id);
- } else {
- $reg_data = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
- }
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function iosregiter(){
- $ios_openid = input('ios_openid', '', 'trim');
- $gender = input('gender', -1, 'intval');
- if (!$ios_openid) {
- $this->error(__('Invalid parameters'));
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- }
- $reg_data = [
- 'register_from' => input('register_from',''),
- 'gender' => $gender
- ];
- $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
-
- public function perfect_info() {
- $avatar = input('avatar', '', 'trim');
- $nickname = input('nickname', '', 'trim');
- $birthday = input('birthday', '', 'strtotime');
- $hometown_cityid = input('hometown_cityid', '', 'trim');
- $job_id = input('job_id', '', 'trim');
- $character_id = input('character_id', '', 'trim');
- $introcode = input('introcode', '', 'trim');
- $data = [];
- if ($avatar) {
- $data['avatar'] = $avatar;
- }
- if ($nickname !== '') {
- if (iconv_strlen($nickname, 'utf-8') > 10) {
- $this->error('昵称最多10个字~');
- }
- $data['nickname'] = $nickname;
- }
- if ($birthday) {
- $data['birthday'] = $birthday;
- }
- if ($hometown_cityid) {
- $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
- if (!$count) {
- $this->error('城市不存在');
- }
- $data['hometown_cityid'] = $hometown_cityid;
- }
- if ($job_id) {
- $count = Db::name('enum_job')->where('id', $job_id)->count('id');
- if (!$count) {
- $this->error('职业不存在');
- }
- $data['job_id'] = $job_id;
- }
- if ($character_id) {
- $count = Db::name('enum_character')->where('id', $character_id)->count('id');
- if (!$count) {
- $this->error('性格不存在');
- }
- $data['character_id'] = $character_id;
- }
- if ($introcode && !$this->auth->intro_uid) {
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
- if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();
- }
- }
-
- Db::startTrans();
- $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改失败');
- }
-
- if(isset($data['intro_uid'])){
- $intro_jewel = config('site.new_user_intro_jewel');
- if($intro_jewel > 0){
- $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
- if($rs_wallet['status'] === false){
- Db::rollback();
- $this->error('邀请新人奖励赠送失败');
- }
- }
- }
-
- if(isset($data['avatar'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- if (isset($data['birthday'])) {
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- Db::commit();
- $this->success('修改成功');
- }
-
- public function idcard_auth() {
- $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
- if ($info && $info['status'] == 1) {
- $this->error('您已通过审核!');
- }
- $nickname = input('nickname', '', 'trim');
- $idcard = input('idcard', '', 'trim');
- if ($nickname === '') {
- $this->error('请输入姓名');
- }
- if (iconv_strlen($nickname, 'utf-8') > 50) {
- $this->error('请输入正确姓名');
- }
- if ($idcard === '') {
- $this->error('请输入身份证号');
- }
- if (iconv_strlen($idcard, 'utf-8') != 18) {
- $this->error('请输入正确身份证号');
- }
- $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
- if ($count) {
- $this->error('身份证号已存在');
- }
- $data = [];
- $data['truename'] = $nickname;
- $data['idcard'] = $idcard;
-
- $auth_restult = $this->userauth_tencent($idcard, $nickname);
- if ($auth_restult) {
- $data['status'] = 1;
- $msg = '认证通过';
- } else {
- $data['status'] = 2;
- $msg = '认证不通过';
- }
-
- Db::startTrans();
- if (!$info) {
- $data["user_id"] = $this->auth->id;
- $data["createtime"] = time();
- $res = Db::name('user_idconfirm')->insertGetId($data);
- } else {
- $data['updatetime'] = time();
- $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
- }
- if (!$res) {
- Db::rollback();
- $this->error('认证失败');
- }
- $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
- if ($rt === false) {
- Db::rollback();
- $this->error('认证失败');
- }
- if ($data['status'] == 1) {
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
-
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
- } else {
-
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
- }
- Db::commit();
- $this->success($msg);
- }
-
- public function userauth_tencent($idcard = '', $nickname = '') {
- try {
-
-
- $config = config('tencent_im');
- $cred = new Credential($config['SecretId'], $config['SecretKey']);
-
- $httpProfile = new HttpProfile();
- $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
-
- $clientProfile = new ClientProfile();
- $clientProfile->setHttpProfile($httpProfile);
-
- $client = new FaceidClient($cred, "", $clientProfile);
-
- $req = new IdCardVerificationRequest();
- $params = array(
- "IdCard" => $idcard,
- "Name" => $nickname
- );
- $req->fromJsonString(json_encode($params));
-
- $resp = $client->IdCardVerification($req);
-
- $result = json_decode($resp->toJsonString(), true);
- if (isset($result['Result']) && $result['Result'] == 0) {
- return 1;
- } else {
- return 0;
- }
- }
- catch(TencentCloudSDKException $e) {
- return 0;
- }
- }
-
- public function addalipayaccount() {
- $id = input('id', 0, 'intval');
- $type = input('type', 0, 'intval');
- $realname = input('realname', '', 'trim');
- $banknumber = input('banknumber', '', 'trim');
- $bankname = input('bankname', '', 'trim');
- if (!in_array($type, [1, 2])) {
- $this->error('参数错误');
- }
-
- if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
- $this->error('账号姓名1-30位');
- }
- if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
- $this->error('账号1-50位');
- }
- if ($type == 1) {
- if (iconv_strlen($bankname, 'utf-8') != 18) {
- $this->error('请输入正确身份证号');
- }
- }
- if ($type == 2) {
- if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
- $this->error('开户行名称1-50位');
- }
- }
- $user_bank = Db::name('user_bank');
- if ($id) {
-
-
- $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
- if (!$info) {
- $this->error('账号不存在');
- }
- if ($info['type'] != $type) {
- $this->error('账号类型错误');
- }
-
- $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
- if ($count) {
- $this->error('该账户有未审核的提现记录,暂不可修改');
- }
- $data['realname'] = $realname;
- $data['banknumber'] = $banknumber;
- $data['updatetime'] = time();
- $data['bankname'] = $bankname;
- $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
- if ($rs === false) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- } else {
-
-
- $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
- if ($count) {
- $this->error('您已经拥有该类型账号,请联系后台解绑');
- }
- $data['user_id'] = $this->auth->id;
- $data['type'] = $type;
- $data['realname'] = $realname;
- $data['banknumber'] = $banknumber;
- $data['bankname'] = $bankname;
- $data['createtime'] = time();
- $rs = $user_bank->insertGetId($data);
- if (!$rs) {
- $this->error('添加失败');
- }
- $this->success('添加成功');
- }
- }
-
- public function alipayinfo() {
- $type = input('type', 0, 'intval');
- $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
- if (!$info) {
- $info = (object)[];
- }
- $this->success('success', $info);
- }
-
- public function realauth() {
- if ($this->auth->real_status == 1) {
- $this->error('您已经真人认证过了~');
- }
- if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
- $this->error('请先上传真人头像~');
- }
-
- $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';
- $token_result = file_get_contents($token_url);
- if (!$token_result) {
- $this->error('您的网络开小差啦1~');
- }
- $token_result = json_decode($token_result, true);
- if ($token_result['code'] != 0) {
- $this->error('您的网络开小差啦2~');
- }
- $token = $token_result['access_token'];
-
- $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';
- $ticket_result = file_get_contents($ticket_url);
- if (!$ticket_result) {
- $this->error('您的网络开小差啦3~');
- }
- $ticket_result = json_decode($ticket_result, true);
- if ($ticket_result['code'] != 0) {
- $this->error('您的网络开小差啦4~');
- }
- $ticket = $ticket_result['tickets'][0]['value'];
-
- $sign_data = [
- 'wbappid' => config('tencent_yun')['secret_id'],
- 'userId' => (string)$this->auth->id,
- 'version' => '1.0.0',
- 'ticket' => $ticket,
- 'nonce' => Random::alnum(32)
- ];
- asort($sign_data);
- $sign_string = join('', $sign_data);
- $sign = sha1($sign_string);
-
- $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000);
- $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
- $avatar = one_domain_image($this->auth->avatar);
- $avatar = str_replace('https', 'http', $avatar);
- $img = file_get_contents($avatar);
- $img = str_replace('data:image/jpg;base64', '', $img);
- $img = str_replace('\n', '', $img);
- $sourcePhotoStr = base64_encode($img);
- $data = [
- 'webankAppId' => config('tencent_yun')['secret_id'],
- 'orderNo' => $orderNo,
- 'userId' => (string)$this->auth->id,
- 'sourcePhotoStr' => $sourcePhotoStr,
- 'sourcePhotoType' => 2,
- 'version' => '1.0.0',
- 'sign' => $sign,
- 'nonce' => $sign_data['nonce']
- ];
- $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
- if (!$rs) {
- $this->error('您的网络开小差啦5~');
- }
- $rs = json_decode($rs, true);
- if (!$rs || $rs['code'] != 0) {
- $this->error('您的网络开小差啦6~');
- }
- $user_auth = [
- 'user_id' => $this->auth->id,
- 'certify_id' => $rs['result']['faceId'],
- 'out_trade_no' => $data['orderNo'],
- 'status' => 0,
- 'createtime' => time(),
- 'updatetime' => time()
- ];
-
- Db::startTrans();
-
- $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
- if ($info) {
- $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
- } else {
- $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
- }
- if (!$auth_rs) {
- Db::rollback();
- $this->error('您的网络开小差啦7~');
- }
-
- $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
- if ($user_rs === false) {
- Db::rollback();
- $this->error('您的网络开小差啦8~');
- }
- Db::commit();
- $return_data = [
- 'face_id' => $user_auth['certify_id'],
- 'order_no' => $user_auth['out_trade_no'],
- 'user_id' => (string)$this->auth->id,
- 'nonce' => $sign_data['nonce'],
- 'sign' => $sign
- ];
- $this->success('success', $return_data);
- }
-
- public function getrealauthresult() {
- $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
- if (!$user_auth) {
- $this->success('尚未认证');
- }
- if ($user_auth['status'] == 1) {
- $this->success('真人认证通过');
- }
- if (!$user_auth['certify_id']) {
- $this->success('请先进行真人认证');
- }
-
- $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';
- $token_result = file_get_contents($token_url);
- if (!$token_result) {
- $this->error('您的网络开小差啦1~');
- }
- $token_result = json_decode($token_result, true);
- if ($token_result['code'] != 0) {
- $this->error('您的网络开小差啦2~');
- }
- $token = $token_result['access_token'];
-
- $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';
- $ticket_result = file_get_contents($ticket_url);
- if (!$ticket_result) {
- $this->error('您的网络开小差啦3~');
- }
- $ticket_result = json_decode($ticket_result, true);
- if ($ticket_result['code'] != 0) {
- $this->error('您的网络开小差啦4~');
- }
- $ticket = $ticket_result['tickets'][0]['value'];
-
- $sign_data = [
- 'wbappid' => config('tencent_yun')['secret_id'],
- 'orderNo' => $user_auth['out_trade_no'],
- 'version' => '1.0.0',
- 'ticket' => $ticket,
- 'nonce' => Random::alnum(32)
- ];
- asort($sign_data);
- $sign_string = join('', $sign_data);
- $sign = sha1($sign_string);
-
- $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
- $data = [
- 'appId' => config('tencent_yun')['secret_id'],
- 'version' => '1.0.0',
- 'nonce' => $sign_data['nonce'],
- 'orderNo' => $user_auth['out_trade_no'],
- 'sign' => $sign
- ];
- $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
- if (!$rs) {
- $this->error('您的网络开小差啦5~');
- }
- $rs = json_decode($rs, true);
- if (!$rs || $rs['code'] != 0) {
- $this->error($rs['msg']);
- }
- if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
- $edit_data['status'] = 1;
- $msg = '真人认证成功';
- } else {
- $edit_data['status'] = 2;
- $edit_data['certify_id'] = '';
- $edit_data['out_trade_no'] = '';
- $msg = '真人认证失败';
- }
- $edit_data['updatetime'] = time();
-
- Db::startTrans();
-
- $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
- if (!$result) {
- Db::rollback();
- $this->error('查询认证结果失败2');
- }
-
- $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
- if (!$rs) {
- Db::rollback();
- $this->error('查询认证结果失败3');
- }
- if ($edit_data['status'] == 1) {
-
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
-
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
- } else {
-
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
- }
- Db::commit();
- $this->success($msg);
- }
-
- public function kefu() {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [0, 1])) {
- $this->error('您的网络开小差啦~');
- }
- if ($type == 0) {
- $user_id = config('site.customer_service_id') ? : 0;
- } else {
- $user_id = config('site.pay_customer_service_id') ? : 0;
- }
- $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
- if (!$list) {
- $this->success('success', $list);
- }
- foreach ($list as $k => &$v) {
- $v['nickname'] = '客服' . ($k + 1);
- $v['avatar'] = config('avatar_girl');
- }
- $this->success('success', $list);
- }
-
- public function posterlist() {
- $list = config('site.intro_images');
- if (!$list) {
- $this->success('success', (object)[]);
- }
- foreach ($list as &$v) {
- $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
- }
- $this->success('success', $list);
- }
-
-
- public function createposter($image = '') {
- $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
- return $haibao;
- }
-
- public function setgender() {
- $user_id = $this->auth->id;
- $gender = input('gender', -1, 'intval');
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $edit_data['gender'] = $gender;
- $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl');
- $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
- if (!$rs) {
- $this->error('您的网络开小差啦~');
- }
-
- $data['gender'] = $edit_data['gender'];
- $data['avatar'] = $edit_data['avatar'];
- $this->success('success', $data);
- }
-
- public function realavatar_auit() {
- if ($this->auth->real_status != 1) {
- $this->error('尚未通过真人认证');
- }
- $avatar = input('avatar', '', 'trim');
- if ($avatar === '') {
- $this->error('参数缺失');
- }
- $avatar = one_domain_image($avatar);
- $now_avatar = one_domain_image($this->auth->avatar);
- if ($avatar == $now_avatar) {
- $this->error('头像未改变');
- }
-
- $result = $this->face_tencent($now_avatar, $avatar);
- $this->success('结果', $result);
- }
-
- public function editrealavatar() {
- if ($this->auth->real_status != 1) {
- $this->error('尚未通过真人认证');
- }
- $avatar = input('avatar', '', 'trim');
- if ($avatar === '') {
- $this->error('参数缺失');
- }
- $avatar = one_domain_image($avatar);
- $now_avatar = one_domain_image($this->auth->avatar);
- if ($avatar == $now_avatar) {
- $this->error('头像未改变');
- }
-
- $auit_result = $this->face_tencent($now_avatar, $avatar);
- if ($auit_result != 1) {
- $this->success('提示', ['code' => 2]);
- }
- $data['avatar'] = $avatar;
- $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if (!$user_result) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
-
- public function editrealavatarcancelauit() {
- if ($this->auth->real_status != 1) {
- $this->error('尚未通过真人认证');
- }
- $avatar = input('avatar', '', 'trim');
- if ($avatar === '') {
- $this->error('参数缺失');
- }
- $avatar = one_domain_image($avatar);
- $now_avatar = one_domain_image($this->auth->avatar);
- if ($avatar == $now_avatar) {
- $this->error('头像未改变');
- }
- $data['avatar'] = $avatar;
- $data['real_status'] = -1;
-
- Db::startTrans();
- $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if (!$user_result) {
- Db::rollback();
- $this->error('修改失败');
- }
- $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
- if (!$user_auth_result) {
- Db::rollback();
- $this->error('修改失败');
- }
- Db::commit();
- $this->success('修改成功');
- }
-
-
- public function face_tencent($urla = '', $urlb = '') {
- try {
-
-
- $config = config('tencent_im');
- $cred = new Credential($config['SecretId'], $config['SecretKey']);
-
- $httpProfile = new HttpProfile();
- $httpProfile->setEndpoint("iai.tencentcloudapi.com");
-
- $clientProfile = new ClientProfile();
- $clientProfile->setHttpProfile($httpProfile);
-
- $client = new IaiClient($cred, "ap-beijing", $clientProfile);
-
- $req = new CompareFaceRequest();
- $params = array(
- "UrlA" => $urla,
- "UrlB" => $urlb,
- "FaceModelVersion" => "3.0"
- );
- $req->fromJsonString(json_encode($params));
-
- $resp = $client->CompareFace($req);
-
- $result = json_decode($resp->toJsonString(), true);
-
- if (isset($result['Score']) && $result['Score'] >= 60) {
- return 1;
- } else {
- return 0;
- }
- }
- catch(TencentCloudSDKException $e) {
- return 0;
- }
- }
-
- public function editcity() {
- $name = input('name', '', 'trim');
- if ($name === '') {
- $this->error('参数缺失');
- }
- $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
- if (!$hometown_cityid) {
- $this->success('修改成功');
- }
- Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
- $this->success('修改成功');
- }
-
- public function searchuser() {
- $keyword = input('keyword', '', 'trim');
- if ($keyword === '') {
- $this->error('请输入关键字');
- }
- $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
- $id = $id ? : 0;
- $this->success('用户', $id);
- }
-
- public function bindalipayaccount() {
- $mt_user_bank = Db::name('user_bank');
- $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
- if ($count) {
- $this->error('您已绑定支付宝啦');
- }
- $auth_code = input('auth_code', '', 'trim');
- if (!$auth_code) {
- $this->error('授权码缺失');
- }
-
- $rs = getAlipayInfo($auth_code);
- if ($rs['status'] == 0) {
- $this->error($rs['info']);
- }
- $rs = $rs['data'];
-
- $data['banknumber'] = $rs['user_id'];
- if (!$data['banknumber']) {
- $this->error('获取用户信息失败');
- }
- $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
- if ($bank_number_count) {
- $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
- }
- if (isset($rs['nick_name'])) {
- $data['realname'] = $rs['nick_name'];
- }
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- $data['type'] = 1;
- $rt = $mt_user_bank->insertGetId($data);
- if (!$rt) {
- $this->error('绑定失败');
- }
- $this->success('绑定成功');
- }
-
- public function addgreetcontent() {
- $type = input('type', 0, 'intval');
- $title = input('title', '', 'trim');
- $content = input('content', '', 'trim');
- $duration = input('duration', 0, 'intval');
- if (!in_array($type, [0, 1, 2])) {
- $this->error('您的网络开小差了');
- }
- if ($content === '') {
- $this->error('请设置打招呼内容');
- }
- if (iconv_strlen($content, 'utf-8') > 255) {
- $this->error('打招呼内容最多255位');
- }
- if ($type == 1) {
- if ($title === '') {
- $this->error('请输入语音名称');
- }
- if (iconv_strlen($title, 'utf-8') > 50) {
- $this->error('语音名称最多50字');
- }
- if (!$duration) {
- $this->error('参数缺失');
- }
- }
- $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
- if ($count > 10) {
- $this->error('同一类型打招呼最多设置10条');
- }
- $data['user_id'] = $this->auth->id;
- $data['type'] = $type;
- $data['content'] = $content;
- if ($type == 1) {
- $data['title'] = $title;
- $data['duration'] = $duration;
- }
- $data['createtime'] = time();
-
- $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
- if (!$default_greet_count) {
- $data['is_default'] = 1;
- }
- $rs = Db::name('user_greet_content')->insertGetId($data);
- if (!$rs) {
- $this->error('您的网络开小差了');
- }
- $this->success('设置成功');
- }
-
- public function getgreetcontent() {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [0, 1, 2, 3])) {
- $this->error('您的网络开小差了');
- }
- if ($type == 3) {
- $list = Db::name('user_greet_content')->where(function ($query) {
- $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
- })->whereOr(function ($query) {
- $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
- })->select();
- } else {
- $where['user_id'] = $this->auth->id;
- $where['type'] = $type;
- $list = Db::name('user_greet_content')->where($where)->select();
- }
- if ($list) {
- foreach ($list as &$v) {
- if ($v['type'] != 0) {
- $v['content'] = one_domain_image($v['content']);
- }
- }
- }
- $this->success('打招呼内容', $list);
- }
-
-
- public function setdefaultgreet() {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
- if (!$count) {
- $this->error('您的网络开小差了');
- }
-
- Db::startTrans();
-
- $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
- if ($rs === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
-
- $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
- if ($rt === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
- Db::commit();
- $this->success('设置成功');
- }
-
- public function deldefaultgreet() {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $mt_user_greet_content = Db::name('user_greet_content');
- $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
- if (!$info) {
- $this->error('您的网络开小差了');
- }
-
- Db::startTrans();
-
- $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
- if ($rs === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
-
- if ($info['is_default'] == 1) {
- $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
- if ($first_greet) {
- $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
- if ($rt === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
- }
- }
- Db::commit();
- $this->success('删除成功');
- }
- }
|