Loading

微信回复图片

微信回复图片

注意是mediaId,不是messageId;

这个注意了,其他与文本消息一致;

package com.tuling.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class ScanImage {
    @XmlElements({ 
        @XmlElement(name = "Image", type = Image.class) 
    })
    private Integer id;

    @XmlElement(name="ToUserName")
    private String toUserName;

    @XmlElement(name="FromUserName") 
    private String fromUserName;

    @XmlElement(name="CreateTime") 
    private Integer createTime;

    @XmlElement(name="MsgType") 
    private String msgType;

    @XmlElement(name="Event") 
    private String event;

    @XmlElement(name="EventKey") 
    private String eventKey;

    @XmlElement(name="Content")
    private String content;

    @XmlElement(name="MsgId")
    private String msgId;

    @XmlElement(name="Latitude")
    private String latitude;

    @XmlElement(name="Longitude")
    private String longitude;

    @XmlElement(name="Precision")
    private String myPrecision;
    
    @XmlElement(name="Image", type=Image.class)
    private Image mediaId;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public Integer getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Integer createTime) {
        this.createTime = createTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getEventKey() {
        return eventKey;
    }

    public void setEventKey(String eventKey) {
        this.eventKey = eventKey;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String latitude) {
        this.latitude = latitude;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String longitude) {
        this.longitude = longitude;
    }

    public String getMyPrecision() {
        return myPrecision;
    }

    public void setMyPrecision(String myPrecision) {
        this.myPrecision = myPrecision;
    }

    public Image getMediaId() {
        return mediaId;
    }

    public void setMediaId(Image mediaId) {
        this.mediaId = mediaId;
    }
}
package com.tuling.model;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Image {
    
    @XmlElement(name="MediaId")
    private String mediaId;

    public String getMediaId() {
        return mediaId;
    }

    public void setMediaId(String mediaId) {
        this.mediaId = mediaId;
    }
    
    

}

controller中

    // 回复图片消息
    private Object imageMessage(Scan scan) {
        ScanImage reply = new ScanImage();
        reply.setToUserName(scan.getFromUserName());
        reply.setFromUserName(scan.getToUserName());
        reply.setCreateTime((int) (Calendar.getInstance().getTimeInMillis() / 1000) );
        reply.setMsgType("image");
        Image image =  new Image();
        image.setMediaId(scan.getMediaId());
        reply.setMediaId(image);
        System.out.println("$$$$$$$$$$$$$$$$$IMAGE_MESSAGE$$$$$$$$$$$$$$$$$$$$$$$");
        return reply;
    }

 

posted @ 2017-04-06 16:26  stono  阅读(509)  评论(0编辑  收藏  举报