微信 公众号 和 小程序 模板消息 demo
2017-08-03 00:00
543 查看
需要导入 weixin4j 框架(jar包)
公众号:
小程序:
公众号:
public String transHints(String openId,String url,String first,String merchant,String transType,String orderId,String time,String acmount,String remark) throws WeixinException{ WeixinProxy weixinProxy = new WeixinProxy(new WeixinAccount(qijukejiEnvironment.getWechatAppID(),qijukejiEnvironment.getWxAppletAppSecret()), new FileCacheStorager<Token>());//你的AppID和AppSecret TemplateMessage templateMessage = new TemplateMessage(openId, qijukejiEnvironment.getWechatTemplatesTransHints(), url);//你的模板id,和点击进入界面的url Map<String, NameValue> mes = new HashMap<String, NameValue>(); mes.put("first", new NameValue("first", first)); mes.put("keyword1", new NameValue("keyword1", merchant)); mes.put("keyword2", new NameValue("keyword2", transType)); mes.put("keyword3", new NameValue("keyword3", orderId)); mes.put("keyword4", new NameValue("keyword4", time)); mes.put("keyword5", new NameValue("keyword5", acmount)); mes.put("remark", new NameValue("remark", remark)); templateMessage.setItems(mes); return weixinProxy.sendTmplMessage(templateMessage); }
小程序:
public void transHints(String openId,String url,String formId,String activity,String merchantName,String merchantInfo,String time,String orderId,String remark,String discount) throws WeixinException{ String urlApplet = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" + weixinAppletProxy.getTokenManager().getAccessToken();//你的access_token //根据你的模板 JSONObject jsonObjectData = new JSONObject(); JSONObject jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",activity); jsonObjectData.put("keyword1", jsonObjectValue); jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",merchantName); jsonObjectData.put("keyword2", jsonObjectValue); jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",merchantInfo); jsonObjectData.put("keyword3", jsonObjectValue); jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",time); jsonObjectData.put("keyword4", jsonObjectValue); jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",orderId); jsonObjectData.put("keyword5", jsonObjectValue); jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",remark); jsonObjectData.put("keyword6", jsonObjectValue); jsonObjectValue = new JSONObject(); jsonObjectValue.put("value",discount); jsonObjectData.put("keyword7", jsonObjectValue); JSONObject jsonObject = new JSONObject(); jsonObject.put("touser",openId); jsonObject.put("template_id",qijukejiEnvironment.getWxAppletTemplatesTransHints());//你的模板id jsonObject.put("page",url); jsonObject.put("form_id",formId); jsonObject.put("data",jsonObjectData); WeixinRequestExecutor weixinExecutor = new WeixinRequestExecutor(); WeixinResponse response = weixinExecutor.post(urlApplet,jsonObject.toJSONString()); }
相关文章推荐
- 微信小程序,公众号发送模板消息(java)
- 微信小程序——发送模板消息
- 微信小程序模板消息总结
- 微信小程序之发送模板消息(通过openid推送消息给用户)
- 微信小程序实例:创建下发模板消息实例
- 微信小程序-模板消息全面解析加实例
- 突破微信小程序模板消息的推送限制
- 微信开发群发图文消息效果,公众号群发消息案例demo
- 微信公众账号推送模板消息(java版)
- 【微信小程序】发送消息模板教程
- 微信小程序实例:创建下发模板消息实例
- 微信小程序之定时发送模板消息
- 微信小程序-详解微信登陆、微信支付、模板消息 超级详细
- 微信小程序发送模板消息
- 微信小程序开发模板消息的时候 出现 errcode: 41028, errmsg: "invalid form id hint:
- 微信小程序模板消息群发、无限制推送相关讲解
- 突破微信小程序模板消息限制,实现无限制主动推送
- 小程序模板消息发送(微信推送)
- 微信小程序七(模板条件列表渲染完成模拟公众号自动回复)
- 微信小程序开发之formId使用(模板消息)