SendWechatPush.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.zoniot.ccrc.commom.utils;
  2. import java.io.IOException;
  3. /**
  4. * 微信公众号消息推送
  5. */
  6. public class SendWechatPush {
  7. /**
  8. * 统一消息发送异常通知(微信公众号和小程序)
  9. */
  10. public static String sendAbnormalNotice(String accessToken,String oa_appid, String openId, String url,String weapp_appid, String pagepath, String first, String keyword1, String keyword2, String keyword3, String remark) {
  11. if (accessToken != null && !"".equals(accessToken)) {
  12. String sendUrl = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" + accessToken;
  13. String json = "{\n" +
  14. " \"touser\": \""+openId+"\",\n" +
  15. " \"mp_template_msg\": {\n" +
  16. " \"appid\": \""+oa_appid +"\",\n" +
  17. " \"template_id\": \"r8mtd2mgMt8w-sNgHsJ4deoD2bfq-0RyK9lCY3WEoxI\",\n" +
  18. " \"url\": \""+url+"\",\n" +
  19. " \"miniprogram\": {\n" +
  20. " \"appid\": \""+weapp_appid+"\",\n" +
  21. " \"path\": \""+pagepath+"\"\n" +
  22. " },\n" +
  23. " \"data\": {\n" +
  24. " \"first\": {\n" +
  25. " \"value\": \""+first+"\",\n" +
  26. " \"color\": \"#173177\"\n" +
  27. " },\n" +
  28. " \"keyword1\": {\n" +
  29. " \"value\": \""+keyword1+"\",\n" +
  30. " \"color\": \"#173177\"\n" +
  31. " },\n" +
  32. " \"keyword2\": {\n" +
  33. " \"value\": \""+keyword2+"\",\n" +
  34. " \"color\": \"#173177\"\n" +
  35. " },\n" +
  36. " \"keyword3\": {\n" +
  37. " \"value\": \""+keyword3+"\",\n" +
  38. " \"color\": \"#173177\"\n" +
  39. " },\n" +
  40. " \"remark\": {\n" +
  41. " \"value\": \""+remark+"\",\n" +
  42. " \"color\": \"#173177\"\n" +
  43. " }\n" +
  44. " }\n" +
  45. " }\n" +
  46. "}";
  47. try {
  48. return HttpRequest.doPost(sendUrl, json);
  49. } catch (IOException e) {
  50. return null;
  51. }
  52. } else {
  53. return "accessToken不存在";
  54. }
  55. }
  56. }