当前位置: 首页>>代码示例>>Java>>正文


Java WxItemImageEntity.setMediaId方法代码示例

本文整理汇总了Java中org.hamster.weixinmp.dao.entity.item.WxItemImageEntity.setMediaId方法的典型用法代码示例。如果您正苦于以下问题:Java WxItemImageEntity.setMediaId方法的具体用法?Java WxItemImageEntity.setMediaId怎么用?Java WxItemImageEntity.setMediaId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hamster.weixinmp.dao.entity.item.WxItemImageEntity的用法示例。


在下文中一共展示了WxItemImageEntity.setMediaId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: remoteMediaUpload

import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; //导入方法依赖的package包/类
public WxBaseItemMediaEntity remoteMediaUpload(String accessToken,
		WxMediaTypeEnum type, byte[] content) throws WxException {
	MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
	String typeString = null;
	switch (type) {
	case IMAGE:
	case THUMB:
	case VIDEO:
	case VOICE:
		typeString = type.toString().toLowerCase();
		break;
	case MUSIC:
	case DEFAULT:
	case PIC_DESC:
		throw new WxException("Not supported upload type : "
				+ type.toString());
	default:
		break;
	}

	Map<String, String> params = WxUtil.getAccessTokenParams(accessToken);
	System.out.println(typeString);
	params.put("type", typeString);
	ContentBody contentBody = new ByteArrayBody(content, ContentType.MULTIPART_FORM_DATA, "name.jpg");
	entityBuilder.addPart("media", contentBody);
	MediaResultMapper result = WxUtil.sendRequest(
			config.getMediaUploadUrl(), HttpMethod.POST, params,
			entityBuilder.build(), MediaResultMapper.class);

	WxBaseItemMediaEntity resultEntity = null;
	switch (type) {
	case IMAGE:
		WxItemImageEntity imageEntity = new WxItemImageEntity();
		imageEntity.setMediaId(result.getMedia_id());
		imageEntity.setCreatedDate(new Date(result.getCreated_at() * 1000));
		resultEntity = imageEntity;
		break;
	case THUMB:
		WxItemThumbEntity thumbEntity = new WxItemThumbEntity();
		thumbEntity.setMediaId(result.getMedia_id());
		thumbEntity.setCreatedDate(new Date(result.getCreated_at() * 1000));
		resultEntity = thumbEntity;
		break;
	case VIDEO:
		WxItemVideoEntity videoEntity = new WxItemVideoEntity();
		videoEntity.setMediaId(result.getMedia_id());
		videoEntity.setCreatedDate(new Date(result.getCreated_at() * 1000));
		resultEntity = videoEntity;
		break;
	case VOICE:
		WxItemVoiceEntity voiceEntity = new WxItemVoiceEntity();
		voiceEntity.setMediaId(result.getMedia_id());
		voiceEntity.setCreatedDate(new Date(result.getCreated_at() * 1000));
		resultEntity = voiceEntity;
		break;
	case MUSIC:
	case DEFAULT:
	case PIC_DESC:
		throw new WxException("Not supported upload type : "
				+ type.toString());
	default:
		break;
	}
	return resultEntity;
}
 
开发者ID:Charlemin,项目名称:weixin-mp-java-master,代码行数:66,代码来源:WxMediaService.java

示例2: getMsgImage

import org.hamster.weixinmp.dao.entity.item.WxItemImageEntity; //导入方法依赖的package包/类
/**
 * <code>
 * &lt;xml&gt;
	 * &nbsp;&nbsp;&lt;ToUserName&gt;&lt;![CDATA[toUser]]&gt;&lt;/ToUserName&gt;
    * &nbsp;&nbsp;&lt;FromUserName&gt;&lt;![CDATA[fromUser]]&gt;&lt;/FromUserName&gt;
	 * &nbsp;&nbsp;&lt;CreateTime&gt;1348831860&lt;/CreateTime&gt;
    * &nbsp;&nbsp;&lt;MsgType&gt;&lt;![CDATA[image]]&gt;&lt;/MsgType&gt;
    * &nbsp;&nbsp;&lt;PicUrl&gt;&lt;![CDATA[this is a url]]&gt;&lt;/PicUrl&gt;
    * &nbsp;&nbsp;&lt;MediaId&gt;&lt;![CDATA[media_id]]&gt;&lt;/MediaId&gt;
    * &nbsp;&nbsp;&lt;MsgId&gt;1234567890123456&lt;/MsgId&gt;
    * &lt;/xml&gt;
 * </code>
 * 
 * @param xmlstr
 * @return
 * @throws DocumentException
 */
public static WxMsgImageEntity getMsgImage(Element ele) throws DocumentException {
	WxMsgImageEntity result = msgEntityFactory(WxMsgImageEntity.class, ele);
	WxItemImageEntity image = new WxItemImageEntity();
	image.setMediaId(strVal(ele, "MediaId"));
	image.setPicUrl(strVal(ele, "PicUrl"));
	result.setImage(image);
	return result;
}
 
开发者ID:Charlemin,项目名称:weixin-mp-java-master,代码行数:26,代码来源:WxXmlUtil.java


注:本文中的org.hamster.weixinmp.dao.entity.item.WxItemImageEntity.setMediaId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。