Home > Backend Development > PHP Tutorial > WeChat service account development-obtaining user location information

WeChat service account development-obtaining user location information

WBOY
Release: 2016-07-29 09:12:06
Original
1789 people have browsed it

WeChat service account development-obtaining user location information

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.

Principle

1. Location information acquisition process

WeChat service account development-obtaining user location information

2. Location information message

<xml><tousername></tousername>
<fromusername></fromusername>
<createtime>1444035882</createtime>
<msgtype></msgtype>
<event></event>
<latitude>28.701618</latitude>
<longitude>115.818817</longitude>
<precision>30.000000</precision>
</xml>
Copy after login

Parameter description:

Parameter Description
ToUser Name Developer WeChat ID
FromUserName Sender account (an OpenID)
CreateTime Message creation time (integer)
MsgType Message type, event
Event Event type, LOCATION
Latitude Geographical location latitude
Longitude Geographical location longitude
Precision Geographical location accuracy

Steps to obtain location information

1. Apply for service account certification

Only certified service accounts can gain access to WeChat advanced services.

2. Enable user location information acquisition function

Developer Center -> Obtain user location

WeChat service account development-obtaining user location information

3. weiPHP location information message processing.

1. Configure the WeChat service account development interface

WeChat service account development-obtaining user location information
The WeChat server will push the interaction event messages between the user and WeChat to the SP server through this interface.

2. Process the location message in IndexAction of WeixinController.

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"].
Copy after login

LOCATION location information WeChat development

The above introduces the development of WeChat service account-obtaining user location information, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template