From b0c72c63dadd0221b5923b40affe7a0b345f7df7 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Wed, 17 Jun 2020 17:19:52 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java                          |    4 -
 src/main/java/com/xcong/excoin/utils/mail/SmsSend.java                              |  126 ++++++++++++++++++++++++++++++++++++++++++
 src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java |    2 
 3 files changed, 127 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java b/src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java
index ac6ee46..95d294a 100644
--- a/src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java
@@ -141,7 +141,7 @@
         homeSymbolsVo.setUpOrDown(upOrDown);
         homeSymbolsVo.setVolume(symbolObject.getAmount());
         if (cnyUsdtExchange != null) {
-            BigDecimal cnyPrice = openPrice.multiply(cnyUsdtExchange.getValue()).setScale(2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal cnyPrice = newestPrice.multiply(cnyUsdtExchange.getValue()).setScale(2, BigDecimal.ROUND_HALF_UP);
             homeSymbolsVo.setCnyPrice(cnyPrice);
         }
 
diff --git a/src/main/java/com/xcong/excoin/utils/mail/SmsSend.java b/src/main/java/com/xcong/excoin/utils/mail/SmsSend.java
new file mode 100644
index 0000000..b810df6
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/utils/mail/SmsSend.java
@@ -0,0 +1,126 @@
+package com.xcong.excoin.utils.mail;
+
+import net.sf.json.JSONObject;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+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.HttpClientBuilder;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * @author wzy
+ * @date 2020-06-17
+ **/
+public class SmsSend {
+    /**
+     * 时间戳接口配置
+     */
+    public static final String TIMESTAMP = "https://api.mysubmail.com/service/timestamp";
+
+    public static final String TYPE_MD5 = "md5";
+    public static final String TYPE_SHA1 = "sha1";
+    /**
+     * API 请求接口配置
+     */
+    private static final String URL = "https://api.mysubmail.com/message/xsend";
+
+
+    public static boolean sendVerifyCode(String telphone, String code, int time) {
+        TreeMap<String, Object> requestData = new TreeMap<String, Object>();
+        JSONObject vars = new JSONObject();
+
+        String appid = "51258";
+        String appkey = "a9b6e0758dc40d3c346887fc0e154642";
+        String project = "E98Tx3";
+        String signtype = "";
+        vars.put("code", code);
+        vars.put("time", time);
+
+        requestData.put("appid", appid);
+        requestData.put("project", project);
+        requestData.put("to", telphone);
+        if (!vars.isEmpty()) {
+            requestData.put("vars", vars.toString());
+        }
+
+        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+        @SuppressWarnings("deprecation")
+        ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8);
+        for (Map.Entry<String, Object> entry : requestData.entrySet()) {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+            if (value instanceof String) {
+                builder.addTextBody(key, String.valueOf(value), contentType);
+            }
+        }
+        if (signtype.equals(TYPE_MD5) || signtype.equals(TYPE_SHA1)) {
+            String timestamp = getTimestamp();
+            requestData.put("timestamp", timestamp);
+            requestData.put("sign_type", signtype);
+            String signStr = appid + appkey + RequestEncoder.formatRequest(requestData) + appid + appkey;
+
+            builder.addTextBody("timestamp", timestamp);
+            builder.addTextBody("sign_type", signtype);
+            builder.addTextBody("signature", RequestEncoder.encode(signtype, signStr), contentType);
+        } else {
+            builder.addTextBody("signature", appkey, contentType);
+        }
+
+        HttpPost httpPost = new HttpPost(URL);
+        httpPost.addHeader("charset", "UTF-8");
+        httpPost.setEntity(builder.build());
+        try {
+            CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build();
+            HttpResponse response = closeableHttpClient.execute(httpPost);
+            HttpEntity httpEntity = response.getEntity();
+            if (httpEntity != null) {
+                String jsonStr = EntityUtils.toString(httpEntity, "UTF-8");
+                System.out.println(jsonStr);
+                if ("success".equals(JSONObject.fromObject(jsonStr).getString("status"))) {
+                    return true;
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    /**
+     * 获取时间戳
+     *
+     * @return
+     */
+    private static String getTimestamp() {
+        CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build();
+        HttpGet httpget = new HttpGet(TIMESTAMP);
+        try {
+            HttpResponse response = closeableHttpClient.execute(httpget);
+            HttpEntity httpEntity = response.getEntity();
+            String jsonStr = EntityUtils.toString(httpEntity, "UTF-8");
+            if (jsonStr != null) {
+                JSONObject json = JSONObject.fromObject(jsonStr);
+                return json.getString("timestamp");
+            }
+            closeableHttpClient.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    public static void main(String[] args) {
+        sendVerifyCode("15773002834", "123456", 2);
+    }
+}
diff --git a/src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java b/src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java
index 0ba66e9..782ebd3 100644
--- a/src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java
+++ b/src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java
@@ -92,8 +92,6 @@
                     return true;
                 }
             }
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -118,8 +116,6 @@
                 return json.getString("timestamp");
             }
             closeableHttpClient.close();
-        } catch (ClientProtocolException e) {
-            e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }

--
Gitblit v1.9.1