Message2.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.happy.common.http;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.google.gson.Gson;
  4. import com.google.gson.reflect.TypeToken;
  5. import com.happy.Model.Message.Mp_template_msg;
  6. import com.happy.Model.weixin.AccessToken;
  7. import com.happy.Model.weixin.WeiXinUtil;
  8. import java.util.HashMap;
  9. /**
  10. * 公众号,推送信息,推给商家信息
  11. */
  12. public class Message2 {
  13. /** 公众号推送消息
  14. * openid:用户小程序openid, order_num订单号,
  15. * h_type房型, live_end入住和离店日期:2023-08-02~2023-08-06
  16. * user_name:用户名, hotel_name:酒店名
  17. * **/
  18. public static String send(String openid,String order_num,
  19. String h_type,String live_end,
  20. String user_name,String hotel_name,String id)
  21. throws Exception {
  22. Gson gson = new Gson();
  23. String access_token = "";
  24. JSONObject json = new JSONObject();
  25. json.put("grant_type", "client_credential");
  26. json.put("appid",WeiXinUtil.appid_g);
  27. json.put("secret",WeiXinUtil.screct_g);
  28. String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
  29. access_token = HttpsClient.sendJson(url,json);
  30. access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
  31. JSONObject message = new JSONObject();
  32. message.put("touser", openid);
  33. message.put("template_id", "pQLY-9pKW-lD-6PuOlxieatGmuCHOezubTxI99cs7Zo");
  34. JSONObject small = new JSONObject();
  35. small.put("appid", WeiXinUtil.appid_c);
  36. small.put("pagepath", "/pages/push/push?id=" + id);
  37. message.put("miniprogram", small);
  38. // 订单号
  39. JSONObject character_string1_ = new JSONObject();
  40. character_string1_.put("value", order_num);
  41. character_string1_.put("color", "#173177");
  42. // 房型名称
  43. JSONObject thing6 = new JSONObject();
  44. thing6.put("value", h_type);
  45. thing6.put("color", "#0000FF");
  46. // 入离时间
  47. JSONObject time11 = new JSONObject();
  48. time11.put("value", live_end);
  49. time11.put("color", "#173177");
  50. // 客户名称
  51. JSONObject thing10 = new JSONObject();
  52. thing10.put("value", user_name);
  53. thing10.put("color", "#173177");
  54. // 酒店名称
  55. JSONObject thing9_ = new JSONObject();
  56. thing9_.put("value", hotel_name);
  57. thing9_.put("color", "#173177");
  58. // 封装data
  59. JSONObject data = new JSONObject();
  60. // 订单号
  61. data.put("character_string1",character_string1_);
  62. // 房型名称
  63. data.put("thing6",thing6);
  64. // 入离时间
  65. data.put("time11",time11);
  66. // 客户名称
  67. data.put("thing10",thing10);
  68. // 酒店名称
  69. data.put("thing9",thing9_);
  70. message.put("data",data);
  71. return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token, message);
  72. }
  73. }