Home > Backend Development > PHP Tutorial > WeChat service account development-obtain user location information, obtain_PHP tutorial

WeChat service account development-obtain user location information, obtain_PHP tutorial

WBOY
Release: 2016-07-12 09:05:09
Original
1263 people have browsed it

WeChat service account development-obtain user location information, obtain

WeChat service account development-obtain 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-obtain user location information, obtain_PHP tutorial

2. Location information message

<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>
Copy after login

Parameter description:

参数描述
ToUserName 开发者微信号
FromUserName 发送方帐号(一个OpenID)
CreateTime 消息创建时间 (整型)
MsgType 消息类型,event
Event 事件类型,LOCATION
Latitude 地理位置纬度
Longitude 地理位置经度
Precision 地理位置精度

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 -> Get user location

WeChat service account development-obtain user location information, obtain_PHP tutorial

3. weiPHP geographical location information message processing.

1. Configure WeChat service account development interface

WeChat service account development-obtain user location information, obtain_PHP tutorial
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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1070039.htmlTechArticleWeChat service account development - obtain user location information, obtain WeChat service account development - obtain user location information in WeChat public account During development, obtaining user location information is a very common function...
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