例子一:
- /**
- *
- * sendPreview:(通过该接口发送消息给指定用户,在手机端查看消息的样式和排版。).
- *
- * @author HanKeQi
- * @param @param openId 用户唯一标示 不能为空
- * @param @param mediaId 类型
- * @param @param messagetype 5中类型必选其中之一
- * @param @return 设定文件
- * @throws JSONObject DOM对象
- * @since JDK 1.7
- */
- public static JSONObject sendPreview(String openId,String mediaId,String messagetype){
- String content="\"media_id\":\""+mediaId+"\"";
- String send_url="https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token="+getAccessToken();
- if ("text".equals(messagetype)) {
- content="\"content\":\""+mediaId+"\"";
- }
- String jsonStr="{\"touser\":\""+openId+"\",\""+messagetype+"\":{"+content+"}, \"msgtype\":\""+messagetype+"\"}";
- JSONObject jsonObject=httpRequest(send_url, "POST", jsonStr);
- if (0==jsonObject.getInt("errcode")) {
- return jsonObject;
- }
- return null;
- }
例子二:
/**
*
* @param req 卡券消息请求对象
* @param authAppid
* @param openId
* @param mediaId
* @param messagetype
* @return
*/
public GetSendMessageJsonRes getMassMessagePreview(WxcardMsgJsonReq req,String authAppid, String openId,
String mediaId, String messagetype) {
logger.debug("预览接口.....");
GetSendMessageJsonRes response = null;
StringBuilder sb = new StringBuilder(baseApiUrl);
sb.append("cgi-bin/message/mass/mass/preview?access_token=").append(
weixinBaseService.getWeixinAuthToken(authAppid));
Map<String,Object> map = new HashMap<String, Object>();
map.put("touser", openId);
if ("text".equals(messagetype)) {
map.put("content", mediaId);
} else if ("wxcard".equals(messagetype)) {
//卡券 WxcardMsgJsonReq
map.put("wxcard", req);
}else{
map.put("media_id", mediaId);
}
map.put("msgtype", messagetype);
BaseJsonRes baseJsonRes = weixinBaseService.post(sb.toString(),weixinConvertor.toJson(map));
String resultJson = weixinBaseService.isSuccess(baseJsonRes
.getErrcode()) ? baseJsonRes.getErrmsg() : weixinConvertor
.toJson(baseJsonRes);
response = weixinConvertor.toBean(resultJson,
GetSendMessageJsonRes.class);
return response;
}