IpServer.php 979 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/24
  6. * Time: 下午3:51
  7. */
  8. namespace wechat\server;
  9. use Yii;
  10. use common\models\NewsIprecord;
  11. class IpServer
  12. {
  13. public function add($nid)
  14. {
  15. $ip = Yii::$app->request->userIP;
  16. // $data = json_decode(file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip),true);
  17. // if(!empty($data) && $data['code'] == 0)
  18. // {
  19. $model = new NewsIprecord();
  20. $model->ip = $ip;
  21. $model->nid = $nid;
  22. $row = $model->FindByIp();
  23. if($row == null)
  24. {
  25. // $model->region = $data['data']['region'];
  26. // $model->city = $data['data']['city'];
  27. // $model->country = $data['data']['country'];
  28. if($model->save())return true;
  29. }
  30. // }
  31. return false;
  32. }
  33. }