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
<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>
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
Only certified service accounts can gain access to WeChat advanced services.
Developer Center -> Obtain 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
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.