Home > Article > Backend Development > WeChat service account development-obtain user location information, obtain_PHP tutorial
In the development of WeChat public accounts, obtaining user location information is a very common functional requirement. Through the user's location information, you can do some map navigation and LBS-based marketing activities.
The following will introduce the principles and steps for WeChat service accounts to obtain user location information.
<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>
Parameter description:
参数 | 描述 |
---|---|
ToUserName | 开发者微信号 |
FromUserName | 发送方帐号(一个OpenID) |
CreateTime | 消息创建时间 (整型) |
MsgType | 消息类型,event |
Event | 事件类型,LOCATION |
Latitude | 地理位置纬度 |
Longitude | 地理位置经度 |
Precision | 地理位置精度 |
Only certified service accounts can gain access to WeChat advanced services.
Developer Center -> Get user location
The WeChat server will push the interaction event messages between the user and WeChat to the SP server through this interface.
Convert the xml message into a php array, and then take out the latitude and longitude information for use.
$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 location information WeChat development