陈士柏 2 år sedan
förälder
incheckning
a6a00ba2ea
1 ändrade filer med 78 tillägg och 0 borttagningar
  1. 78 0
      mhotel/src/com/happy/common/http/Message2.java

+ 78 - 0
mhotel/src/com/happy/common/http/Message2.java

@@ -0,0 +1,78 @@
+package com.happy.common.http;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.happy.Model.Message.Mp_template_msg;
+import com.happy.Model.weixin.AccessToken;
+import com.happy.Model.weixin.WeiXinUtil;
+
+import java.util.HashMap;
+
+/**
+ * 公众号,推送信息,推给商家信息
+ */
+public class Message2 {
+
+    /** 公众号推送消息
+     * openid:用户小程序openid, order_num订单号,
+     *  h_type房型, live_end入住和离店日期:2023-08-02~2023-08-06
+     *  user_name:用户名, hotel_name:酒店名
+     * **/
+    public static String send(String openid,String order_num,
+                              String h_type,String live_end,
+                              String user_name,String hotel_name,String id)
+            throws Exception {
+        Gson gson = new Gson();
+        String access_token = "";
+        JSONObject json = new JSONObject();
+        json.put("grant_type", "client_credential");
+        json.put("appid",WeiXinUtil.appid_g);
+        json.put("secret",WeiXinUtil.screct_g);
+        String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
+        access_token = HttpsClient.sendJson(url,json);
+        access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
+        JSONObject message = new JSONObject();
+        message.put("touser", openid);
+        message.put("template_id", "pQLY-9pKW-lD-6PuOlxieatGmuCHOezubTxI99cs7Zo");
+        JSONObject small = new JSONObject();
+        small.put("appid", WeiXinUtil.appid_c);
+        small.put("pagepath", "/pages/push/push?id=" + id);
+        message.put("miniprogram", small);
+        // 订单号
+        JSONObject character_string1_ = new JSONObject();
+        character_string1_.put("value", order_num);
+        character_string1_.put("color", "#173177");
+        // 房型名称
+        JSONObject thing6 = new JSONObject();
+        thing6.put("value", h_type);
+        thing6.put("color", "#0000FF");
+        // 入离时间
+        JSONObject time11 = new JSONObject();
+        time11.put("value", live_end);
+        time11.put("color", "#173177");
+        // 客户名称
+        JSONObject thing10 = new JSONObject();
+        thing10.put("value", user_name);
+        thing10.put("color", "#173177");
+        // 酒店名称
+        JSONObject thing9_ = new JSONObject();
+        thing9_.put("value", hotel_name);
+        thing9_.put("color", "#173177");
+        // 封装data
+        JSONObject data = new JSONObject();
+        // 订单号
+        data.put("character_string1",character_string1_);
+        // 房型名称
+        data.put("thing6",thing6);
+        // 入离时间
+        data.put("time11",time11);
+        // 客户名称
+        data.put("thing10",thing10);
+        // 酒店名称
+        data.put("thing9",thing9_);
+        message.put("data",data);
+        return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token, message);
+    }
+
+}