微信服务号开发-获取用户位置信息,获取
微信服务号开发-获取用户位置信息
在微信公众号开发的中,获取用户位置信息是非常常见的功能需求,通过用户的位置信息,可以做一些地图导航,以及基于LBS的营销活动。
下面将介绍微信服务号获取用户位置信息的原理与步骤。
原理
1. 位置信息获取流程
2. 位置信息报文
<xml><ToUserName><![CDATA[gh_public_member_account]]></ToUserName> <FromUserName><![CDATA[oNEGGwGfl8f5xMEqVHToL63LDL40]]></FromUserName> <CreateTime>1444035882</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[LOCATION]]></Event> <Latitude>28.701618</Latitude> <Longitude>115.818817</Longitude> <Precision>30.000000</Precision> </xml>
参数说明:
参数 | 描述 |
---|---|
ToUserName | 开发者微信号 |
FromUserName | 发送方帐号(一个OpenID) |
CreateTime | 消息创建时间 (整型) |
MsgType | 消息类型,event |
Event | 事件类型,LOCATION |
Latitude | 地理位置纬度 |
Longitude | 地理位置经度 |
Precision | 地理位置精度 |
获取位置信息步骤
1. 申请服务号认证
只有通过认证的服务号,才能够获取访问微信高级服务的权限。
2. 开启用户位置信息获取功能
开发者中心 -> 获取用户地理位置
3. weiPHP地理位置信息消息处理。
1. 配置微信服务号开发接口
微信服务器将会把用户与微信之间的交互事件消息,通过此接口推送给SP服务器。
2. 在WeixinController的IndexAction中处理location消息。
将xml消息转化为php数组,然后取出经纬度信息,以备使用。
$content = file_get_contents ( 'php://input' ); $data = new \SimpleXMLElement ( $content ); foreach ( $data as $key => $value ) { $this->data [$key] = strval ( $value ); } // to use data["longitude"]; data["latitude"].
LOCATION位置信息微信开发

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools