守望者--AIR技术交流

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: ANE FlasCC 炼金术
查看: 1367|回复: 1

[入门资料] 微信公众平台 java示例 接收消息并回复

[复制链接]
  • TA的每日心情
    擦汗
    2018-4-10 15:18
  • 签到天数: 447 天

    [LV.9]以坛为家II

    1742

    主题

    2094

    帖子

    13万

    积分

    超级版主

    Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

    威望
    562
    贡献
    29
    金币
    52619
    钢镚
    1422

    开源英雄守望者

    发表于 2016-8-18 16:04:21 | 显示全部楼层 |阅读模式
    来源:http://blog.csdn.net/morning99/article/details/43865471

    最近公司在开发微信项目,所以自己也试着申请了个人的订阅服务号,实现了通过微信接收信息转发至java后台解析并回复的消息的简单功能,在还没忘记的时候记录一下,以便日后查阅,并且贡献出代码希望能给大家一个参考。

    好首先你要看下面的示例,要事先申请微信公众平台的订阅服务号(个人只能申请这个),地址https://mp.weixin.qq.com ,申请的范例我这里就不讲了,一般根据提示可以自行完成,如果这都完成不了,那只能去度娘翻翻了。

    要想让用户发送给公众帐号的消息转发给java后台服务器,首先要 在开发者中心 进行 服务器配置 ,

    下图为认证启动后小效果:


    你要先进入到 修改配置里面,如下图:


    你要填写这几个文本框内的内容,

    1.URL 不用解释了,就是微信将用户发来的消息转发到你服务器的请求的地址,我让微信把请求发送到本地服务这样方便调试。

    推荐一款反向代理的工具 pagekite.net ,感兴趣的朋友可以去搜索一下。使用相当方便,就是需要python2.7.x环境支持,然后运行下载的一个脚本,输入你的邮箱,

    然后在输入你要设置的域名前缀,就搞定,下次运行就不用在输入,它影射的是本地80端口,所以你启动服务的时候记得改成80端口就对了,

    还有这个貌似对于一个邮箱只有31天和5个连接的限制,PS:邮箱这东西都是免费的,你懂的。


    2.Token:这个长度符合就行 自己随意

    3.EncodingAESKey:点击随机生成 就OK


    下面介绍我的代码:

    我的开发环境是eclipse+springMvc

    "/chat" 是我最终项目的请求Controller URL路径

    下面是homecontroller


    1. @Controller
    2. @RequestMapping("/*")
    3. public class HomeController {

    4.         private String Token = "123456789abcdef";

    5.         @RequestMapping(value = "chat", method = { RequestMethod.GET, RequestMethod.POST })
    6.         @ResponseBody
    7.         public void liaotian(Model model, HttpServletRequest request, HttpServletResponse response) {
    8.                 System.out.println("进入chat");
    9.                 boolean isGet = request.getMethod().toLowerCase().equals("get");
    10.                 if (isGet) {
    11.                         String signature = request.getParameter("signature");
    12.                         String timestamp = request.getParameter("timestamp");
    13.                         String nonce = request.getParameter("nonce");
    14.                         String echostr = request.getParameter("echostr");
    15.                         System.out.println(signature);
    16.                         System.out.println(timestamp);
    17.                         System.out.println(nonce);
    18.                         System.out.println(echostr);
    19.                         access(request, response);
    20.                 } else {
    21.                         // 进入POST聊天处理
    22.                         System.out.println("enter post");
    23.                         try {
    24.                                 // 接收消息并返回消息
    25.                                 acceptMessage(request, response);
    26.                         } catch (IOException e) {
    27.                                 e.printStackTrace();
    28.                         }
    29.                 }
    30.         }

    31.         /**
    32.          * 验证URL真实性
    33.          *
    34.          * @author morning
    35.          * @date 2015年2月17日 上午10:53:07
    36.          * @param request
    37.          * @param response
    38.          * @return String
    39.          */
    40.         private String access(HttpServletRequest request, HttpServletResponse response) {
    41.                 // 验证URL真实性
    42.                 System.out.println("进入验证access");
    43.                 String signature = request.getParameter("signature");// 微信加密签名
    44.                 String timestamp = request.getParameter("timestamp");// 时间戳
    45.                 String nonce = request.getParameter("nonce");// 随机数
    46.                 String echostr = request.getParameter("echostr");// 随机字符串
    47.                 List<String> params = new ArrayList<String>();
    48.                 params.add(Token);
    49.                 params.add(timestamp);
    50.                 params.add(nonce);
    51.                 // 1. 将token、timestamp、nonce三个参数进行字典序排序
    52.                 Collections.sort(params, new Comparator<String>() {
    53.                         @Override
    54.                         public int compare(String o1, String o2) {
    55.                                 return o1.compareTo(o2);
    56.                         }
    57.                 });
    58.                 // 2. 将三个参数字符串拼接成一个字符串进行sha1加密
    59.                 String temp = SHA1.encode(params.get(0) + params.get(1) + params.get(2));
    60.                 if (temp.equals(signature)) {
    61.                         try {
    62.                                 response.getWriter().write(echostr);
    63.                                 System.out.println("成功返回 echostr:" + echostr);
    64.                                 return echostr;
    65.                         } catch (IOException e) {
    66.                                 e.printStackTrace();
    67.                         }
    68.                 }
    69.                 System.out.println("失败 认证");
    70.                 return null;
    71.         }

    72.         private void acceptMessage(HttpServletRequest request, HttpServletResponse response) throws IOException {
    73.                 // 处理接收消息
    74.                 ServletInputStream in = request.getInputStream();
    75.                 // 将POST流转换为XStream对象
    76.                 XStream xs = SerializeXmlUtil.createXstream();
    77.                 xs.processAnnotations(InputMessage.class);
    78.                 xs.processAnnotations(OutputMessage.class);
    79.                 // 将指定节点下的xml节点数据映射为对象
    80.                 xs.alias("xml", InputMessage.class);
    81.                 // 将流转换为字符串
    82.                 StringBuilder xmlMsg = new StringBuilder();
    83.                 byte[] b = new byte[4096];
    84.                 for (int n; (n = in.read(b)) != -1;) {
    85.                         xmlMsg.append(new String(b, 0, n, "UTF-8"));
    86.                 }
    87.                 // 将xml内容转换为InputMessage对象
    88.                 InputMessage inputMsg = (InputMessage) xs.fromXML(xmlMsg.toString());

    89.                 String servername = inputMsg.getToUserName();// 服务端
    90.                 String custermname = inputMsg.getFromUserName();// 客户端
    91.                 long createTime = inputMsg.getCreateTime();// 接收时间
    92.                 Long returnTime = Calendar.getInstance().getTimeInMillis() / 1000;// 返回时间

    93.                 // 取得消息类型
    94.                 String msgType = inputMsg.getMsgType();
    95.                 // 根据消息类型获取对应的消息内容
    96.                 if (msgType.equals(MsgType.Text.toString())) {
    97.                         // 文本消息
    98.                         System.out.println("开发者微信号:" + inputMsg.getToUserName());
    99.                         System.out.println("发送方帐号:" + inputMsg.getFromUserName());
    100.                         System.out.println("消息创建时间:" + inputMsg.getCreateTime() + new Date(createTime * 1000l));
    101.                         System.out.println("消息内容:" + inputMsg.getContent());
    102.                         System.out.println("消息Id:" + inputMsg.getMsgId());

    103.                         StringBuffer str = new StringBuffer();
    104.                         str.append("<xml>");
    105.                         str.append("<ToUserName><![CDATA[" + custermname + "]]></ToUserName>");
    106.                         str.append("<FromUserName><![CDATA[" + servername + "]]></FromUserName>");
    107.                         str.append("<CreateTime>" + returnTime + "</CreateTime>");
    108.                         str.append("<MsgType><![CDATA[" + msgType + "]]></MsgType>");
    109.                         str.append("<Content><![CDATA[你说的是:" + inputMsg.getContent() + ",吗?]]></Content>");
    110.                         str.append("</xml>");
    111.                         System.out.println(str.toString());
    112.                         response.getWriter().write(str.toString());
    113.                 }
    114.                 // 获取并返回多图片消息
    115.                 if (msgType.equals(MsgType.Image.toString())) {
    116.                         System.out.println("获取多媒体信息");
    117.                         System.out.println("多媒体文件id:" + inputMsg.getMediaId());
    118.                         System.out.println("图片链接:" + inputMsg.getPicUrl());
    119.                         System.out.println("消息id,64位整型:" + inputMsg.getMsgId());

    120.                         OutputMessage outputMsg = new OutputMessage();
    121.                         outputMsg.setFromUserName(servername);
    122.                         outputMsg.setToUserName(custermname);
    123.                         outputMsg.setCreateTime(returnTime);
    124.                         outputMsg.setMsgType(msgType);
    125.                         ImageMessage images = new ImageMessage();
    126.                         images.setMediaId(inputMsg.getMediaId());
    127.                         outputMsg.setImage(images);
    128.                         System.out.println("xml转换:/n" + xs.toXML(outputMsg));
    129.                         response.getWriter().write(xs.toXML(outputMsg));

    130.                 }
    131.         }

    132. }
    复制代码

    加密SHA1,此代码是来自网上

    1. /*
    2. * 微信公众平台(JAVA) SDK
    3. *
    4. * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
    5. * http://www.ansitech.com/weixin/sdk/
    6. *
    7. * Licensed under the Apache License, Version 2.0 (the "License");
    8. * you may not use this file except in compliance with the License.
    9. * You may obtain a copy of the License at
    10. *
    11. *      http://www.apache.org/licenses/LICENSE-2.0
    12. *
    13. * Unless required by applicable law or agreed to in writing, software
    14. * distributed under the License is distributed on an "AS IS" BASIS,
    15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16. * See the License for the specific language governing permissions and
    17. * limitations under the License.
    18. */
    19. package com.mor.util;

    20. import java.security.MessageDigest;

    21. /**
    22. * <p>
    23. * Title: SHA1算法
    24. * </p>
    25. *
    26. */
    27. public final class SHA1 {

    28.         private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    29.         /**
    30.          * Takes the raw bytes from the digest and formats them correct.
    31.          *
    32.          * @param bytes
    33.          *            the raw bytes from the digest.
    34.          * @return the formatted bytes.
    35.          */
    36.         private static String getFormattedText(byte[] bytes) {
    37.                 int len = bytes.length;
    38.                 StringBuilder buf = new StringBuilder(len * 2);
    39.                 // 把密文转换成十六进制的字符串形式
    40.                 for (int j = 0; j < len; j++) {
    41.                         buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
    42.                         buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
    43.                 }
    44.                 return buf.toString();
    45.         }

    46.         public static String encode(String str) {
    47.                 if (str == null) {
    48.                         return null;
    49.                 }
    50.                 try {
    51.                         MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    52.                         messageDigest.update(str.getBytes());
    53.                         return getFormattedText(messageDigest.digest());
    54.                 } catch (Exception e) {
    55.                         throw new RuntimeException(e);
    56.                 }
    57.         }
    58. }
    复制代码
    输入信息实体类 InputMessage
    1. <pre name="code" class="java">/*
    2. * 微信公众平台(JAVA) SDK
    3. *
    4. * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
    5. * http://www.ansitech.com/weixin/sdk/
    6. *
    7. * Licensed under the Apache License, Version 2.0 (the "License");
    8. * you may not use this file except in compliance with the License.
    9. * You may obtain a copy of the License at
    10. *
    11. *      http://www.apache.org/licenses/LICENSE-2.0
    12. *
    13. * Unless required by applicable law or agreed to in writing, software
    14. * distributed under the License is distributed on an "AS IS" BASIS,
    15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16. * See the License for the specific language governing permissions and
    17. * limitations under the License.
    18. */
    19. package com.mor.maven.demo.mavenweb.model;

    20. import java.io.Serializable;

    21. import com.thoughtworks.xstream.annotations.XStreamAlias;

    22. /**
    23. * POST的XML数据包转换为消息接受对象
    24. *
    25. * <p>
    26. * 由于POST的是XML数据包,所以不确定为哪种接受消息,<br/>
    27. * 所以直接将所有字段都进行转换,最后根据<tt>MsgType</tt>字段来判断取何种数据
    28. * </p>
    29. *
    30. */
    31. @XStreamAlias("xml")
    32. public class InputMessage implements Serializable {

    33.         /**
    34.          *
    35.          */
    36.         private static final long serialVersionUID = 1L;
    37.         @XStreamAlias("ToUserName")
    38.         private String ToUserName;
    39.         @XStreamAlias("FromUserName")
    40.         private String FromUserName;
    41.         @XStreamAlias("CreateTime")
    42.         private Long CreateTime;
    43.         @XStreamAlias("MsgType")
    44.         private String MsgType = "text";
    45.         @XStreamAlias("MsgId")
    46.         private Long MsgId;
    47.         // 文本消息
    48.         @XStreamAlias("Content")
    49.         private String Content;
    50.         // 图片消息
    51.         @XStreamAlias("PicUrl")
    52.         private String PicUrl;
    53.         // 位置消息
    54.         @XStreamAlias("LocationX")
    55.         private String LocationX;
    56.         @XStreamAlias("LocationY")
    57.         private String LocationY;
    58.         @XStreamAlias("Scale")
    59.         private Long Scale;
    60.         @XStreamAlias("Label")
    61.         private String Label;
    62.         // 链接消息
    63.         @XStreamAlias("Title")
    64.         private String Title;
    65.         @XStreamAlias("Description")
    66.         private String Description;
    67.         @XStreamAlias("Url")
    68.         private String URL;
    69.         // 语音信息
    70.         @XStreamAlias("MediaId")
    71.         private String MediaId;
    72.         @XStreamAlias("Format")
    73.         private String Format;
    74.         @XStreamAlias("Recognition")
    75.         private String Recognition;
    76.         // 事件
    77.         @XStreamAlias("Event")
    78.         private String Event;
    79.         @XStreamAlias("EventKey")
    80.         private String EventKey;
    81.         @XStreamAlias("Ticket")
    82.         private String Ticket;

    83.         public String getToUserName() {
    84.                 return ToUserName;
    85.         }

    86.         public void setToUserName(String toUserName) {
    87.                 ToUserName = toUserName;
    88.         }

    89.         public String getFromUserName() {
    90.                 return FromUserName;
    91.         }

    92.         public void setFromUserName(String fromUserName) {
    93.                 FromUserName = fromUserName;
    94.         }

    95.         public Long getCreateTime() {
    96.                 return CreateTime;
    97.         }

    98.         public void setCreateTime(Long createTime) {
    99.                 CreateTime = createTime;
    100.         }

    101.         public String getMsgType() {
    102.                 return MsgType;
    103.         }

    104.         public void setMsgType(String msgType) {
    105.                 MsgType = msgType;
    106.         }

    107.         public Long getMsgId() {
    108.                 return MsgId;
    109.         }

    110.         public void setMsgId(Long msgId) {
    111.                 MsgId = msgId;
    112.         }

    113.         public String getContent() {
    114.                 return Content;
    115.         }

    116.         public void setContent(String content) {
    117.                 Content = content;
    118.         }

    119.         public String getPicUrl() {
    120.                 return PicUrl;
    121.         }

    122.         public void setPicUrl(String picUrl) {
    123.                 PicUrl = picUrl;
    124.         }

    125.         public String getLocationX() {
    126.                 return LocationX;
    127.         }

    128.         public void setLocationX(String locationX) {
    129.                 LocationX = locationX;
    130.         }

    131.         public String getLocationY() {
    132.                 return LocationY;
    133.         }

    134.         public void setLocationY(String locationY) {
    135.                 LocationY = locationY;
    136.         }

    137.         public Long getScale() {
    138.                 return Scale;
    139.         }

    140.         public void setScale(Long scale) {
    141.                 Scale = scale;
    142.         }

    143.         public String getLabel() {
    144.                 return Label;
    145.         }

    146.         public void setLabel(String label) {
    147.                 Label = label;
    148.         }

    149.         public String getTitle() {
    150.                 return Title;
    151.         }

    152.         public void setTitle(String title) {
    153.                 Title = title;
    154.         }

    155.         public String getDescription() {
    156.                 return Description;
    157.         }

    158.         public void setDescription(String description) {
    159.                 Description = description;
    160.         }

    161.         public String getURL() {
    162.                 return URL;
    163.         }

    164.         public void setURL(String uRL) {
    165.                 URL = uRL;
    166.         }

    167.         public String getEvent() {
    168.                 return Event;
    169.         }

    170.         public void setEvent(String event) {
    171.                 Event = event;
    172.         }

    173.         public String getEventKey() {
    174.                 return EventKey;
    175.         }

    176.         public void setEventKey(String eventKey) {
    177.                 EventKey = eventKey;
    178.         }

    179.         public String getMediaId() {
    180.                 return MediaId;
    181.         }

    182.         public void setMediaId(String mediaId) {
    183.                 MediaId = mediaId;
    184.         }

    185.         public String getFormat() {
    186.                 return Format;
    187.         }

    188.         public void setFormat(String format) {
    189.                 Format = format;
    190.         }

    191.         public String getRecognition() {
    192.                 return Recognition;
    193.         }

    194.         public void setRecognition(String recognition) {
    195.                 Recognition = recognition;
    196.         }

    197.         public String getTicket() {
    198.                 return Ticket;
    199.         }

    200.         public void setTicket(String ticket) {
    201.                 Ticket = ticket;
    202.         }
    203. }
    复制代码
    为了加入 CDATA 验证创建的@interface类
    1. package com.mor.maven.demo.mavenweb.model;

    2. import java.lang.annotation.ElementType;
    3. import java.lang.annotation.Retention;
    4. import java.lang.annotation.RetentionPolicy;
    5. import java.lang.annotation.Target;

    6. @Retention(RetentionPolicy.RUNTIME)
    7. @Target({ ElementType.FIELD })
    8. public @interface XStreamCDATA {

    9. }
    复制代码
    改写的XStream工具类
    1. package com.mor.util;

    2. import java.io.Writer;
    3. import java.lang.reflect.Field;

    4. import com.mor.maven.demo.mavenweb.model.XStreamCDATA;
    5. import com.thoughtworks.xstream.XStream;
    6. import com.thoughtworks.xstream.annotations.XStreamAlias;
    7. import com.thoughtworks.xstream.core.util.QuickWriter;
    8. import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
    9. import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
    10. import com.thoughtworks.xstream.io.xml.XppDriver;

    11. /**
    12. * xml 转换工具类
    13. *
    14. * @author morning
    15. * @date 2015年2月16日 下午2:42:50
    16. */
    17. public class SerializeXmlUtil {

    18.         public static XStream createXstream() {
    19.                 return new XStream(new XppDriver() {
    20.                         @Override
    21.                         public HierarchicalStreamWriter createWriter(Writer out) {
    22.                                 return new PrettyPrintWriter(out) {
    23.                                         boolean cdata = false;
    24.                                         Class<?> targetClass = null;

    25.                                         @Override
    26.                                         public void startNode(String name, @SuppressWarnings("rawtypes") Class clazz) {
    27.                                                 super.startNode(name, clazz);
    28.                                                 // 业务处理,对于用XStreamCDATA标记的Field,需要加上CDATA标签
    29.                                                 if (!name.equals("xml")) {
    30.                                                         cdata = needCDATA(targetClass, name);
    31.                                                 } else {
    32.                                                         targetClass = clazz;
    33.                                                 }
    34.                                         }

    35.                                         @Override
    36.                                         protected void writeText(QuickWriter writer, String text) {
    37.                                                 if (cdata) {
    38.                                                         writer.write("<![CDATA[");
    39.                                                         writer.write(text);
    40.                                                         writer.write("]]>");
    41.                                                 } else {
    42.                                                         writer.write(text);
    43.                                                 }
    44.                                         }
    45.                                 };
    46.                         }
    47.                 });
    48.         }

    49.         private static boolean needCDATA(Class<?> targetClass, String fieldAlias) {
    50.                 boolean cdata = false;
    51.                 // first, scan self
    52.                 cdata = existsCDATA(targetClass, fieldAlias);
    53.                 if (cdata)
    54.                         return cdata;
    55.                 // if cdata is false, scan supperClass until java.lang.Object
    56.                 Class<?> superClass = targetClass.getSuperclass();
    57.                 while (!superClass.equals(Object.class)) {
    58.                         cdata = existsCDATA(superClass, fieldAlias);
    59.                         if (cdata)
    60.                                 return cdata;
    61.                         superClass = superClass.getClass().getSuperclass();
    62.                 }
    63.                 return false;
    64.         }

    65.         private static boolean existsCDATA(Class<?> clazz, String fieldAlias) {
    66.                 if ("MediaId".equals(fieldAlias)) {
    67.                         return true; // 特例添加 morning99
    68.                 }
    69.                 // scan fields
    70.                 Field[] fields = clazz.getDeclaredFields();
    71.                 for (Field field : fields) {
    72.                         // 1. exists XStreamCDATA
    73.                         if (field.getAnnotation(XStreamCDATA.class) != null) {
    74.                                 XStreamAlias xStreamAlias = field.getAnnotation(XStreamAlias.class);
    75.                                 // 2. exists XStreamAlias
    76.                                 if (null != xStreamAlias) {
    77.                                         if (fieldAlias.equals(xStreamAlias.value()))// matched
    78.                                                 return true;
    79.                                 } else {// not exists XStreamAlias
    80.                                         if (fieldAlias.equals(field.getName()))
    81.                                                 return true;
    82.                                 }
    83.                         }
    84.                 }
    85.                 return false;
    86.         }

    87. }
    复制代码
    输出实体类 OutputMessage
    1. package com.mor.maven.demo.mavenweb.model;

    2. import com.thoughtworks.xstream.annotations.XStreamAlias;

    3. /**
    4. *
    5. * @author morning
    6. * @date 2015年2月16日 下午2:29:32
    7. */
    8. @XStreamAlias("xml")
    9. public class OutputMessage {

    10.         @XStreamAlias("ToUserName")
    11.         @XStreamCDATA
    12.         private String ToUserName;

    13.         @XStreamAlias("FromUserName")
    14.         @XStreamCDATA
    15.         private String FromUserName;

    16.         @XStreamAlias("CreateTime")
    17.         private Long CreateTime;

    18.         @XStreamAlias("MsgType")
    19.         @XStreamCDATA
    20.         private String MsgType = "text";

    21.         private ImageMessage Image;

    22.         public String getToUserName() {
    23.                 return ToUserName;
    24.         }

    25.         public void setToUserName(String toUserName) {
    26.                 ToUserName = toUserName;
    27.         }

    28.         public String getFromUserName() {
    29.                 return FromUserName;
    30.         }

    31.         public void setFromUserName(String fromUserName) {
    32.                 FromUserName = fromUserName;
    33.         }

    34.         public Long getCreateTime() {
    35.                 return CreateTime;
    36.         }

    37.         public void setCreateTime(Long createTime) {
    38.                 CreateTime = createTime;
    39.         }

    40.         public String getMsgType() {
    41.                 return MsgType;
    42.         }

    43.         public void setMsgType(String msgType) {
    44.                 MsgType = msgType;
    45.         }

    46.         public ImageMessage getImage() {
    47.                 return Image;
    48.         }

    49.         public void setImage(ImageMessage image) {
    50.                 Image = image;
    51.         }

    52. }
    复制代码
    图片信息实体类
    1. package com.mor.maven.demo.mavenweb.model;

    2. import com.thoughtworks.xstream.annotations.XStreamAlias;

    3. @XStreamAlias("Image")
    4. public class ImageMessage extends MediaIdMessage {
    5. }
    复制代码
    多媒体id 实体类
    1. package com.mor.maven.demo.mavenweb.model;

    2. import com.thoughtworks.xstream.annotations.XStreamAlias;

    3. public class MediaIdMessage {
    4.         @XStreamAlias("MediaId")
    5.         @XStreamCDATA
    6.         private String MediaId;

    7.         public String getMediaId() {
    8.                 return MediaId;
    9.         }

    10.         public void setMediaId(String mediaId) {
    11.                 MediaId = mediaId;
    12.         }

    13. }
    复制代码

    基本就这些类,也不知道拷贝全没有。

    不过在输出xml的时候由于要添加CDATA标签所以没有实现完美,目前自己在SerializeXmlUtil 内添加了一下判断


    如果是子标签下的值目前只能用这种方法加CDATA,不知道各位同学有没有好的方法。

    目前只是实现了服务器认证,接收文本信息并回复原文本信息加上些附加信息,接收图片信息并返回原图片信息。

    后期会有扩展,先记录到此。



    依赖的类库(jar包)




    源码:



    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    守望者AIR技术交流社区(www.airmyth.com)
    回复

    使用道具 举报

  • TA的每日心情
    郁闷
    2016-8-19 16:08
  • 签到天数: 7 天

    [LV.3]偶尔看看II

    4

    主题

    31

    帖子

    2628

    积分

    少尉

    Rank: 6Rank: 6

    威望
    0
    贡献
    8
    金币
    320
    钢镚
    25
    发表于 2016-8-18 17:24:40 | 显示全部楼层
    看看。。。。。
    我是一个兵
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    
    关闭

    站长推荐上一条 /4 下一条

    QQ|手机版|Archiver|网站地图|小黑屋|守望者 ( 京ICP备14061876号

    GMT+8, 2024-3-28 21:09 , Processed in 0.054185 second(s), 37 queries .

    守望者AIR

    守望者AIR技术交流社区

    本站成立于 2014年12月31日

    快速回复 返回顶部 返回列表