您的位置:首页 > 移动开发 > 微信开发

微信小程序发送模板消息

2017-12-28 00:00 507 查看
摘要: 微信小程序发送模板消息后台

/**
* 模板详情
* @param openId openId
* @param templateId 模板ID
* @param tokenId tokenId
* TODO throw new exception
*/
public void templateItem(String openId,String templateId,String tokenId, String formId){
TemplateData templateData = TemplateData.New();
templateData.setTouser(openId);
templateData.setTemplate_id(templateId);
templateData.add("keyword1","新年礼券","#173177");//TODO 卡券名称
templateData.add("keyword2","2017年12月29日-2018年1月3日","#173177");//TODO 领取时间
templateData.add("keyword3","2017年12月29日-2018年1月3日","#173177");//TODO 有效日期
templateData.add("keyword4","购物满299元可抵30元(正价商品)","#173177");//TODO 使用限制
JSONObject json = new JSONObject(templateData);
try {
json.put("form_id",formId);
json.put("page","/pages/code/code");
} catch (JSONException e) {
e.printStackTrace();
}
//TODO "emphasis_keyword": "keyword1.DATA" 放大关键字
String jsonResult = HttpUtils.post(
"https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" + tokenId,
json.toString());
com.alibaba.fastjson.JSONObject parseObject = JSON.parseObject(jsonResult);

System.out.println("wechatOut========"+parseObject.toJSONString());
String errmsg = parseObject.getString("errmsg");
if (!errmsg.equals("ok")) {
throw new BaseAppException(errmsg);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  微信小程序