【移动应用开发技术】如何使用java实现微信分类接收消息以及创建实体_第1页
【移动应用开发技术】如何使用java实现微信分类接收消息以及创建实体_第2页
【移动应用开发技术】如何使用java实现微信分类接收消息以及创建实体_第3页
【移动应用开发技术】如何使用java实现微信分类接收消息以及创建实体_第4页
【移动应用开发技术】如何使用java实现微信分类接收消息以及创建实体_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】如何使用java实现微信分类接收消息以及创建实体

(一)消息实体基础类package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

BaseMessage

*

@Description:

微信请求消息基本类

*

@author

dapengniao

*

@date

2016年3月7日

下午3:03:59

*/

public

class

BaseMessage

{

//

开发者微信号

private

String

ToUserName;

//

发送方帐号(一个OpenID)

private

String

FromUserName;

//

消息创建时间

(整型)

private

long

CreateTime;

//

消息类型(text/image/location/link/video/shortvideo)

private

String

MsgType;

//

消息id,64位整型

private

long

MsgId;

public

String

getToUserName()

{

return

ToUserName;

}

public

void

setToUserName(String

toUserName)

{

ToUserName

=

toUserName;

}

public

String

getFromUserName()

{

return

FromUserName;

}

public

void

setFromUserName(String

fromUserName)

{

FromUserName

=

fromUserName;

}

public

long

getCreateTime()

{

return

CreateTime;

}

public

void

setCreateTime(long

createTime)

{

CreateTime

=

createTime;

}

public

String

getMsgType()

{

return

MsgType;

}

public

void

setMsgType(String

msgType)

{

MsgType

=

msgType;

}

public

long

getMsgId()

{

return

MsgId;

}

public

void

setMsgId(long

msgId)

{

MsgId

=

msgId;

}

}(二)普通消息pojo实体package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

ImageMessage

*

@Description:

图片消息

*

@author

dapengniao

*

@date

2016年3月7日

下午3:04:52

*/

public

class

ImageMessage

extends

BaseMessage

{

//

图片链接

private

String

PicUrl;

public

String

getPicUrl()

{

return

PicUrl;

}

public

void

setPicUrl(String

picUrl)

{

PicUrl

=

picUrl;

}

}package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

LinkMessage

*

@Description:

连接消息

*

@author

dapengniao

*

@date

2016年3月7日

下午3:05:48

*/

public

class

LinkMessage

extends

BaseMessage

{

//

消息标题

private

String

Title;

//

消息描述

private

String

Description;

//

消息链接

private

String

Url;

public

String

getTitle()

{

return

Title;

}

public

void

setTitle(String

title)

{

Title

=

title;

}

public

String

getDescription()

{

return

Description;

}

public

void

setDescription(String

description)

{

Description

=

description;

}

public

String

getUrl()

{

return

Url;

}

public

void

setUrl(String

url)

{

Url

=

url;

}

}package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

LocationMessage

*

@Description:

地理位置消息

*

@author

dapengniao

*

@date

2016年3月7日

下午3:06:10

*/

public

class

LocationMessage

extends

BaseMessage

{

//

地理位置维度

private

String

Location_X;

//

地理位置经度

private

String

Location_Y;

//

地图缩放大小

private

String

Scale;

//

地理位置信息

private

String

Label;

public

String

getLocation_X()

{

return

Location_X;

}

public

void

setLocation_X(String

location_X)

{

Location_X

=

location_X;

}

public

String

getLocation_Y()

{

return

Location_Y;

}

public

void

setLocation_Y(String

location_Y)

{

Location_Y

=

location_Y;

}

public

String

getScale()

{

return

Scale;

}

public

void

setScale(String

scale)

{

Scale

=

scale;

}

public

String

getLabel()

{

return

Label;

}

public

void

setLabel(String

label)

{

Label

=

label;

}

}package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

TextMessage

*

@Description:

文本消息

*

@author

dapengniao

*

@date

2016年3月7日

下午3:06:40

*/

public

class

TextMessage

extends

BaseMessage

{

//

消息内容

private

String

Content;

public

String

getContent()

{

return

Content;

}

public

void

setContent(String

content)

{

Content

=

content;

}

}package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

VideoMessage

*

@Description:

视频/小视屏消息

*

@author

dapengniao

*

@date

2016年3月7日

下午3:12:51

*/

public

class

VideoMessage

extends

BaseMessage

{

private

String

MediaId;

//

视频消息媒体id,可以调用多媒体文件下载接口拉取数据

private

String

ThumbMediaId;

//

视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据

public

String

getMediaId()

{

return

MediaId;

}

public

void

setMediaId(String

mediaId)

{

MediaId

=

mediaId;

}

public

String

getThumbMediaId()

{

return

ThumbMediaId;

}

public

void

setThumbMediaId(String

thumbMediaId)

{

ThumbMediaId

=

thumbMediaId;

}

}package

com.cuiyongzhi.wechat.message.req;

/**

*

ClassName:

VoiceMessage

*

@Description:

语音消息

*

@author

dapengniao

*

@date

2016年3月7日

下午3:07:10

*/

public

class

VoiceMessage

extends

BaseMessage

{

//

媒体ID

private

String

MediaId;

//

语音格式

private

String

Format;

public

String

getMediaId()

{

return

MediaId;

}

public

void

setMediaId(String

mediaId)

{

MediaId

=

mediaId;

}

public

String

getFormat()

{

return

Format;

}

public

void

setFormat(String

format)

{

Format

=

format;

}

}(三)消息分类处理package

com.cuiyongzhi.wechat.dispatcher;

import

java.util.Map;

import

com.cuiyongzhi.wechat.util.MessageUtil;

/**

*

ClassName:

MsgDispatcher

*

@Description:

消息业务处理分发器

*

@author

dapengniao

*

@date

2016年3月7日

下午4:04:21

*/

public

class

MsgDispatcher

{

public

static

String

processMessage(Map<String,

String>

map)

{

if

(map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT))

{

//

文本消息

System.out.println("==============这是文本消息!");

}

if

(map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_IMAGE))

{

//

图片消息

System.out.println("==============这是图片消息!");

}

if

(map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_LINK))

{

//

链接消息

System.out.println("==============这是链接消息!");

}

if

(map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_LOCATION))

{

//

位置消息

System.out.println("==============这是位置消息!");

}

if

(map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_VIDEO))

{

//

视频消息

System.out.println("==============这是视频消息!");

}

if

(map.get("MsgType").equals(MessageUtil.REQ_MESSAGE_TYPE_VOICE))

{

//

语音消息

System.out.println("==============这是语音消息!");

}

return

null;

}

}package

com.cuiyongzhi.wechat.dispatcher;

import

java.util.Map;

import

com.cuiyongzhi.wechat.util.MessageUtil;

/**

*

ClassName:

EventDispatcher

*

@Description:

事件消息业务分发器

*

@author

dapengniao

*

@date

2016年3月7日

下午4:04:41

*/

public

class

EventDispatcher

{

public

static

String

processEvent(Map<String,

String>

map)

{

if

(map.get("Event").equals(MessageUtil.EVENT_TYPE_SUBSCRIBE))

{

//关注事件

System.out.println("==============这是关注事件!");

}

if

(map.get("Event").equals(MessageUtil.EVENT_TYPE_UNSUBSCRIBE))

{

//取消关注事件

System.out.println("==============这是取消关注事件!");

}

if

(map.get("Event").equals(MessageUtil.EVENT_TYPE_SCAN))

{

//扫描二维码事件

System.out.println("==============这是扫描二维码事件!");

}

if

(map.get("Event").equals(MessageUtil.EVENT_TYPE_LOCATION))

{

//位置上报事件

System.out.println("==============这是位置上报事件!");

}

if

(map.get("Event").equals(MessageUtil.EVENT_TYPE_CLICK))

{

//自定义菜单点击事件

System.out.println("==============这是自定义菜单点击事件!");

}

if

(map.get("Event").equals(MessageUtil.EVENT_TYPE_VIEW))

{

//自定义菜单View事件

System.out.println("==============这是自定义菜单View事件!");

}

return

null;

}

}package

com.cuiyongzhi.wechat.controller;

import

java.io.PrintWriter;

import

java.util.Map;

import

javax.servlet.http.HttpServletRequest;

import

javax.servlet.http.HttpServletResponse;

import

org.apache.log4j.Logger;

import

org.springframework.stereotype.Controller;

import

org.springframework.web.bind.annotation.RequestMapping;

import

org.springframework.web.bind.annotation.RequestMethod;

import

org.springframework.web.bind.annotation.RequestParam;

import

com.cuiyongzhi.wechat.dispatcher.EventDispatcher;

import

com.cuiyongzhi.wechat.dispatcher.MsgDispatcher;

import

com.cuiyongzhi.wechat.util.MessageUtil;

import

com.cuiyongzhi.wechat.util.SignUtil;

@Controller

@RequestMapping("/wechat")

public

class

WechatSecurity

{

private

static

Logger

logger

=

Logger.getLogger(WechatSecurity.class);

/**

*

*

@Description:

用于接收get参数,返回验证参数

*

@param

@param

request

*

@param

@param

response

*

@param

@param

signature

*

@param

@param

timestamp

*

@param

@param

nonce

*

@param

@param

echostr

*

@author

dapengniao

*

@date

2016年3月4日

下午6:20:00

*/

@RequestMapping(value

=

"security",

method

=

RequestMethod.GET)

public

void

doGet(

HttpServletRequest

request,

HttpServletResponse

response,

@RequestParam(value

=

"signature",

required

=

true)

String

signature,

@RequestParam(value

=

"timestamp",

required

=

true)

String

timestamp,

@RequestParam(value

=

"nonce",

required

=

true)

String

nonce,

@RequestParam(value

=

"echostr",

required

=

true)

String

echostr)

{

try

{

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论