Login.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use think\Db;
  16. use Firebase\JWT\JWT;
  17. use think\facade\Validate;
  18. use think\cache\driver\Redis;
  19. /**
  20. * @title 用户登录
  21. * @controller Login
  22. * @group worker
  23. */
  24. class Login extends Base
  25. {
  26. /**
  27. * @title 注册
  28. * @desc 注册
  29. * @url /api/Login/Register
  30. * @method POST
  31. * @tag 基础
  32. * @header
  33. * @param name:phone type:string require:1 desc:手机号
  34. * @param name:ver_code type:string require:1 desc:验证码
  35. * @param name:password type:string require:1 desc:密码
  36. * @param name:confirm_password type:string require:1 desc:确认密码
  37. * @param name:second_password type:string require:1 desc:二级密码
  38. * @param name:confirm_second_password type:string require:1 desc:二级确认密码
  39. * @param name:invite_code type:string require:0 desc:邀请码
  40. *
  41. */
  42. public function Register(){
  43. $this->error('系统升级中...');
  44. $phone = input('phone');
  45. $ver_code = input('ver_code');
  46. $password = input('password');
  47. $confirm_password = input('confirm_password');
  48. $second_password = input('second_password');
  49. $confirm_second_password = input('confirm_second_password');
  50. $invite_code = input('invite_code');
  51. if (!$phone || !$ver_code || !$password || !$confirm_password || !$second_password || !$confirm_second_password){
  52. $this->error('参数错误');
  53. }
  54. if (!Validate::regex($phone, "^1\d{10}$")) {
  55. $this->error('手机号格式错误');
  56. }
  57. //验证短信验证码
  58. $time = time()-60;
  59. $sms = Db::name('store_sms')->where(['mobile' => $phone, 'event' => 'register'])
  60. ->where('createtime','>',$time)
  61. ->order('id', 'DESC')
  62. ->find();
  63. if (!$sms || $sms['code'] != $ver_code) $this->error('短信验证码不正确!');
  64. // if ($ver_code!=='123456') $this->error('验证码错误');
  65. $user = Db::name('store_member')
  66. ->where('is_deleted',0)
  67. ->where('phone',$phone)
  68. ->find();
  69. if ($user) $this->error('手机号已注册');
  70. if (!preg_match('/^[0-9a-z]{6,12}$/i',$password)) $this->error('密码格式错误,请输入6-12位数字+字母');
  71. if ($password!=$confirm_password) $this->error('密码与确认密码不一致');
  72. if (!preg_match('/^[0-9]{6}$/i',$second_password)) $this->error('二级密码格式错误,请输入6位纯数字');
  73. if ($second_password!=$confirm_second_password) $this->error('二级密码与确认密码不一致');
  74. if ($invite_code){
  75. $isset = Db::name('store_member')->where('is_deleted',0)->where('id',$invite_code)->find();
  76. if (!$isset) $this->error('邀请码不存在');
  77. }else{
  78. $invite_code = 0;
  79. }
  80. //钱包地址
  81. //$offlineaccount = getOfflineAccount();
  82. // $address = json_decode($offlineaccount,true)['address'];
  83. // $laddress = getWalletAddress($phone,$address);
  84. // if ($laddress['code']==0){
  85. // $wallet_address = $laddress['data']['opbChainClientAddress'];
  86. // }
  87. $data = [
  88. 'phone'=>$phone,
  89. 'pid'=>$invite_code,
  90. 'password'=>md5($password),
  91. 'second_password'=>md5($second_password),
  92. //'wallet_address'=>$wallet_address,
  93. //'offline_account'=>$offlineaccount
  94. ];
  95. $member_id = Db::name('store_member')->insertGetId($data);
  96. if ($member_id){
  97. $invite_img = setintivecode($member_id);
  98. $invite_address = getintiveaddress($member_id);
  99. Db::name('store_member')->where('id',$member_id)->update(['name'=>'收藏家'.$member_id,'invite_img'=>$invite_img,'invite_address'=>$invite_address]);
  100. //邀请好友送积分
  101. if ($invite_code>0){
  102. $invite_friends_integral = getConfigValue('invite_friends_integral');
  103. memberMoneyChange($invite_friends_integral,1,$invite_code,'邀请好友',1,$member_id);
  104. }
  105. $this->success('注册成功');
  106. }
  107. $this->error('注册失败');
  108. }
  109. /**
  110. * @title 登录
  111. * @desc 登录
  112. * @url /api/Login/passwordLogin
  113. * @method POST
  114. * @tag 基础
  115. * @header
  116. * @param name:phone type:int require:1 default:-- desc:手机号
  117. * @param name:password type:string require:1 default:-- desc:密码
  118. * @return name:token type:string default:-- desc:用户登录成功后的token值
  119. */
  120. public function passwordLogin()
  121. {
  122. $phone = input('phone');
  123. $password = input('password');
  124. if (empty($password) || empty($phone)) {
  125. $this->error('参数错误');
  126. }
  127. $member = Db::name('store_member')
  128. ->where('phone', $phone)
  129. ->where('is_deleted',0)
  130. ->find();
  131. if (!$member) $this->error('手机号未注册');
  132. if ($member['password']!=md5($password)) $this->error('密码错误');
  133. $token = self::create_jwt($member['id']);
  134. setMemberInfoHash($member['id']);
  135. Db::name('store_member')->where('id',$member['id'])->update(['token'=>$token]);
  136. $this->success('登录成功', $token);
  137. }
  138. //token加密
  139. public function create_jwt($uid)
  140. {
  141. $key = md5(config('app.jwt')); //jwt的签发密钥,验证token的时候需要用到
  142. $time = time(); //签发时间
  143. $expire = $time + config('app.jwt_time'); //过期时间
  144. $token = array(
  145. "uid" => $uid,
  146. "iss" => "https://zain.com",//签发组织
  147. "aud" => "https://zain.com", //签发作者
  148. "iat" => $time,
  149. "nbf" => $time,
  150. "exp" => $expire
  151. );
  152. $jwt = JWT::encode($token, $key);
  153. return $jwt;
  154. }
  155. /**
  156. * @title 找回密码
  157. * @desc 找回密码
  158. * @url /api/Login/ForgetPassword
  159. * @method POST
  160. * @tag 基础
  161. * @header
  162. * @param name:phone type:int require:1 default:-- desc:手机号
  163. * @param name:ver_code type:string require:1 desc:验证码
  164. * @param name:password type:string require:1 default:-- desc:密码
  165. * @param name:confirm_password type:string require:1 desc:确认密码
  166. */
  167. public function ForgetPassword(){
  168. $phone = input('phone');
  169. $ver_code = input('ver_code');
  170. $password = input('password');
  171. $confirm_password = input('confirm_password');
  172. if (!$phone || !$ver_code || !$password || !$confirm_password) $this->error('参数错误');
  173. $member = Db::name('store_member')
  174. ->where('phone', $phone)
  175. ->where('is_deleted',0)
  176. ->find();
  177. if (!$member) $this->error('手机号未注册');
  178. //验证短信验证码
  179. $time = time()-60;
  180. $sms = Db::name('store_sms')->where(['mobile' => $phone, 'event' => 'forgetpwd'])
  181. ->where('createtime','>',$time)
  182. ->order('id', 'DESC')
  183. ->find();
  184. if (!$sms || $sms['code'] != $ver_code) $this->error('短信验证码不正确!');
  185. if (!preg_match('/^[0-9a-z]{6,12}$/i',$password)) $this->error('密码格式错误,请输入6-12位数字+字母');
  186. if ($password!=$confirm_password) $this->error('密码与确认密码不一致');
  187. $data = [
  188. 'password'=>md5($password),
  189. 'update_at'=>date('Y-m-d H:i:s')
  190. ];
  191. if (Db::name('store_member')->where('id',$member['id'])->update($data)) $this->success('修改成功');
  192. $this->error('修改失败');
  193. }
  194. public function test(){
  195. // $redis = new Redis();
  196. // $nonce = $redis->get('nonce');
  197. // $url2 = "http://192.144.219.204:8083/ddc1155/balanceOf?ddcId=10962&nonce=$nonce&owner=0x38700ebb3c04dfb905c93bb2b3fbe06fea607fb0";
  198. // $res2=curlRequest($url2);
  199. // echo $res2;die;
  200. $url2='http://192.144.219.204:8083/ddc/getNonce';
  201. $nonce=curlRequest($url2);
  202. echo $nonce;die;
  203. $str=rand(100000000,999999999);
  204. $url2 = "http://192.144.219.204:8083/ddc1155/safeMint?amount=10&ddcURI=$str&nonce=$nonce&to=0xc472ec30ec813784b19872565e045c7153ea3f17";
  205. $res2=curlRequest($url2);
  206. $url = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash='.$res2;
  207. $res=curlRequest($url);
  208. echo $res;die;
  209. $result2 = json_decode($res2,true);
  210. set_time_limit(0);
  211. $url2='http://192.144.219.204:8083/ddc/getNonce';
  212. $nonce=curlRequest($url2);
  213. echo $nonce;die;
  214. // $redis = new Redis();
  215. //$redis->set('nonce',$nonce);
  216. die;
  217. $list = Db::name('test')->where('error',1)->select();
  218. foreach ($list as &$v){
  219. $url2 = 'http://192.144.219.204:8083/ddc/official?address='.$v['key'];
  220. $res2=curlRequest($url2);
  221. $result2 = json_decode($res2,true);
  222. if ($result2['code']=='-1'){
  223. Db::name('test')->where('key',$v['key'])->update(['error'=>0]);
  224. }else if ($result2['code']==0){
  225. Db::name('test')->where('key',$v['key'])->update(['error'=>2]);
  226. }
  227. }
  228. die;
  229. $url2 = 'http://192.144.219.204:8083/ddc/official?address=0xd257295e958a7000fa572e5f114d1cae2ea5a279';
  230. $res2=curlRequest($url2);
  231. $result2 = json_decode($res2,true);
  232. print_r($result2);die;
  233. Db::name('store_order_info')
  234. ->whereNotNull('company_hash')
  235. ->whereIn('status','1')
  236. ->where('company_hash','neq','')
  237. ->where('collectors_hash','eq','')
  238. ->chunk('20',function ($list){
  239. $from = '0xc472ec30ec813784b19872565e045c7153ea3f17';
  240. foreach ($list as &$v){
  241. echo $v['id']."<br />";
  242. $url2='http://192.144.219.204:8083/ddc/getNonce';
  243. $nonce=curlRequest($url2);
  244. if ($v['status']==1){
  245. $mid = $v['mid'];
  246. }elseif ($v['status']==3){
  247. $from = Db::name('store_member')->where('id',$v['to_mid'])->value('wallet_address');
  248. $mid = $v['to_mid'];
  249. }
  250. $to = Db::name('store_member')->where('id',$mid)->value('wallet_address');
  251. if (empty($to) || $to == ''){
  252. continue;
  253. }
  254. //$ddcid = Db::name('hash')->where('hash',$v['company_hash'])->value('ddcid');
  255. $ddcid = $v['ddcid'];
  256. $url = "http://192.144.219.204:8083/ddc/transfer?from=$from&to=$to&ddcid=$ddcid&nonce=".$nonce;
  257. $res=curlRequest($url);
  258. echo $res.'<br />';
  259. $result=json_decode($res,true);
  260. if($result['code']){
  261. continue;
  262. }else{
  263. Db::name('store_order_info')
  264. ->where('id',$v['id'])
  265. ->update(['collectors_hash'=>$res,'collectors_hash_time'=>date('Y-m-d H:i:s')]);
  266. }
  267. }
  268. },'id','desc');
  269. die();
  270. $list = Db::name('store_order_info')->whereNull('ddcid')->select();
  271. foreach ($list as &$v){
  272. $hash = Db::name('hash')->where('goods_id',$v['c_id'])->where('success',1)->where('status',0)->order('id asc')->limit(1)->find();
  273. $data = [
  274. 'company_hash'=>$hash['hash'],
  275. 'ddcid'=>$hash['ddcid']
  276. ];
  277. Db::name('store_order_info')
  278. ->where('id',$v['id'])
  279. ->update($data);
  280. Db::name('hash')->where('hash',$hash['hash'])->update(['status'=>1]);
  281. }
  282. dump($list);die;
  283. $list = Db::name('store_order_info')->where('c_id',0)->select();
  284. foreach ($list as &$v){
  285. $info = json_decode($v['pro_info'],true);
  286. Db::name('store_order_info')->where('id',$v['id'])->update(['c_id'=>$info['id']]);
  287. }
  288. die;
  289. Db::name('store_order_info')
  290. ->whereNotNull('company_hash')
  291. ->where('id','10100')
  292. ->whereIn('status','1,3')
  293. ->where('company_hash','neq','')
  294. ->where('collectors_hash','eq','')
  295. ->chunk('20',function ($list){
  296. $from = '0xc472ec30ec813784b19872565e045c7153ea3f17';
  297. foreach ($list as &$v){
  298. echo $v['id']."<br />";
  299. $url2='http://192.144.219.204:8083/ddc/getNonce';
  300. $nonce=curlRequest($url2);
  301. if ($v['status']==1){
  302. $mid = $v['mid'];
  303. }elseif ($v['status']==3){
  304. $from = Db::name('store_member')->where('id',$v['to_mid'])->value('wallet_address');
  305. $mid = $v['to_mid'];
  306. }
  307. $to = Db::name('store_member')->where('id',$mid)->value('wallet_address');
  308. if (empty($to) || $to == ''){
  309. continue;
  310. }
  311. $ddcid =Db::name('hash')->where('hash',$v['company_hash'])->value('ddcid');
  312. $url = "http://192.144.219.204:8083/ddc/transfer?from=$from&to=$to&ddcid=$ddcid&nonce=".$nonce;
  313. $res=curlRequest($url);
  314. echo $res.'<br />';
  315. $result=json_decode($res,true);
  316. if($result['code']){
  317. continue;
  318. }else{
  319. Db::name('store_order_info')->where('id',$v['id'])->update(['collectors_hash'=>$res,'collectors_hash_time'=>date('Y-m-d H:i:s')]);
  320. }
  321. }
  322. },'id','asc');
  323. die;
  324. $url = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash=0x3b27b0941070a9aac74c6315700557da112793aaa095702bb8308652c226bf71';
  325. $res=curlRequest($url);
  326. print_r($res);die;
  327. // $url = 'http://192.144.219.204:8083/ddc/status?address=0x3a1ca5e6fd0acfa43eeea3002cf4c72c86ad0d81';
  328. // $res=curlRequest($url);
  329. // $result = json_decode($res,true);
  330. // dump($result);
  331. // die;
  332. //
  333. // $url = 'http://192.144.219.204:8083/ddc/official?address=0x65f71404c42565c736536ec1e1ab29859d67b9d8';
  334. // $res=curlRequest($url);
  335. // $result = json_decode($res,true);
  336. // dump($result);
  337. // die;
  338. $list = Db::name('hash')->whereIn('id','4386')->select();
  339. foreach ($list as &$v){
  340. $url = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash='.$v['hash'];
  341. $res=curlRequest($url);
  342. Db::name('hash')->where('id',$v['id'])->update(['result'=>$res]);
  343. $result3=json_decode($res,true);
  344. dump($result3);
  345. if (isset($result3['status']) && $result3['status']=='0x1'){
  346. $url4='http://192.144.219.204:8083/ddc/createDdcid?hash='.$v['hash'];
  347. $ddcid=curlRequest($url4);
  348. echo 'ddcid:'.$ddcid."<br />";
  349. $result4=json_decode($ddcid,true);
  350. if($result4['code']){
  351. dump($result4);
  352. }else{
  353. $update_data['ddcid'] = $ddcid;
  354. }
  355. Db::name('hash')->where('id',$v['id'])->update($update_data);
  356. }
  357. }
  358. die;
  359. //
  360. // $member = Db::name('store_member')->where('id','100040')->select();
  361. // foreach ($member as &$v){
  362. // if (empty($v['offline_account']) || $v['offline_account']==''){
  363. // $offline_accounts = getOfflineAccount();
  364. // $v['offline_account'] =$offline_accounts;
  365. // }
  366. // $offline_account = json_decode($v['offline_account'],true);
  367. // $address = $offline_account['address'];
  368. // $laddress = getWalletAddress($v['phone'].$v['id'],$address);
  369. // dump($laddress);
  370. //// if ($laddress['code']==0){
  371. //// $wallet_address = $laddress['data']['opbChainClientAddress'];
  372. //// Db::name('store_member')->where('id',$v['id'])->update(['wallet_address'=>$wallet_address]);
  373. //// }
  374. // }
  375. // die;
  376. // $url3 = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash=0x29dd82a90fe77dd4581ed0e95d50588a4a5dfd7a5625e5b3530819d5235aefdf';
  377. // $res3=curlRequest($url3);
  378. // echo $res3;
  379. // die;
  380. // $list = Db::name('hash')->order('id desc')->limit(30)->select();
  381. // foreach ($list as &$v){
  382. // $url3 = 'http://192.144.219.204:8083/ddc/getTransactionReceipt?hash='.$v['hash'];
  383. // $res3=curlRequest($url3);
  384. // $result3=json_decode($res3,true);
  385. // if (isset($result3['status']) && $result3['status']=='0x1'){
  386. // echo "创建成功".$v['hash']."<br />";
  387. // }else{
  388. // echo "创建失败".$v['hash']."<br />";
  389. // }
  390. // }
  391. // die;
  392. // $url = 'http://192.144.219.204:8083/ddc/getNonce';
  393. // $res=curlRequest($url);
  394. // print_r($res);die;
  395. //充值能量
  396. // $rand = get_order_sn();
  397. // $url = 'http://192.144.219.204:8083/ddc/rechargeGas?money=40&address=0x3fc6da539f8591250a2f989574646ab03cde7cba&transSn='.$rand;
  398. // $res=curlRequest($url);
  399. // print_r($res);die;
  400. //充值业务费
  401. $rand = get_order_sn();
  402. $url = 'http://192.144.219.204:8083/ddc/rechargeBusiness?money=30&address=0x3fc6da539f8591250a2f989574646ab03cde7cba&transSn='.$rand;
  403. $res=curlRequest($url);
  404. print_r($res);die;
  405. //传递ddcid
  406. $url2='http://192.144.219.204:8083/ddc/getNonce';
  407. $nonce=curlRequest($url2);
  408. // $from = '0x8583c53ca3759f0893cb6c156b682e8fef22ed95';
  409. // $to = '0xf52a94d36dc81d48eed46a23b5397f822df0118e';
  410. $from = '0xf52a94d36dc81d48eed46a23b5397f822df0118e';
  411. $to = '0xf12ef3091e3169f0b79d7d224f0ab7fa5916945f';
  412. $ddcid ='10816';
  413. $url = "http://192.144.219.204:8083/ddc/transfer?from=$from&to=$to&ddcid=$ddcid&nonce=".$nonce;
  414. $res=curlRequest($url);
  415. print_r($res);die;
  416. $url = 'http://192.144.219.204:8083/ddc/createAccount';
  417. $result = file_get_contents($url);
  418. $result = json_decode($result,true);
  419. $name = rand(0,100);
  420. $url2 = "http://192.144.219.204:8083/ddc/createAddress?name=".$name."&account=".$result['address'];
  421. $res=curlRequest($url2);
  422. $result=json_decode($res,true);
  423. dump($result);
  424. }
  425. }