Browse Source

上传文件

陈士柏 2 years ago
parent
commit
908275c623

+ 79 - 0
mhotel/src/com/happy/common/http/Get_airticle.java

@@ -0,0 +1,79 @@
+package com.happy.common.http;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.happy.Model.weixin.AccessToken;
+import com.happy.Model.weixin.WeiXinUtil;
+import com.happy.Until.HttpUtils;
+import com.happy.common.model.airticle.*;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import java.awt.*;
+import java.util.List;
+
+public class Get_airticle {
+
+    public static List<Item_content> get(int page, int rows) throws Exception {
+        Gson gson = new Gson();
+        int start = (page - 1) * rows;// 每页的起始下标
+        String access_token = "";
+        JSONObject json = new JSONObject();
+        json.put("grant_type", "client_credential");
+        json.put("appid", "wx19d0b6ab36feedf4");
+        json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
+        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 data = new JSONObject();
+        data.put("offset", start);
+        data.put("count", rows);
+        data.put("no_content", 0);
+        String msg =  HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token="+access_token, data);
+        Item item = JSONObject.parseObject(msg,Item.class);
+        return item.getItem();
+    }
+
+    public static int getTotal() throws Exception {
+        Gson gson = new Gson();
+        String access_token = "";
+        JSONObject json = new JSONObject();
+        json.put("grant_type", "client_credential");
+        json.put("appid", "wx19d0b6ab36feedf4");
+        json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
+        String url = "https://api.weixin.qq.com/cgi-bin/stable_token";
+        access_token = HttpsClient.sendJson(url,json);
+        System.out.println(access_token);
+        access_token = gson.fromJson(access_token, AccessToken.class).getAccess_token();
+        JSONObject data = new JSONObject();
+        String msg =  HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/count?access_token="+access_token, data);
+        System.out.println(msg);
+        New_count item = JSONObject.parseObject(msg, New_count.class);
+        return item.getTotal_count();
+    }
+
+    public static Content getByMediaId(String media_id) throws Exception {
+        Gson gson = new Gson();
+        String access_token = "";
+        JSONObject json = new JSONObject();
+        json.put("grant_type", "client_credential");
+        json.put("appid", "wx19d0b6ab36feedf4");
+        json.put("secret","c16af9c2f93e48f8ae9a5492beb261f4");
+        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 data = new JSONObject();
+        data.put("media_id", media_id);
+        String msg =  HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/draft/get?access_token="+access_token, data);
+        return JSONObject.parseObject(msg,Content.class);
+    }
+
+    public static String getFirstImg(String content){
+        Document doc = Jsoup.parse(content);
+        Elements links = doc.select("img[data-src]");
+        return links.get(0).attr("data-src");
+    }
+
+}

+ 535 - 0
mhotel/src/com/happy/common/http/HttpsClient.java

@@ -0,0 +1,535 @@
+package com.happy.common.http;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.happy.Until.CreateSign1;
+import com.happy.Until.TimeExchange;
+import com.happy.common.wx.WxConfig;
+import com.happy.common.wx.WxConstants;
+import com.happy.common.wx.WxUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * HttpsClient类
+ * @author lujunjie
+ * @date   2018/03/01
+ */
+public class HttpsClient {
+
+    /**
+     * GET请求方式
+     */
+    public static final String METHOD_GET = "GET";
+    /**
+     * POST请求方式
+     */
+    public static final String METHOD_POST = "POST";
+    /**
+     * 连接超时时间
+     */
+    private static Integer CONNECTION_TIMEOUT = WxConfig.connectionTimeout;
+    /**
+     * 请求超时时间
+     */
+    private static Integer READ_TIMEOUT = WxConfig.readTimeout;
+
+    /**
+     * 发起https请求
+     * @param requestUrl 请求地址
+     * @param requestMethod 请求方式(Get或者post)
+     * @param postData 提交数据
+     * @return JSONObject
+     */
+    public static JSONObject httpsRequestReturnJSONObject(String requestUrl, String requestMethod, String postData) throws Exception{
+        JSONObject  jsonObject = JSONObject.parseObject(HttpsClient.httpsRequestReturnString(requestUrl,requestMethod,postData));
+        System.out.println("jsonObjectDate:  " + jsonObject);
+        return jsonObject;
+    }
+
+
+    /**
+     * 发起https请求
+     * @param requestUrl 请求地址
+     * @param requestMethod 请求方式(Get或者post)
+     * @param postData 提交数据
+     * @return String
+     */
+    public static String httpsRequestReturnString(String requestUrl, String requestMethod, String postData) throws Exception{
+        String response;
+        HttpsURLConnection httpsUrlConnection = null;
+        try{
+            //创建https请求证书
+            TrustManager[] tm={new MyX509TrustManager()};
+            //创建SSLContext管理器对像,使用我们指定的信任管理器初始化
+            SSLContext sslContext=SSLContext.getInstance("SSL","SunJSSE");
+            sslContext.init(null, tm, new java.security.SecureRandom());
+            SSLSocketFactory ssf=sslContext.getSocketFactory();
+
+            // 创建URL对象
+            URL url= new URL(requestUrl);
+            // 创建HttpsURLConnection对象,并设置其SSLSocketFactory对象
+            httpsUrlConnection=(HttpsURLConnection)url.openConnection();
+            //设置ssl证书
+            httpsUrlConnection.setSSLSocketFactory(ssf);
+
+            //设置header信息
+            httpsUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            //设置User-Agent信息
+            httpsUrlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
+            //设置可接受信息
+            httpsUrlConnection.setDoOutput(true);
+            //设置可输入信息
+            httpsUrlConnection.setDoInput(true);
+            //不使用缓存
+            httpsUrlConnection.setUseCaches(false);
+            //设置请求方式(GET/POST)
+            httpsUrlConnection.setRequestMethod(requestMethod);
+            //设置连接超时时间
+            if (CONNECTION_TIMEOUT > 0) {
+                httpsUrlConnection.setConnectTimeout(CONNECTION_TIMEOUT);
+            } else {
+                //默认10秒超时
+                httpsUrlConnection.setConnectTimeout(10000);
+            }
+            //设置请求超时
+            if (READ_TIMEOUT > 0) {
+                httpsUrlConnection.setReadTimeout(READ_TIMEOUT);
+            } else {
+                //默认10秒超时
+                httpsUrlConnection.setReadTimeout(10000);
+            }
+            //设置编码
+            httpsUrlConnection.setRequestProperty("Charsert", WxConstants.DEFAULT_CHARSET);
+
+            //判断是否需要提交数据
+            if(StringUtils.equals(requestMethod,HttpsClient.METHOD_POST) && StringUtils.isNotBlank(postData)){
+                //讲参数转换为字节提交
+                byte[] bytes = postData.getBytes(WxConstants.DEFAULT_CHARSET);
+                //设置头信息
+                httpsUrlConnection.setRequestProperty("Content-Length", Integer.toString(bytes.length));
+                //开始连接
+                httpsUrlConnection.connect();
+                //防止中文乱码
+                OutputStream outputStream=httpsUrlConnection.getOutputStream();
+                outputStream.write(postData.getBytes(WxConstants.DEFAULT_CHARSET));
+                outputStream.flush();
+                outputStream.close();
+            }else{
+                //开始连接
+                httpsUrlConnection.connect();
+            }
+            response = WxUtil.getStreamString(httpsUrlConnection.getInputStream());
+        }catch (Exception e){
+            throw new Exception();
+        }finally {
+            if (httpsUrlConnection != null) {
+                // 关闭连接
+                httpsUrlConnection.disconnect();
+            }
+        }
+        return response;
+    }
+
+
+    public static String get(String url, Map<String, String> params){
+        CloseableHttpClient httpClient = null;
+        HttpGet httpGet = null;
+        StringBuffer str = new StringBuffer("");
+        try {
+            httpClient = HttpClients.createDefault();
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000).build();
+            String ps = "";
+            for (String pKey : params.keySet()) {
+                if(!"".equals(ps)){
+                    ps = ps + "&";
+                }
+                ps = pKey+"="+params.get(pKey);
+            }
+            if(!"".equals(ps)){
+                url = url + "?" + ps;
+            }
+            httpGet = new HttpGet(url);
+            httpGet.setConfig(requestConfig);
+            CloseableHttpResponse response = httpClient.execute(httpGet);
+            HttpEntity httpEntity = response.getEntity();
+            str.append(EntityUtils.toString(httpEntity,"utf-8"));
+        } catch (ClientProtocolException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }finally{
+            try {
+                if(httpGet!=null){
+                    httpGet.releaseConnection();
+                }
+                if(httpClient!=null){
+                    httpClient.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return str.toString();
+    }
+
+    public static String get(String strURL) throws Exception{
+
+        URL url = new URL(strURL);
+        HttpURLConnection httpConn = (HttpURLConnection)
+                url.openConnection();
+        httpConn.setRequestMethod("GET");
+        httpConn.connect();
+        System.out.println("bbb: "+httpConn.getResponseCode());
+        BufferedReader reader = new BufferedReader(new InputStreamReader(
+                httpConn.getInputStream(),"utf-8"));
+        String line;
+        StringBuffer buffer = new StringBuffer();
+        while ((line = reader.readLine()) != null) {
+            buffer.append(line);
+        }
+        reader.close();
+        httpConn.disconnect();
+
+        return buffer.toString();
+    }
+
+    /**
+     * 发送 post请求
+     * @param
+     * @param
+     */
+    public static String post(String url, Map<String, String> params){
+        CloseableHttpClient httpClient = null;
+        HttpPost httpPost = null;
+        StringBuilder sb = new StringBuilder("");
+        try {
+            httpClient = HttpClients.createDefault();
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000).build();
+            httpPost = new HttpPost(url);
+            httpPost.setConfig(requestConfig);
+            List<NameValuePair> ps = new ArrayList<NameValuePair>();
+            for (String pKey : params.keySet()) {
+                ps.add(new BasicNameValuePair(pKey, params.get(pKey)));
+            }
+            httpPost.setEntity(new UrlEncodedFormEntity(ps));
+            CloseableHttpResponse response = httpClient.execute(httpPost);
+            HttpEntity httpEntity = response.getEntity();
+            sb.append(EntityUtils.toString(httpEntity,"utf-8"));
+        } catch (ClientProtocolException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }finally{
+            try {
+                if(httpPost!=null){
+                    httpPost.releaseConnection();
+                }
+                if(httpClient!=null){
+                    httpClient.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return sb.toString();
+    }
+
+    public static String postFile(String url, File file){
+
+        CloseableHttpClient httpClient = null;
+        HttpPost httpPost = null;
+        StringBuilder sb = new StringBuilder("");
+        try {
+            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+            builder.addBinaryBody("files", file, ContentType.DEFAULT_BINARY, file.getName());
+            httpClient = HttpClients.createDefault();
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20000).setConnectTimeout(20000).build();
+            httpPost = new HttpPost(url);
+            httpPost.setConfig(requestConfig);
+            httpPost.setEntity(builder.build());
+            CloseableHttpResponse response = httpClient.execute(httpPost);
+            HttpEntity httpEntity = response.getEntity();
+            sb.append(EntityUtils.toString(httpEntity,"utf-8"));
+        } catch (ClientProtocolException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }finally{
+            try {
+                if(httpPost!=null){
+                    httpPost.releaseConnection();
+                }
+                if(httpClient!=null){
+                    httpClient.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        JSONObject  jsonObject = JSONObject.parseObject(sb.toString());
+        return jsonObject.get("data").toString();
+    }
+
+    //url表示请求链接,param表示json格式的请求参数		//自定义菜单创建访问方式
+    public static String sendPost(String url, String param) {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+        try {
+            URL realUrl = new URL(url);
+            // 打开和URL之间的连接
+            URLConnection conn = realUrl.openConnection();
+            // 设置通用的请求属性 注意Authorization生成
+            // conn.setRequestProperty("Content-Type",
+            // "application/x-www-form-urlencoded");
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(),"utf-8"));
+            // 发送请求参数
+            out.print("&"+param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream(),"utf-8"));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送 请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+
+    //url表示请求链接,param表示json格式的请求参数		//自定义菜单创建访问方式
+    public static String sendPost2(String url, String param) {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+        try {
+            HttpsURLConnection httpsUrlConnection = null;
+            //创建https请求证书
+            TrustManager[] tm={new MyX509TrustManager()};
+            //创建SSLContext管理器对像,使用我们指定的信任管理器初始化
+            SSLContext sslContext=SSLContext.getInstance("SSL","SunJSSE");
+            sslContext.init(null, tm, new java.security.SecureRandom());
+            SSLSocketFactory ssf=sslContext.getSocketFactory();
+            // 创建URL对象
+            URL realUrl= new URL(url);
+            // 创建HttpsURLConnection对象,并设置其SSLSocketFactory对象,
+            // 打开和URL之间的连接
+            httpsUrlConnection=(HttpsURLConnection)realUrl.openConnection();
+            //设置ssl证书
+            httpsUrlConnection.setSSLSocketFactory(ssf);
+            // 设置通用的请求属性 注意Authorization生成
+            // conn.setRequestProperty("Content-Type",
+            // "application/x-www-form-urlencoded");
+            // 发送POST请求必须设置如下两行
+            httpsUrlConnection.setRequestMethod("POST");
+            httpsUrlConnection.setDoOutput(true);
+            httpsUrlConnection.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(new OutputStreamWriter(httpsUrlConnection.getOutputStream(),"utf-8"));
+            // 发送请求参数
+            out.print("&"+param);
+            // flush输出流的缓冲
+            out.flush();
+            if (httpsUrlConnection.getResponseCode()==200) {
+                // 定义BufferedReader输入流来读取URL的响应
+                in = new BufferedReader(
+                        new InputStreamReader(httpsUrlConnection.getInputStream(), "utf-8"));
+                String line;
+                while ((line = in.readLine()) != null) {
+                    result += line;
+                }
+            }else {
+                result = "获取输入流异常!";
+            }
+        } catch (Exception e) {
+            System.out.println("发送 请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    public static String dateToStamp(String s) throws Exception {
+        String res = "";
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = simpleDateFormat.parse(s);
+        long time = date.getTime();
+        res = String.valueOf(time);
+        return res;
+    }
+
+    /*
+     * 将时间戳转换为时间
+     */
+    public static String stampToDate(String s){
+        String res;
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long lt = new Long(s);
+        Date date = new Date(lt);
+        res = simpleDateFormat.format(date);
+        return res;
+    }
+
+    public static String sendJson(String request_url, JSONObject json) {
+        OutputStreamWriter out = null;
+        InputStream is = null;
+        String result = "";
+        try {
+            URL url = new URL(request_url);// 创建连接
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+            connection.setUseCaches(false);
+            connection.setInstanceFollowRedirects(true);
+            connection.setRequestMethod("POST"); // 设置请求方式
+            // 设置接收数据的格式
+            connection.setRequestProperty("Accept", "application/json");
+            // 设置发送数据的格式
+            connection.setRequestProperty("Content-Type", "application/json");
+            connection.connect();
+            out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
+            out.append(json.toString());
+            out.flush();
+            out.close();
+            // 读取响应
+            is = connection.getInputStream();
+            int length = (int) connection.getContentLength();// 获取字节长度
+            System.out.println(length);
+            if (length != -1) {
+                byte[] data = new byte[length];
+                byte[] temp = new byte[512];
+                int readLen = 0;
+                int destPos = 0;
+                while ((readLen = is.read(temp)) > 0) {
+                    System.arraycopy(temp, 0, data, destPos, readLen);
+                    destPos += readLen;
+                }
+                result = new String(data, "UTF-8"); // utf-8编码
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                is.close();
+                out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * post请求
+     * @param request_url
+     * @param json
+     * @return
+     */
+    public static String sendJson2(String request_url, JSONObject json) {
+        OutputStreamWriter out = null;
+        InputStream is = null;
+        String result = "";
+        try {
+            URL url = new URL(request_url);// 创建连接
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+            connection.setUseCaches(false);
+            connection.setInstanceFollowRedirects(true);
+            connection.setRequestMethod("POST"); // 设置请求方式
+            // 设置接收数据的格式
+            connection.setRequestProperty("Accept", "application/json");
+            // 设置发送数据的格式
+            connection.setRequestProperty("Content-Type", "application/json");
+            connection.connect();
+            out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
+            out.append(json.toString());
+            out.flush();
+            out.close();
+            // 读取响应
+            is = connection.getInputStream();
+            BufferedReader in = new BufferedReader(new InputStreamReader(is));
+            result = in.readLine();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                is.close();
+                out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    public static void main(String[] args) throws Exception {
+        JSONObject json = new JSONObject();
+        json.put("buildCode", "5栋");
+        json.put("currentAggr", "20");
+        json.put("energyType", "2");
+        json.put("updateTime", "2021-09-09 10:15:33");
+        String msg = sendJson2("https://chtech.ncjti.edu.cn/bigdata-api/api/energy/energyDataUpload", json);
+        System.out.println(msg);
+    }
+}

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

@@ -0,0 +1,548 @@
+package com.happy.common.http;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.happy.Model.weixin.WeiXinUtil;
+import com.happy.Until.Enum.PayEnum;
+import com.happy.Until.Func;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+// 小程序消息通知
+public class Message {
+
+    /**
+     * hotel_name酒店名称
+     * order_status订单状态,用中文表示
+     * live_time入住时间
+     * end_time离店时间
+     * dom_name房间名称
+     * **/
+
+    public static String send(String openid,String hotel_name,
+                              String order_status,String live_time,
+                              String end_time,String dom_name)
+            throws Exception {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("grant_type", "client_credential");
+        jsonObject.put("appid", WeiXinUtil.appid_c);
+        jsonObject.put("secret",WeiXinUtil.screct_c);
+        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", "c9whRYC3d8ebNI_RdyG2X_1BBDwy2625hHmRWlW5Z9U");
+        message.put("page", "/pages/orderManage/orderManage");
+        message.put("miniprogram_state", "formal");
+        message.put("lang", "zh_CN");
+        JSONObject data = new JSONObject();
+        // 酒店名称
+        JSONObject string1 = new JSONObject();
+        string1.put("value", hotel_name);
+        // 订单状态
+        JSONObject phrase2 = new JSONObject();
+        phrase2.put("value", PayEnum.getValueBykey(Func.parseInt(order_status)));
+        // 到店时间
+        JSONObject date5 = new JSONObject();
+        date5.put("value", live_time);
+        // 离店时间
+        JSONObject date6 = new JSONObject();
+        date6.put("value", end_time);
+        // 房间名称
+        JSONObject thing27 = new JSONObject();
+        thing27.put("value", dom_name);
+        // 酒店名称
+        data.put("thing1",string1);
+        // 订单状态
+        data.put("phrase2",phrase2);
+        // 入住日期
+        data.put("date5",date5);
+        // 离店日期
+        data.put("date6",date6);
+        // 房间名称
+        data.put("thing27",thing27);
+        message.put("data", data);
+        return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+token, message);
+    }
+
+    public static String wxErrorMsg(String mag) {
+        Map mapType = JSON.parseObject(mag, Map.class);
+        Integer errorcode = (Integer) mapType.get("errcode");
+        String errmsg = "";
+        switch (errorcode) {
+            case -1:
+                errmsg = "系统繁忙";
+                break;
+            case 0:
+                errmsg = "请求成功";
+                break;
+            case 40001:
+                errmsg = "获取access_token时Secret错误,或者access_token无效";
+                break;
+            case 40002:
+                errmsg = "不合法的凭证类型";
+                break;
+            case 40003:
+                errmsg = "不合法的UserID";
+                break;
+            case 40004:
+                errmsg = "不合法的媒体文件类型 ";
+                break;
+            case 40005:
+                errmsg = "不合法的文件类型 ";
+                break;
+            case 40006:
+                errmsg = "不合法的文件大小";
+                break;
+            case 40007:
+                errmsg = "不合法的媒体文件id";
+                break;
+            case 40008:
+                errmsg = "不合法的消息类型 ";
+                break;
+            case 40013:
+                errmsg = "不合法的corpid ";
+                break;
+            case 40014:
+                errmsg = "不合法的access_token";
+                break;
+            case 40015:
+                errmsg = "不合法的菜单类型";
+                break;
+            case 40016:
+                errmsg = "不合法的按钮个数";
+                break;
+            case 40017:
+                errmsg = "不合法的按钮类型";
+                break;
+            case 40018:
+                errmsg = "不合法的按钮名字长度";
+                break;
+            case 40019:
+                errmsg = "不合法的按钮KEY长度";
+                break;
+            case 40020:
+                errmsg = "不合法的按钮URL长度 ";
+                break;
+            case 40021:
+                errmsg = "不合法的菜单版本号 ";
+                break;
+            case 40022:
+                errmsg = "不合法的子菜单级数";
+                break;
+            case 40023:
+                errmsg = "不合法的子菜单按钮个数";
+                break;
+            case 40024:
+                errmsg = "不合法的子菜单按钮类型";
+                break;
+            case 40025:
+                errmsg = "不合法的子菜单按钮名字长度";
+                break;
+            case 40026:
+                errmsg = "不合法的子菜单按钮KEY长度";
+                break;
+            case 40027:
+                errmsg = "不合法的子菜单按钮URL长度";
+                break;
+            case 40028:
+                errmsg = "不合法的自定义菜单使用员工";
+                break;
+            case 40029:
+                errmsg = "不合法的oauth_code";
+                break;
+            case 40031:
+                errmsg = "不合法的UserID列表";
+                break;
+            case 40032:
+                errmsg = "不合法的UserID列表长度";
+                break;
+            case 40033:
+                errmsg = "不合法的请求字符,不能包含\\uxxxx格式的字符 ";
+                break;
+            case 40035:
+                errmsg = "不合法的参数 ";
+                break;
+            case 40038:
+                errmsg = "不合法的请求格式 ";
+                break;
+            case 40039:
+                errmsg = "不合法的URL长度";
+                break;
+            case 40040:
+                errmsg = "不合法的插件token";
+                break;
+            case 40041:
+                errmsg = "不合法的插件id";
+                break;
+            case 40042:
+                errmsg = "不合法的插件会话";
+                break;
+            case 40048:
+                errmsg = "url中包含不合法domain";
+                break;
+            case 40054:
+                errmsg = "不合法的子菜单url域名";
+                break;
+            case 40055:
+                errmsg = "不合法的按钮url域名 ";
+                break;
+            case 40056:
+                errmsg = "不合法的agentid";
+                break;
+            case 40057:
+                errmsg = "不合法的callbackurl";
+                break;
+            case 40058:
+                errmsg = "不合法的红包参数 ";
+                break;
+            case 40059:
+                errmsg = "不合法的上报地理位置标志位 ";
+                break;
+            case 40060:
+                errmsg = "设置上报地理位置标志位时没有设置callbackurl";
+                break;
+            case 40061:
+                errmsg = "设置应用头像失败";
+                break;
+            case 40062:
+                errmsg = "不合法的应用模式";
+                break;
+            case 40063:
+                errmsg = "红包参数为空";
+                break;
+            case 40064:
+                errmsg = "管理组名字已存在";
+                break;
+            case 40065:
+                errmsg = "不合法的管理组名字长度";
+                break;
+            case 40066:
+                errmsg = "不合法的部门列表";
+                break;
+            case 40067:
+                errmsg = "标题长度不合法 ";
+                break;
+            case 40068:
+                errmsg = "不合法的标签ID";
+                break;
+            case 40069:
+                errmsg = "不合法的标签ID列表";
+                break;
+            case 40070:
+                errmsg = "列表中所有标签(用户)ID都不合法  ";
+                break;
+            case 40071:
+                errmsg = "不合法的标签名字,标签名字已经存在 ";
+                break;
+            case 40072:
+                errmsg = "不合法的标签名字长度";
+                break;
+            case 40073:
+                errmsg = "不合法的openid";
+                break;
+            case 40074:
+                errmsg = "news消息不支持指定为高保密消息";
+                break;
+            case 41001:
+                errmsg = "缺少access_token参数 ";
+                break;
+            case 41002:
+                errmsg = "缺少corpid参数";
+                break;
+            case 41003:
+                errmsg = "缺少refresh_token参数";
+                break;
+            case 41004:
+                errmsg = "缺少secret参数";
+                break;
+            case 41005:
+                errmsg = "缺少多媒体文件数据";
+                break;
+            case 41006:
+                errmsg = "缺少media_id参数";
+                break;
+            case 41007:
+                errmsg = "缺少子菜单数据";
+                break;
+            case 41008:
+                errmsg = "缺少oauth code";
+                break;
+            case 41009:
+                errmsg = "缺少UserID";
+                break;
+            case 41010:
+                errmsg = "缺少url";
+                break;
+            case 41011:
+                errmsg = "缺少agentid";
+                break;
+            case 41012:
+                errmsg = "缺少应用头像mediaid";
+                break;
+            case 41013:
+                errmsg = "缺少应用名字";
+                break;
+            case 41014:
+                errmsg = "缺少应用描述";
+                break;
+            case 41015:
+                errmsg = "缺少Content";
+                break;
+            case 41016:
+                errmsg = "缺少标题";
+                break;
+            case 41017:
+                errmsg = "缺少标签ID";
+                break;
+            case 41018:
+                errmsg = "缺少标签名字 ";
+                break;
+            case 42001:
+                errmsg = "access_token超时 ";
+                break;
+            case 42002:
+                errmsg = "refresh_token超时";
+                break;
+            case 42003:
+                errmsg = "oauth_code超时 ";
+                break;
+            case 42004:
+                errmsg = "插件token超时";
+                break;
+            case 43001:
+                errmsg = "需要GET请求";
+                break;
+            case 43002:
+                errmsg = "需要POST请求";
+                break;
+            case 43003:
+                errmsg = "需要HTTPS";
+                break;
+            case 43004:
+                errmsg = "需要接收者关注";
+                break;
+            case 43005:
+                errmsg = "需要好友关系";
+                break;
+            case 43006:
+                errmsg = "需要订阅";
+                break;
+            case 43007:
+                errmsg = "需要授权";
+                break;
+            case 43008:
+                errmsg = "需要支付授权";
+                break;
+            case 43009:
+                errmsg = "需要员工已关注";
+                break;
+            case 43010:
+                errmsg = "需要处于回调模式";
+                break;
+            case 43011:
+                errmsg = "需要企业授权";
+                break;
+            case 43101:
+                errmsg = "用户拒绝接受消息,如果用户之前曾经订阅过,则表示用户取消了订阅关系";
+                break;
+            case 44001:
+                errmsg = "多媒体文件为空";
+                break;
+            case 44002:
+                errmsg = "POST的数据包为空";
+                break;
+            case 44003:
+                errmsg = "图文消息内容为空";
+                break;
+            case 44004:
+                errmsg = "文本消息内容为空";
+                break;
+            case 45001:
+                errmsg = "多媒体文件大小超过限制";
+                break;
+            case 45002:
+                errmsg = "消息内容超过限制";
+                break;
+            case 45003:
+                errmsg = "标题字段超过限制";
+                break;
+            case 45004:
+                errmsg = "描述字段超过限制";
+                break;
+            case 45005:
+                errmsg = "链接字段超过限制";
+                break;
+            case 45006:
+                errmsg = "图片链接字段超过限制";
+                break;
+            case 45007:
+                errmsg = "语音播放时间超过限制";
+                break;
+            case 45008:
+                errmsg = "图文消息超过限制";
+                break;
+            case 45009:
+                errmsg = "接口调用超过限制";
+                break;
+            case 45010:
+                errmsg = "创建菜单个数超过限制";
+                break;
+            case 45015:
+                errmsg = "回复时间超过限制";
+                break;
+            case 45016:
+                errmsg = "系统分组,不允许修改";
+                break;
+            case 45017:
+                errmsg = "分组名字过长";
+                break;
+            case 45018:
+                errmsg = "分组数量超过上限";
+                break;
+            case 45024:
+                errmsg = "账号数量超过上限";
+                break;
+            case 46001:
+                errmsg = "不存在媒体数据";
+                break;
+            case 46002:
+                errmsg = "不存在的菜单版本";
+                break;
+            case 46003:
+                errmsg = "不存在的菜单数据";
+                break;
+            case 46004:
+                errmsg = "不存在的员工";
+                break;
+            case 47001:
+                errmsg = "解析JSON/XML内容错误";
+                break;
+            case 48002:
+                errmsg = "Api禁用";
+                break;
+            case 50001:
+                errmsg = "redirect_uri未授权";
+                break;
+            case 50002:
+                errmsg = "员工不在权限范围";
+                break;
+            case 50003:
+                errmsg = "应用已停用";
+                break;
+            case 50004:
+                errmsg = "员工状态不正确(未关注状态) ";
+                break;
+            case 50005:
+                errmsg = "企业已禁用";
+                break;
+            case 60001:
+                errmsg = "部门长度不符合限制";
+                break;
+            case 60002:
+                errmsg = "部门层级深度超过限制";
+                break;
+            case 60003:
+                errmsg = "部门不存在";
+                break;
+            case 60004:
+                errmsg = "父亲部门不存在";
+                break;
+            case 60005:
+                errmsg = "不允许删除有成员的部门";
+                break;
+            case 60006:
+                errmsg = "不允许删除有子部门的部门";
+                break;
+            case 60007:
+                errmsg = "不允许删除根部门";
+                break;
+            case 60008:
+                errmsg = "部门名称已存在";
+                break;
+            case 60009:
+                errmsg = "部门名称含有非法字符";
+                break;
+            case 60010:
+                errmsg = "部门存在循环关系";
+                break;
+            case 60011:
+                errmsg = "管理员权限不足,(user/department/agent)无权限";
+                break;
+            case 60012:
+                errmsg = "不允许删除默认应用";
+                break;
+            case 60013:
+                errmsg = "不允许关闭应用";
+                break;
+            case 60014:
+                errmsg = "不允许开启应用";
+                break;
+            case 60015:
+                errmsg = "不允许修改默认应用可见范围";
+                break;
+            case 60016:
+                errmsg = "不允许删除存在成员的标签";
+                break;
+            case 60017:
+                errmsg = "不允许设置企业";
+                break;
+            case 60102:
+                errmsg = "UserID已存在";
+                break;
+            case 60103:
+                errmsg = "手机号码不合法";
+                break;
+            case 60104:
+                errmsg = "手机号码已存在";
+                break;
+            case 60105:
+                errmsg = "邮箱不合法";
+                break;
+            case 60106:
+                errmsg = "邮箱已存在";
+                break;
+            case 60107:
+                errmsg = "微信号不合法";
+                break;
+            case 60108:
+                errmsg = "微信号已存在";
+                break;
+            case 60109:
+                errmsg = "QQ号已存在";
+                break;
+            case 60110:
+                errmsg = "部门个数超出限制";
+                break;
+            case 60111:
+                errmsg = "UserID不存在";
+                break;
+            case 60112:
+                errmsg = "成员姓名不合法";
+                break;
+            case 60113:
+                errmsg = "身份认证信息(微信号/手机/邮箱)不能同时为空 ";
+                break;
+            case 60114:
+                errmsg = "性别不合法";
+                break;
+
+            default:
+                errmsg = "没有此错误码! ";
+                break;
+        }
+        return errmsg;
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        System.out.println(send("ou2uV5Oqu_qLJLfCGshpj_b5ajno","测试","测试",
+                "2023-08-25","2023-08-26","cesss"));
+    }
+}

+ 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);
+    }
+
+}

+ 82 - 0
mhotel/src/com/happy/common/http/Message3.java

@@ -0,0 +1,82 @@
+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.WechatResult;
+import com.happy.Model.weixin.WeiXinUtil;
+import com.happy.Until.HttpUtils;
+
+import java.util.HashMap;
+
+public class Message3 {
+
+    /** 小程序推送消息到公众号
+     * 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 {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("grant_type", "client_credential");
+        jsonObject.put("appid", WeiXinUtil.appid_c); // 小程序
+        jsonObject.put("secret",WeiXinUtil.screct_c);
+        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);
+
+        Mp_template_msg mp_template_msg = new Mp_template_msg();
+        mp_template_msg.setAppid(WeiXinUtil.appid_g);  // 公众号
+        mp_template_msg.setTemplate_id("pQLY-9pKW-lD-6PuOlxieatGmuCHOezubTxI99cs7Zo");
+        mp_template_msg.setUrl("index");
+        JSONObject jsonObject1 = new JSONObject();
+        jsonObject1.put("appid",WeiXinUtil.appid_c);
+        jsonObject1.put("pagepath","/pages/push/push?id="+id);
+        mp_template_msg.setMiniprogram(jsonObject1);
+        // 订单号
+        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_);
+        mp_template_msg.setData(data);
+        message.put("mp_template_msg",mp_template_msg);
+        return HttpsClient.sendJson("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token="+token, message);
+
+    }
+
+}

+ 23 - 0
mhotel/src/com/happy/common/http/MyX509TrustManager.java

@@ -0,0 +1,23 @@
+package com.happy.common.http;
+
+import javax.net.ssl.X509TrustManager;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+/**
+ * X509TrustManager用于实现SSL证书的安全校验
+ * @author lujunjie
+ * @date   2018/03/01
+ */
+public class MyX509TrustManager implements X509TrustManager {
+    @Override
+    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
+
+    @Override
+    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
+
+    @Override
+    public X509Certificate[] getAcceptedIssuers() {
+        return null;
+    }
+}