LEAF平台中的LBS标致3008是什么平台的

位置改变生活 LBS平台能为我们带来什么 - 手机中国
位置改变生活 LBS平台能为我们带来什么
作者:闫瑾
  【 】上周,高德宣布推出LBS+开放平台战略,为不同领域的应用提供数据支持,通过分析用户的位置信息,以及分析用户消费习惯和行为,帮助厂商推广产品,而厂商也可以据此向用户们提供服务,那么LBS到底是什么呢?
  说起LBS,我想大部分用户都不知道它是什么,然而我们每天的生活却都与它息息相关,小编举个例子您就明白了。周末,小编想去看电影,拿出打开团购应用即可查看附近哪家影院有团购促销,买完票之后,小编决定叫一辆车去电影院,打开叫车应用,用车信息被迅速推送到距离我最近的出租车上,很快,小编就到达了目的地。看似简单的几个动作,却包含着大量的LBS服务。
  LBS英文全称:Location Based Service,它是一种基于位置的服务,它可以捕捉用户所处的位置信息,利用手机中的GPS模块将自己的位置信号发送到定位后台来实现来定位,因此精准度也更高一些。与应用相结合,它可以满足用户的各种需求,同时也为商家的推广和营销提供了便利条件。
  在案例中,团购应用根据小编所处的位置,迅速推送了附近几家电影院的信息,而叫车软件也是如此,除了小编自己的位置之外,司机的位置也需要确定,用户可以马上知道车辆的位置并据此预估达到时间,司机也能很快接到用户,如此一来,双方信息对等,在极大降低成本的同时,也提高了效率。
  2010年,LBS服务在我国开始迅猛发展,最初的街旁网、切客网、微领地等等都是LBS服务的受益者,但是他们的商业模式比较单一,简单来说就是签到,在确定了用户的位置之后,商家会推送一些促销广告,或者派送一些免费的赠品,希望借此引来客流,完成销售过程。然而,这种方式过于简单,很快便无法满足用户的需要,商家发现即使推送的广告再诱人,用户似乎也不怎么感冒。
提示:支持键盘“←&→”翻页
用其他账号登录:
请稍后,数据加载中...
请稍后,数据加载中...
上市时间:2017.09
上市时间:2017.09
上市时间:2017.10
上市时间:2017.10
上市时间:2017.11
上市时间:2017.09
上市时间:2017.09
上市时间:2017.11
上市时间:2017.10
上市时间:2017.06
上市时间:2017.09
上市时间:2017.09
上市时间:2017.11
上市时间:2017.10
上市时间:2017.11
上市时间:2017.09
上市时间:2017.09
上市时间:2017.09
上市时间:2017.10
上市时间:2017.10
热门搜索词
Copyright & 2007 -
北京沃德斯玛特网络科技有限责任公司.All rights reserved 发邮件给我们京ICP证-070681号 京ICP备号 京公网安备:京网文[8号博客分类:
实现查找附近功能;
1)发送地理位置;
点击窗口底部的“+”按钮,选择“位置”,点“发送”
2)指定关键词搜索;
格式:附近+关键词\n例如:附近ATM、附近KTV、附近厕所
项目结构图
增加和修改相关源代码
百度地点类
用户位置类
用户位置访问类
百度地图工具类
地图网页文件
核心Service
消息处理工具类
Maven项目文件
上传本地代码到GitHub
上传工程WAR档至SAE
微信客户端测试
完整项目源代码
项目结构图
源代码文件说明
BaiduPlace.java
百度地点类
UserLocation.java
用户位置类
UserLocationDao.java
用户位置访问类
BaiduMapUtil.java
百度地图工具类
CoreService.java
核心服务类,新增处理各种输入,返回不同图文信息
MessageUtil.java
新增生成图文信息的方法
新增json和Base64等jar
增加和修改相关源代码
百度地点类
BaiduPlace.java
package com.coderdream.
* 地址信息
public class BaiduPlace implements Comparable&BaiduPlace& {
* 详细地址
* 联系电话
public String getName() {
public void setName(String name) {
this.name =
public String getAddress() {
public void setAddress(String address) {
this.address =
public String getLng() {
public void setLng(String lng) {
this.lng =
public String getLat() {
public void setLat(String lat) {
this.lat =
public String getTelephone() {
public void setTelephone(String telephone) {
this.telephone =
public int getDistance() {
public void setDistance(int distance) {
this.distance =
public int compareTo(BaiduPlace baiduPlace) {
return this.distance - baiduPlace.getDistance();
用户位置类
UserLocation.java
package com.coderdream.
* 用户地理位置
public class UserLocation {
private String openId;
* 百度地图经度
private String bd09L
* 百度地图纬度
private String bd09L
public String getOpenId() {
return openId;
public void setOpenId(String openId) {
this.openId = openId;
public String getLng() {
public void setLng(String lng) {
this.lng =
public String getLat() {
public void setLat(String lat) {
this.lat =
public String getBd09Lng() {
return bd09L
public void setBd09Lng(String bd09Lng) {
this.bd09Lng = bd09L
public String getBd09Lat() {
return bd09L
public void setBd09Lat(String bd09Lat) {
this.bd09Lat = bd09L
用户位置访问类
UserLocationDao.java
package com.coderdream.
import java.sql.C
import java.sql.PreparedS
import java.sql.ResultS
import java.sql.SQLE
import com.coderdream.model.UserL
import com.coderdream.util.DBU
public class UserLocationDao {
* 保存用户地理位置
* @param request
* @param openId
用户的OpenID
* @param lng
用户发送的经度
* @param lat
用户发送的纬度
* @param bd09_lng
经过百度坐标转换后的经度
* @param bd09_lat
经过百度坐标转换后的纬度
public int saveUserLocation(String openId, String lng, String lat, String bd09_lng, String bd09_lat) {
String sql = "insert into user_location(open_id, lng, lat, bd09_lng, bd09_lat) values (?, ?, ?, ?, ?)";
int count = 0;
Connection con =
PreparedStatement ps =
con = DBUtil.getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, openId);
ps.setString(2, lng);
ps.setString(3, lat);
ps.setString(4, bd09_lng);
ps.setString(5, bd09_lat);
count = ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 释放资源
DBUtil.close(ps);
DBUtil.close(con);
* 获取用户最后一次发送的地理位置
* @param request
* @param openId
用户的OpenID
* @return UserLocation
public UserLocation getLastLocation(String openId) {
UserLocation userLocation =
String sql = "select open_id, lng, lat, bd09_lng, bd09_lat from user_location where open_id=? order by id desc limit 0,1";
Connection con =
PreparedStatement pre =
ResultSet rs =
con = DBUtil.getConnection();
pre = con.prepareStatement(sql);
pre.setString(1, openId);
rs = pre.executeQuery();
if (rs.next()) {
userLocation = new UserLocation();
userLocation.setOpenId(rs.getString("open_id"));
userLocation.setLng(rs.getString("lng"));
userLocation.setLat(rs.getString("lat"));
userLocation.setBd09Lng(rs.getString("bd09_lng"));
userLocation.setBd09Lat(rs.getString("bd09_lat"));
// 释放资源
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(rs);
DBUtil.close(pre);
DBUtil.close(con);
return userL
百度地图工具类
BaiduMapUtil.java
package com.coderdream.
import it.sauronsoftware.base64.Base64;
import java.io.BufferedR
import java.io.InputS
import java.io.InputStreamR
import java.io.UnsupportedEncodingE
import java.net.HttpURLC
import java.net.URL;
import java.net.URLE
import java.util.ArrayL
import java.util.C
import java.util.L
import net.sf.json.JSONO
import org.dom4j.D
import org.dom4j.DocumentH
import org.dom4j.E
import com.coderdream.model.A
import com.coderdream.model.BaiduP
import com.coderdream.model.UserL
* 百度地图操作类 javabase64-1.3.1.jar
public class BaiduMapUtil {
* 圆形区域检索
* @param query
检索关键词
* @param lng
* @param lat
* @return List&BaiduPlace&
* @throws UnsupportedEncodingException
public static List&BaiduPlace& searchPlace(String query, String lng, String lat) throws Exception {
// 拼装请求地址
String requestUrl = "http://api./place/v2/search?&query=QUERY&location=LAT,LNG&radius=2000&output=xml&scope=2&page_size=10&page_num=0&ak=CA21bdecc75efcc30bb4e";
requestUrl = requestUrl.replace("QUERY", URLEncoder.encode(query, "UTF-8"));
requestUrl = requestUrl.replace("LAT", lat);
requestUrl = requestUrl.replace("LNG", lng);
// 调用Place API圆形区域检索
String respXml = httpRequest(requestUrl);
// 解析返回的xml
List&BaiduPlace& placeList = parsePlaceXml(respXml);
return placeL
* 发送http请求
* @param requestUrl
* @return String
public static String httpRequest(String requestUrl) {
StringBuffer buffer = new StringBuffer();
URL url = new URL(requestUrl);
HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();
httpUrlConn.setDoInput(true);
httpUrlConn.setRequestMethod("GET");
httpUrlConn.connect();
// 将返回的输入流转换成字符串
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str =
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
inputStream =
httpUrlConn.disconnect();
} catch (Exception e) {
e.printStackTrace();
return buffer.toString();
* 根据百度地图返回的流解析出地址信息
* @param inputStream
* @return List&BaiduPlace&
@SuppressWarnings("unchecked")
private static List&BaiduPlace& parsePlaceXml(String xml) {
List&BaiduPlace& placeList =
Document document = DocumentHelper.parseText(xml);
// 得到xml根元素
Element root = document.getRootElement();
// 从根元素获取&results&
Element resultsElement = root.element("results");
// 从&results&中获取&result&集合
List&Element& resultElementList = resultsElement.elements("result");
// 判断&result&集合的大小
if (resultElementList.size() & 0) {
placeList = new ArrayList&BaiduPlace&();
// POI名称
Element nameElement =
// POI地址信息
Element addressElement =
// POI经纬度坐标
Element locationElement =
// POI电话信息
Element telephoneElement =
// POI扩展信息
Element detailInfoElement =
// 距离中心点的距离
Element distanceElement =
// 遍历&result&集合
for (Element resultElement : resultElementList) {
nameElement = resultElement.element("name");
addressElement = resultElement.element("address");
locationElement = resultElement.element("location");
telephoneElement = resultElement.element("telephone");
detailInfoElement = resultElement.element("detail_info");
BaiduPlace place = new BaiduPlace();
place.setName(nameElement.getText());
place.setAddress(addressElement.getText());
place.setLng(locationElement.element("lng").getText());
place.setLat(locationElement.element("lat").getText());
// 当&telephone&元素存在时获取电话号码
if (null != telephoneElement)
place.setTelephone(telephoneElement.getText());
// 当&detail_info&元素存在时获取&distance&
if (null != detailInfoElement) {
distanceElement = detailInfoElement.element("distance");
if (null != distanceElement)
place.setDistance(Integer.parseInt(distanceElement.getText()));
placeList.add(place);
// 按距离由近及远排序
Collections.sort(placeList);
} catch (Exception e) {
e.printStackTrace();
return placeL
* 根据Place组装图文列表
* @param placeList
* @param bd09Lng
* @param bd09Lat
* @return List&Article&
public static List&Article& makeArticleList(List&BaiduPlace& placeList, String bd09Lng, String bd09Lat) {
// 项目的根路径
String basePath = "http://1./";
List&Article& list = new ArrayList&Article&();
BaiduPlace place =
for (int i = 0; i & placeList.size(); i++) {
place = placeList.get(i);
Article article = new Article();
article.setTitle(place.getName() + "\n距离约" + place.getDistance() + "米");
// P1表示用户发送的位置(坐标转换后),p2表示当前POI所在位置
article.setUrl(String.format(basePath + "route.jsp?p1=%s,%s&p2=%s,%s", bd09Lng, bd09Lat, place.getLng(),
place.getLat()));
// 将首条图文的图片设置为大图
if (i == 0)
article.setPicUrl(basePath + "images/poisearch.png");
article.setPicUrl(basePath + "images/navi.png");
list.add(article);
* 将微信定位的坐标转换成百度坐标(GCJ-02 -& Baidu)
* @param lng
* @param lat
* @return UserLocation
public static UserLocation convertCoord(String lng, String lat) {
// 百度坐标转换接口
String convertUrl = "http://api./ag/coord/convert?from=2&to=4&x={x}&y={y}";
convertUrl = convertUrl.replace("{x}", lng);
convertUrl = convertUrl.replace("{y}", lat);
UserLocation location = new UserLocation();
String jsonCoord = httpRequest(convertUrl);
JSONObject jsonObject = JSONObject.fromObject(jsonCoord);
// 对转换后的坐标进行Base64解码
location.setBd09Lng(Base64.decode(jsonObject.getString("x"), "UTF-8"));
location.setBd09Lat(Base64.decode(jsonObject.getString("y"), "UTF-8"));
} catch (Exception e) {
location =
e.printStackTrace();
&%@ page language="java" pageEncoding="UTF-8"%&
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&
&base href="&%=basePath%&"&
&title&步行导航&/title&
&meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=0;"&
&meta http-equiv="Content-Type" content="text/ charset=gb2312" /&
&style type="text/css"&
body, html,#allmap {width: 100%;height: 100%;overflow:margin:0;}
&script type="text/javascript" src="http://api./api?v=1.5&ak=CA21bdecc75efcc30bb4e"&&/script&
String p1 = request.getParameter("p1");
String p2 = request.getParameter("p2");
&div id="allmap"&&/div&
&script type="text/javascript"&
// 创建起点、终点的经纬度坐标点
var p1 = new BMap.Point(&%=p1%&);
var p2 = new BMap.Point(&%=p2%&);
// 创建地图、设置中心坐标和默认缩放级别
var map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point((p1.lng+p2.lng)/2, (p1.lat+p2.lat)/2), 17);
// 右下角添加缩放按钮
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));
// 步行导航检索
var walking = new BMap.WalkingRoute(map, {renderOptions:{map: map, autoViewport: true}});
walking.search(p1, p2);
核心服务类
更新代码后,能实现查找附近功能;
1)发送地理位置;
点击窗口底部的“+”按钮,选择“位置”,点“发送”
2)指定关键词搜索;
格式:附近+关键词\n例如:附近ATM、附近KTV、附近厕所。
CoreService.java
package com.coderdream.
import java.io.InputS
import java.text.DateF
import java.text.SimpleDateF
import java.util.ArrayL
import java.util.C
import java.util.D
import java.util.L
import java.util.M
import org.apache.log4j.L
import com.coderdream.bean.L
import com.coderdream.dao.LoggingD
import com.coderdream.dao.UserLocationD
import com.coderdream.model.A
import com.coderdream.model.BaiduP
import com.coderdream.model.M
import com.coderdream.model.MusicM
import com.coderdream.model.NewsM
import com.coderdream.model.TextM
import com.coderdream.model.UserL
import com.coderdream.util.BaiduMapU
import com.coderdream.util.MessageU
* 核心服务类
public class CoreService {
public static String TAG = "CoreService";
private Logger logger = Logger.getLogger(CoreService.class);
private LoggingDao loggingDao = new LoggingDao(this.getClass().getName());
private UserLocationDao userLocationDao = new UserLocationDao();
* 处理微信发来的请求
* @param request
* @return xml
public String processRequest(InputStream inputStream) {
logger.debug(TAG + " #1# processRequest");
SimpleDateFormat f_timestamp = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
Logging logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG,
"#1# processRequest");
loggingDao.addLogging(logging);
// xml格式的消息数据
String respXml =
// 默认返回的文本消息内容
String respContent = "未知的消息类型!";
// 调用parseXml方法解析请求消息
Map&String, String& requestMap = MessageUtil.parseXml(inputStream);
// 发送方帐号
String fromUserName = requestMap.get("FromUserName");
// 开发者微信号
String toUserName = requestMap.get("ToUserName");
// 消息类型
String msgType = requestMap.get("MsgType");
String logStr = "#2# fromUserName: " + fromUserName + ", toUserName: " + toUserName + ", msgType: "
logger.debug(TAG + logStr);
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG, logStr);
loggingDao.addLogging(logging);
// 回复文本消息
TextMessage textMessage = new TextMessage();
textMessage.setToUserName(fromUserName);
textMessage.setFromUserName(toUserName);
textMessage.setCreateTime(new Date().getTime());
textMessage.setMsgType(MessageUtil.MESSAGE_TYPE_TEXT);
logStr = "#3# textMessage: " + textMessage.toString();
logger.debug(TAG + logStr);
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG, logStr);
loggingDao.addLogging(logging);
// 文本消息
if (msgType.equals(MessageUtil.MESSAGE_TYPE_TEXT)) {
// respContent = "您发送的是文本消息!";
// 接收用户发送的文本消息内容
String content = requestMap.get("Content").trim();
// 创建图文消息
NewsMessage newsMessage = new NewsMessage();
newsMessage.setToUserName(fromUserName);
newsMessage.setFromUserName(toUserName);
newsMessage.setCreateTime(new Date().getTime());
newsMessage.setMsgType(MessageUtil.MESSAGE_TYPE_NEWS);
newsMessage.setFuncFlag(0);
List&Article& articleList = new ArrayList&Article&();
if (content.startsWith("翻译")) {
String keyWord = content.replaceAll("^翻译", "").trim();
if ("".equals(keyWord)) {
textMessage.setContent(getTranslateUsage());
textMessage.setContent(BaiduTranslateService.translate(keyWord));
respContent = textMessage.getContent();
// 如果以“歌曲”2个字开头
else if (content.startsWith("歌曲")) {
// 将歌曲2个字及歌曲后面的+、空格、-等特殊符号去掉
String keyWord = content.replaceAll("^歌曲[\\+ ~!@#%^-_=]?", "");
// 如果歌曲名称为空
if ("".equals(keyWord)) {
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG,
"#歌曲名称为空#");
loggingDao.addLogging(logging);
respContent = getMusicUsage();
String[] kwArr = keyWord.split("@");
// 歌曲名称
String musicTitle = kwArr[0];
// 演唱者默认为空
String musicAuthor = "";
if (2 == kwArr.length) {
musicAuthor = kwArr[1];
// 搜索音乐
Music music = BaiduMusicService.searchMusic(musicTitle, musicAuthor);
// 未搜索到音乐
if (null == music) {
respContent = "对不起,没有找到你想听的歌曲&" + musicTitle + "&。";
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG,
"#未搜索到音乐 respContent# " + respContent);
loggingDao.addLogging(logging);
// 音乐消息
("找到 " + musicTitle + " 了!!!");
MusicMessage musicMessage = new MusicMessage();
musicMessage.setToUserName(fromUserName);
musicMessage.setFromUserName(toUserName);
musicMessage.setCreateTime(new Date().getTime());
musicMessage.setMsgType(MessageUtil.MESSAGE_TYPE_MUSIC);
musicMessage.setMusic(music);
newsMessage.setFuncFlag(0);
respXml = MessageUtil.messageToXml(musicMessage);
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG,
"#return respXml# " + respXml);
loggingDao.addLogging(logging);
return respX
// 如果以“历史”2个字开头
else if (content.startsWith("历史")) {
// 将歌曲2个字及歌曲后面的+、空格、-等特殊符号去掉
String dayStr = content.substring(2);
// 如果只输入历史两个字,在输出当天的历史
if (null == dayStr || "".equals(dayStr.trim())) {
DateFormat df = new SimpleDateFormat("MMdd");
dayStr = df.format(Calendar.getInstance().getTime());
respContent = TodayInHistoryService.getTodayInHistoryInfoFromDB(dayStr);
// 周边搜索
else if (content.startsWith("附近")) {
String keyWord = content.replaceAll("附近", "").trim();
// 获取用户最后一次发送的地理位置
UserLocation location = userLocationDao.getLastLocation(fromUserName);
// 未获取到
if (null == location) {
respContent = getLocationUsage();
// 根据转换后(纠偏)的坐标搜索周边POI
List&BaiduPlace& placeList = BaiduMapUtil.searchPlace(keyWord, location.getBd09Lng(),
location.getBd09Lat());
// 未搜索到POI
if (null == placeList || 0 == placeList.size()) {
respContent = String.format("/难过,您发送的位置附近未搜索到“%s”信息!", keyWord);
articleList = BaiduMapUtil.makeArticleList(placeList, location.getBd09Lng(),
location.getBd09Lat());
// 回复图文消息
newsMessage = new NewsMessage();
newsMessage.setToUserName(fromUserName);
newsMessage.setFromUserName(toUserName);
newsMessage.setCreateTime(new Date().getTime());
newsMessage.setMsgType(MessageUtil.MESSAGE_TYPE_NEWS);
newsMessage.setArticles(articleList);
newsMessage.setArticleCount(articleList.size());
return MessageUtil.messageToXml(newsMessage);
// 单图文消息
else if ("1".equals(content)) {
Article article = new Article();
article.setTitle("微信公众帐号开发教程Java版");
article.setDescription("柳峰,80后,微信公众帐号开发经验4个月。为帮助初学者入门,特推出此系列教程,也希望借此机会认识更多同行!");
article.setPicUrl("/meal.jpg");
article.setUrl("http://blog.csdn.net/lyq8479?toUserName=" + fromUserName + "&toUserName="
+ toUserName);
articleList.add(article);
// 设置图文消息个数
newsMessage.setArticleCount(articleList.size());
// 设置图文消息包含的图文集合
newsMessage.setArticles(articleList);
// 将图文消息对象转换成xml字符串
return MessageUtil.messageToXml(newsMessage);
// 单图文消息---不含图片
else if ("2".equals(content)) {
Article article = new Article();
article.setTitle("微信公众帐号开发教程Java版");
// 图文消息中可以使用QQ表情、符号表情
article.setDescription("柳峰,80后,"
// + emoji(0x1F6B9)
+ ",微信公众帐号开发经验4个月。为帮助初学者入门,特推出此系列连载教程,也希望借此机会认识更多同行!\n\n目前已推出教程共12篇,包括接口配置、消息封装、框架搭建、QQ表情发送、符号表情发送等。\n\n后期还计划推出一些实用功能的开发讲解,例如:天气预报、周边搜索、聊天功能等。");
// 将图片置为空
article.setPicUrl("");
article.setUrl("http://blog.csdn.net/lyq8479?toUserName=" + fromUserName + "&toUserName="
+ toUserName);
articleList.add(article);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
return MessageUtil.messageToXml(newsMessage);
// 多图文消息
else if ("3".equals(content)) {
Article article1 = new Article();
article1.setTitle("微信公众帐号开发教程\n引言");
article1.setDescription("");
article1.setPicUrl("/meal.jpg");
article1.setUrl("http://blog.csdn.net/lyq8479/article/details/8937622?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
Article article2 = new Article();
article2.setTitle("第2篇\n微信公众帐号的类型");
article2.setDescription("");
article2.setPicUrl("/meal.jpg");
article2.setUrl("http://blog.csdn.net/lyq8479/article/details/8941577?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
Article article3 = new Article();
article3.setTitle("关注页面");
article3.setDescription("关注页面");
article3.setPicUrl("/meal.jpg");
article3.setUrl("/follow.jsp?toUserName=" + fromUserName + "&toUserName="
+ toUserName);
articleList.add(article1);
articleList.add(article2);
articleList.add(article3);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
return MessageUtil.messageToXml(newsMessage);
// 多图文消息---首条消息不含图片
else if ("4".equals(content)) {
Article article1 = new Article();
article1.setTitle("微信公众帐号开发教程Java版");
article1.setDescription("");
// 将图片置为空
article1.setPicUrl("");
article1.setUrl("http://blog.csdn.net/lyq8479");
Article article2 = new Article();
article2.setTitle("第4篇\n消息及消息处理工具的封装");
article2.setDescription("");
article2.setPicUrl("/meal.jpg");
article2.setUrl("http://blog.csdn.net/lyq8479/article/details/8949088?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
Article article3 = new Article();
article3.setTitle("第5篇\n各种消息的接收与响应");
article3.setDescription("");
article3.setPicUrl("/meal.jpg");
article3.setUrl("http://blog.csdn.net/lyq8479/article/details/8952173?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
Article article4 = new Article();
article4.setTitle("第6篇\n文本消息的内容长度限制揭秘");
article4.setDescription("");
article4.setPicUrl("/meal.jpg");
article4.setUrl("http://blog.csdn.net/lyq8479/article/details/8967824?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
articleList.add(article1);
articleList.add(article2);
articleList.add(article3);
articleList.add(article4);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
return MessageUtil.messageToXml(newsMessage);
// 多图文消息---最后一条消息不含图片
else if ("5".equals(content)) {
Article article1 = new Article();
article1.setTitle("第7篇\n文本消息中换行符的使用");
article1.setDescription("");
article1.setPicUrl("/meal.jpg");
article1.setUrl("http://blog.csdn.net/lyq8479/article/details/9141467?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
Article article2 = new Article();
article2.setTitle("第8篇\n文本消息中使用网页超链接");
article2.setDescription("");
article2.setPicUrl("/meal.jpg");
article2.setUrl("http://blog.csdn.net/lyq8479/article/details/9157455?toUserName=" + fromUserName
+ "&toUserName=" + toUserName);
Article article3 = new Article();
article3.setTitle("如果觉得文章对你有所帮助,请通过博客留言或关注微信公众帐号xiaoqrobot来支持柳峰!");
article3.setDescription("");
// 将图片置为空
article3.setPicUrl("");
article3.setUrl("http://blog.csdn.net/lyq8479");
articleList.add(article1);
articleList.add(article2);
articleList.add(article3);
newsMessage.setArticleCount(articleList.size());
newsMessage.setArticles(articleList);
return MessageUtil.messageToXml(newsMessage);
// 其他,弹出帮助信息
respContent = getUsage();
// 图片消息
else if (msgType.equals(MessageUtil.MESSAGE_TYPE_IMAGE)) {
respContent = "您发送的是图片消息!";
// 语音消息
else if (msgType.equals(MessageUtil.MESSAGE_TYPE_VOICE)) {
respContent = "您发送的是语音消息!";
// 视频消息
else if (msgType.equals(MessageUtil.MESSAGE_TYPE_VIDEO)) {
respContent = "您发送的是视频消息!";
// 地理位置消息
else if (msgType.equals(MessageUtil.MESSAGE_TYPE_LOCATION)) {
respContent = "您发送的是地理位置消息!";
// 用户发送的经纬度
String lng = requestMap.get("Location_Y");
String lat = requestMap.get("Location_X");
// 坐标转换后的经纬度
String bd09Lng =
String bd09Lat =
// 调用接口转换坐标
UserLocation userLocation = BaiduMapUtil.convertCoord(lng, lat);
if (null != userLocation) {
bd09Lng = userLocation.getBd09Lng();
bd09Lat = userLocation.getBd09Lat();
("lng= " + lng + "; lat= " + lat);
("bd09Lng= " + bd09Lng + "; bd09Lat= " + bd09Lat);
// 保存用户地理位置
int count = userLocationDao.saveUserLocation(fromUserName, lng, lat, bd09Lng, bd09Lat);
loggingDao.debug("fromUserName" + fromUserName + "lng= " + lng + "; lat= " + lat + "bd09Lng= "
+ bd09Lng + "; bd09Lat= " + bd09Lat + "count" + count);
StringBuffer buffer = new StringBuffer();
buffer.append("[愉快]").append("成功接收您的位置!").append("\n\n");
buffer.append("您可以输入搜索关键词获取周边信息了,例如:").append("\n");
buffer.append("
附近ATM").append("\n");
buffer.append("
附近KTV").append("\n");
buffer.append("
附近厕所").append("\n");
buffer.append("必须以“附近”两个字开头!");
respContent = buffer.toString();
// 链接消息
else if (msgType.equals(MessageUtil.MESSAGE_TYPE_LINK)) {
respContent = "您发送的是链接消息!";
// 事件推送
else if (msgType.equals(MessageUtil.MESSAGE_TYPE_EVENT)) {
// 事件类型
String eventType = requestMap.get("Event");
if (eventType.equals(MessageUtil.EVENT_TYPE_SUBSCRIBE)) {
respContent = "谢谢您的关注!/n";
respContent += getSubscribeMsg();
// 取消关注
else if (eventType.equals(MessageUtil.EVENT_TYPE_UNSUBSCRIBE)) {
// TODO 取消订阅后用户不会再收到公众账号发送的消息,因此不需要回复
// 扫描带参数二维码
else if (eventType.equals(MessageUtil.EVENT_TYPE_SCAN)) {
// TODO 处理扫描带参数二维码事件
// 上报地理位置
else if (eventType.equals(MessageUtil.EVENT_TYPE_LOCATION)) {
// TODO 处理上报地理位置事件
// 自定义菜单
else if (eventType.equals(MessageUtil.EVENT_TYPE_CLICK)) {
// TODO 处理菜单点击事件
logStr = "#4# respContent: " + respC
logger.debug(TAG + logStr);
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG, logStr);
loggingDao.addLogging(logging);
// 设置文本消息的内容
textMessage.setContent(respContent);
// 将文本消息对象转换成xml
respXml = MessageUtil.messageToXml(textMessage);
logStr = "#5# respXml: " + respX
logger.debug(TAG + logStr);
logging = new Logging(f_timestamp.format(Calendar.getInstance().getTime()), "DEBUG", TAG, logStr);
loggingDao.addLogging(logging);
} catch (Exception e) {
e.printStackTrace();
return respX
* 翻译使用指南
public static String getTranslateUsage() {
StringBuffer buffer = new StringBuffer();
// buffer.append(XiaoqUtil.emoji(0xe148)).append("Q译通使用指南").append("\n\n");
buffer.append("Q译通为用户提供专业的多语言翻译服务,目前支持以下翻译方向:").append("\n");
buffer.append("
中 -& 英").append("\n");
buffer.append("
英 -& 中").append("\n");
buffer.append("
日 -& 中").append("\n\n");
buffer.append("使用示例:").append("\n");
buffer.append("
翻译我是中国人").append("\n");
buffer.append("
翻译dream").append("\n");
buffer.append("
翻译さようなら").append("\n\n");
buffer.append("回复“?”显示主菜单");
return buffer.toString();
* 歌曲点播使用指南
public static String getMusicUsage() {
StringBuffer buffer = new StringBuffer();
buffer.append("歌曲点播操作指南").append("\n\n");
buffer.append("回复:歌曲+歌名").append("\n");
buffer.append("例如:歌曲存在").append("\n");
buffer.append("或者:歌曲存在@汪峰").append("\n\n");
buffer.append("回复“?”显示主菜单");
return buffer.toString();
* 歌曲点播使用指南
public static String getUsage() {
StringBuffer buffer = new StringBuffer();
buffer.append("历史年月(历史0403)").append("\n");
buffer.append("歌曲歌名(歌曲)").append("\n");
buffer.append("翻译词语(翻译明天)-支持中英日语").append("\n");
buffer.append("回复“?”显示主菜单");
return buffer.toString();
* 关注提示语
public static String getSubscribeMsg() {
StringBuffer buffer = new StringBuffer();
buffer.append("您是否有过出门在外四处找ATM或厕所的经历?").append("\n\n");
buffer.append("您是否有过出差在外搜寻美食或娱乐场所的经历?").append("\n\n");
buffer.append("周边搜索为您的出行保驾护航,为您提供专业的周边生活指南,回复“附近”开始体验吧!");
return buffer.toString();
* 使用说明
public static String getLocationUsage() {
StringBuffer buffer = new StringBuffer();
buffer.append("周边搜索使用说明").append("\n\n");
buffer.append("1)发送地理位置").append("\n");
buffer.append("点击窗口底部的“+”按钮,选择“位置”,点“发送”").append("\n\n");
buffer.append("2)指定关键词搜索").append("\n");
buffer.append("格式:附近+关键词\n例如:附近ATM、附近KTV、附近厕所");
return buffer.toString();
消息处理工具类
MessageUtil.java
package com.coderdream.
import java.io.InputS
import java.io.W
import java.util.HashM
import java.util.L
import java.util.M
import org.apache.log4j.L
import org.dom4j.D
import org.dom4j.E
import org.dom4j.io.SAXR
import com.coderdream.model.A
import com.coderdream.model.MusicM
import com.coderdream.model.NewsM
import com.coderdream.model.TextM
import com.thoughtworks.xstream.XS
import com.thoughtworks.xstream.core.util.QuickW
import com.thoughtworks.xstream.io.HierarchicalStreamW
import com.thoughtworks.xstream.io.xml.PrettyPrintW
import com.thoughtworks.xstream.io.xml.XppD
* 消息处理工具类
public class MessageUtil {
public static String TAG = "MessageUtil";
private static Logger logger = Logger.getLogger(MessageUtil.class);
* 请求消息类型:文本
public static final String MESSAGE_TYPE_TEXT = "text";
* 请求消息类型:图片
public static final String MESSAGE_TYPE_IMAGE = "image";
* 请求消息类型:语音
public static final String MESSAGE_TYPE_VOICE = "voice";
* 请求消息类型:视频
public static final String MESSAGE_TYPE_VIDEO = "video";
* 请求消息类型:地理位置
public static final String MESSAGE_TYPE_LOCATION = "location";
* 请求消息类型:链接
public static final String MESSAGE_TYPE_LINK = "link";
* 请求消息类型:事件推送
public static final String MESSAGE_TYPE_EVENT = "event";
* 事件类型:subscribe(订阅)
public static final String EVENT_TYPE_SUBSCRIBE = "subscribe";
* 事件类型:unsubscribe(取消订阅)
public static final String EVENT_TYPE_UNSUBSCRIBE = "unsubscribe";
* 事件类型:scan(用户已关注时的扫描带参数二维码)
public static final String EVENT_TYPE_SCAN = "scan";
* 事件类型:LOCATION(上报地理位置)
public static final String EVENT_TYPE_LOCATION = "LOCATION";
* 事件类型:CLICK(自定义菜单)
public static final String EVENT_TYPE_CLICK = "CLICK";
* 响应消息类型:图文
public static final String MESSAGE_TYPE_NEWS = "news";
* 响应消息类型:音乐
public static final String MESSAGE_TYPE_MUSIC = "music";
* 解析微信发来的请求(XML)
* @param request
* @return Map&String, String&
* @throws Exception
@SuppressWarnings("unchecked")
public static Map&String, String& parseXml(InputStream inputStream) throws Exception {
// 将解析结果存储在HashMap中
Map&String, String& map = new HashMap&String, String&();
logger.debug(TAG + " begin");
// 从request中取得输入流
// InputStream inputStream = request.getInputStream();
// 读取输入流
SAXReader reader = new SAXReader();
Document document = reader.read(inputStream);
logger.debug(TAG + " read inputStream");
// 得到xml根元素
Element root = document.getRootElement();
// 得到根元素的所有子节点
List&Element& elementList = root.elements();
// 遍历所有子节点
for (Element e : elementList) {
map.put(e.getName(), e.getText());
logger.debug(TAG + " ###### log4j debug" + e.getName() + " : " + e.getText());
// 释放资源
inputStream.close();
inputStream =
* 扩展xstream使其支持CDATA
private static XStream xstream = new XStream(new XppDriver() {
public HierarchicalStreamWriter createWriter(Writer out) {
return new PrettyPrintWriter(out) {
// 对所有xml节点的转换都增加CDATA标记
boolean cdata =
@SuppressWarnings("rawtypes")
public void startNode(String name, Class clazz) {
super.startNode(name, clazz);
protected void writeText(QuickWriter writer, String text) {
if (cdata) {
writer.write("&![CDATA[");
writer.write(text);
writer.write("]]&");
writer.write(text);
* 文本消息对象转换成xml
* @param textMessage
文本消息对象
* @return xml
public static String messageToXml(TextMessage textMessage) {
xstream.alias("xml", textMessage.getClass());
return xstream.toXML(textMessage);
* 图文消息对象转换成xml
* @param newsMessage
图文消息对象
* @return xml
public static String messageToXml(NewsMessage newsMessage) {
xstream.alias("xml", newsMessage.getClass());
xstream.alias("item", new Article().getClass());
return xstream.toXML(newsMessage);
* 音乐消息对象转换成xml
* @param musicMessage
音乐消息对象
* @return xml
public static String messageToXml(MusicMessage musicMessage) {
xstream.alias("xml", musicMessage.getClass());
String musicString = xstream.toXML(musicMessage);
return musicS
Maven工程配置文件
&project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&
&modelVersion&4.0.0&/modelVersion&
&groupId&com.coderdream&/groupId&
&artifactId&wxquan&/artifactId&
&packaging&war&/packaging&
&version&0.0.1-SNAPSHOT&/version&
&name&wxquan Maven Webapp&/name&
&url&http://maven.apache.org&/url&
&properties&
&junit.version&4.11&/junit.version&
&servlet.api.version&2.5&/servlet.api.version&
&jsp.api.version&2.1&/jsp.api.version&
&slf4j.version&1.7.5&/slf4j.version&
&dom4j.version&1.6.1&/dom4j.version&
&xstream.version&1.4.7&/xstream.version&
&mysql.version&5.1.17&/mysql.version&
&dbunit.version&2.4.9&/dbunit.version&
&gson.version&2.2.4&/gson.version&
&json.version&2.4&/json.version&
&javabase.version&1.3.1&/javabase.version&
&/properties&
&dependencies&
&!-- 测试的时候用到,打包的时候没有 --&
&dependency&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&${junit.version}&/version&
&scope&test&/scope&
&/dependency&
&!-- 编译的时候用到,打包的时候没有 --&
&dependency&
&groupId&javax.servlet&/groupId&
&artifactId&servlet-api&/artifactId&
&version&${servlet.api.version}&/version&
&scope&provided&/scope&
&/dependency&
&!-- 编译的时候用到,打包的时候没有 --&
&dependency&
&groupId&javax.servlet.jsp&/groupId&
&artifactId&jsp-api&/artifactId&
&version&${jsp.api.version}&/version&
&scope&provided&/scope&
&/dependency&
&!-- 日志包 --&
&dependency&
&groupId&org.slf4j&/groupId&
&artifactId&slf4j-log4j12&/artifactId&
&version&${slf4j.version}&/version&
&/dependency&
&!-- 打包的时候剔除 xml-apis-1.0.b2.jar SAE中不支持 --&
&dependency&
&groupId&dom4j&/groupId&
&artifactId&dom4j&/artifactId&
&version&${dom4j.version}&/version&
&exclusions&
&exclusion&
&groupId&xml-apis&/groupId&
&artifactId&xml-apis&/artifactId&
&/exclusion&
&/exclusions&
&/dependency&
&!-- 打包的时候剔除 xml-apis-1.0.b2.jar SAE中不支持 --&
&!-- 这个jar必须用1.4.7的高版本,否则SAE不支持 --&
&!-- 详细原因:http://blog.csdn.net/lyq8479/article/details/ --&
&dependency&
&groupId&com.thoughtworks.xstream&/groupId&
&artifactId&xstream&/artifactId&
&version&${xstream.version}&/version&
&/dependency&
&!-- 编译的时候用到,打包的时候没有,SAE已包含此jar --&
&dependency&
&groupId&mysql&/groupId&
&artifactId&mysql-connector-java&/artifactId&
&version&${mysql.version}&/version&
&scope&provided&/scope&
&/dependency&
&!-- 测试的时候用到,打包的后WAR里没有 --&
&dependency&
&groupId&org.dbunit&/groupId&
&artifactId&dbunit&/artifactId&
&version&${dbunit.version}&/version&
&scope&test&/scope&
&/dependency&
&dependency&
&groupId&com.google.code.gson&/groupId&
&artifactId&gson&/artifactId&
&version&${gson.version}&/version&
&/dependency&
&dependency&
&groupId&net.sf.json-lib&/groupId&
&artifactId&json-lib&/artifactId&
&version&${json.version}&/version&
&/dependency&
&dependency&
&groupId&it.sauronsoftware&/groupId&
&artifactId&javabase64&/artifactId&
&version&${javabase.version}&/version&
&/dependency&
&/dependencies&
&finalName&wxquan&/finalName&
&/project&
上传本地代码到GitHub
将新增和修改过的代码上传到GitHub
上传工程WAR档至SAE
将eclipse中的工程导出为wxquan.war档,上传到SAE中,更新已有的版本。
微信客户端测试
登录微信网页版:/
先提交位置信息,然后输入“附近咖啡厅”,返回附近咖啡厅的图文信息。
完整源代码
(268.4 KB)
下载次数: 214
论坛回复 /
(0 / 1457)
CoderDream
浏览: 337902 次
来自: 武汉
谢楼主分享,确实是CSS图片问题
javaBase那个包显示有问题啊pom文件那一行报错了
jd技术这么渣也好意思出书,真是醉了
刘强东作序多什么,他也不会什么技术,腾讯出来帮他还不是因为腾讯 ...
想试试搞这个
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'}

我要回帖

更多关于 标致3008是什么平台的 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信