首页 > php教程 > PHP源码 > 快速定位手机号码归属地

快速定位手机号码归属地

PHP中文网
发布: 2016-05-25 17:05:16
原创
2484 人浏览过

跳至

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

<?php

/* vim: set expandtab tabstop=4 shiftwidth=4: */

// +----------------------------------------------------------------------+

// | PHP version 5                                                        |

// +----------------------------------------------------------------------+

// | Copyright (c) 1997-2004 The PHP Group                                |

// +----------------------------------------------------------------------+

// | This source file is subject to version 3.0 of the PHP license,       |

// | that is bundled with this package in the file LICENSE, and is        |

// | available through the world-wide-web at the following url:           |

// | http://www.php.net/license/3_0.txt.                                  |

// | If you did not receive a copy of the PHP license and are unable to   |

// | obtain it through the world-wide-web, please send a note to          |

// | license@php.net so we can mail you a copy immediately.               |

// +----------------------------------------------------------------------+

// | Author: Author|

// |         Copyright 2013-5-31                                 |

// +----------------------------------------------------------------------+

//

 

$mobile_home = new mobile_home();

$mobile_home->set_mobile(18606240180);

$data = $mobile_home->showji();//data是一个数组,可以获取到你想要的信息

//print_r($data);

/**

 *

 * 手机归属地查询

 *

 * 通过curl扩展来实现查询手机号码归属地

 */

//定义一个class

class mobile_home {

    public $mobile;

    public function set_mobile($mobile) {

        $this->mobile = $mobile;

        $this->checklen();

    }

    //检测手机位数

    public function checklen() {

        if (strlen($this->mobile) != "11") {

            die("手机号码有误");

        }

    }

    //调用官方接口

    public function showji() {

        $data = $this->get(&#39;http://api.showji.com/Locating/www.showji.com.aspx?m=&#39; . $this->mobile . &#39;&output=json&#39;, &#39;&#39;, "http://api.showji.com");

        if (is_array($data)) {

            return $data;

        }

    }

    //通过curl扩展获取数据信息

    private function get($urll, $cookie = &#39;&#39;, $referer = &#39;&#39;) {

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $urll);

        curl_setopt($ch, CURLOPT_HEADER, 0);

        curl_setopt($ch, CURLOPT_REFERER, $referer);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        curl_setopt($ch, CURLOPT_COOKIE, $cookie);

        $content = curl_exec($ch);

        curl_close($ch);

        return json_decode($content, true);

    }

}

?>

登录后复制

                   

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板