陈士柏 2 سال پیش
والد
کامیت
4c47afe045
1فایلهای تغییر یافته به همراه57 افزوده شده و 0 حذف شده
  1. 57 0
      mhotel/src/com/happy/common/http/Message.java

+ 57 - 0
mhotel/src/com/happy/common/http/Message.java

@@ -0,0 +1,57 @@
+package com.happy.common.http;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+// 小程序消息通知
+public class Message {
+
+    public static String send(String openid,String order_num,
+                              String user_name,String warm,String time)
+            throws Exception {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("grant_type", "client_credential");
+        jsonObject.put("appid", "wx2fc3f45732fae5d3");
+        jsonObject.put("secret","7eee4a49a4470a77f9222995e8511547");
+        String msg3 = HttpsClient.sendJson2("https://api.weixin.qq.com/cgi-bin/stable_token",jsonObject);
+        Gson gson = new Gson();
+        HashMap<String, String> userMap = gson.fromJson(msg3.toString(), new TypeToken<HashMap<String, String>>() {}.getType());
+        JSONObject message = new JSONObject();
+        String token = userMap.get("access_token");
+        message.put("touser", openid);
+        message.put("template_id", "ERU1ZY9IqwNkDxWyFJvo5VSE7ua-wey3SqhZgjqLDtU");
+        message.put("page", "index");
+        message.put("miniprogram_state", "formal");
+        message.put("lang", "zh_CN");
+        JSONObject data = new JSONObject();
+        // 订单号
+        JSONObject character_string1 = new JSONObject();
+        character_string1.put("value", order_num);
+        // 客户名称
+        JSONObject thing2 = new JSONObject();
+        thing2.put("value", user_name);
+        // 温馨提示
+        JSONObject thing9 = new JSONObject();
+        thing9.put("value", warm);
+        // 下单时间
+        JSONObject time31 = new JSONObject();
+        time31.put("value", time);
+        // 订单号
+        data.put("character_string1",character_string1);
+        // 客户名称
+        data.put("thing2",thing2);
+        // 温馨提示
+        data.put("thing9",thing9);
+        // 下单时间
+        data.put("time31",time31);
+        message.put("data", data);
+        System.out.println(message);
+        return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+token, message);
+    }
+
+
+}