【微信开发】-发送位置进行普通IP定位,主要代码在private function receiveLocation($object)

普通IP定位 API是一个根据IP返回对应大致位置信息的HTTP/HTTPS形式位置服务接口,支持多种语言调用,如C# 、C++、Java等,即通过发送HTTP/HTTPS请求,返回JSON格式的位置数据(包括经纬度信息、地址信息等)。
该接口免费对外开放,您需先申请密钥(AK)才可使用。每个开发者帐号每天使用该服务的次数是有限的,若需更多的使用次数,请完成开发者认证以获取更高配额和更及时的技术支持。
功能介绍

调用API接口,返回请求参数中指定IP的大致位置信息,包括:经纬度、省、市、区县等地址信息。
如果请求参数中的IP为空,则默认返回当前服务请求来源的IP所对应的大致位置信息。
适用场景

以城市为分类的应用或网站:根据用户当前IP来提供对应城市的服务。

普通IP定位 API详见官网:http://lbsyun.baidu.com/index.php?title=webapi/ip-api

高精度IP定位 API详见官网:http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip

下面代码是普通IP定位的

<?
    header("Content-type: text/html; charset=utf-8");
    define("TOKEN","自填");
    define("APPID","自填");
    define("APPSECRET","自填");

    $wechatObj = new wechatCallbackapiTest();
    if(!isset($_GET["echostr"])){
        $wechatObj -> responseMsg();
    }else{
        $wechatObj ->valid();
    }

    class wechatCallbackapiTest{
     
        public function valid(){
     
            $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature(){
     
        if(!defined("TOKEN")){
            throw new Exception();
        }
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        $token = TOKEN;
        $tmpArr = array($token,$timestamp,$nonce);
        sort($tmpArr,SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        if($tmpStr == $signature){
            return true;
        }else{
            return false;
        }
    }

    public function responseMsg()
    {
     
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
        if (!empty($postStr)){
            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            $RX_TYPE = trim($postObj->MsgType);
            switch ($RX_TYPE)
            {
                case "event":
                    $result = $this->receiveEvent($postObj);
                    break;
                case "text":
                    $result = $this->receiveText($postObj);
                    break;
                case "image":
                    $result = $this->receiveImage($postObj);
                    break;
                case "location":
                    $result = $this->receiveLocation($postObj);
                    break;
                case "voice":
                    $result = $this->receiveVoice($postObj);
                    break;
                case "video":
                case "shortvideo":
                    $result = $this->receiveVideo($postObj);
                    break;
                case "link":
                    $result = $this->receiveLink($postObj);
                    break;
                default:
                    $result = "unknown msg type: ".$RX_TYPE;
                    break;
            }
            echo $result;
        }else {
            echo "";
            exit;
        }
    }

    private function receiveEvent($object)
    {
     
        include("locationinfoUpload.php");
        $resInsert = insertLocationinfo($object);
        $content = "";
        switch ($object->Event)
        {
            case "subscribe":
                $content = "欢迎关注通州-羽我同行俱乐部!\n请回复以下关键字:文本 表情 单图文 多图文 音乐\n请按住说话 或 点击 + 再分别发送以下内容:语音 图片 小视频 我的收藏 位置";
                $content .= (!empty($object->EventKey))?("\n来自二维码场景 ".str_replace("qrscene_","",$object->EventKey)):"";
                $content .= "\n\n".'<a href="羽我同行.cn">技术支持 大米</a>';
                break;
            case "unsubscribe":
                $content = "取消关注";
                break;
            case "CLICK":
                switch ($object->EventKey)
                {
                    case "78":
                        $content = array();
                        $content[] = array(

                     "Title"=>"天气在手,羽球无忧,输入“天气北京”", 

                     "Description"=>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zyytaiyame

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值