소스 검색

调整特殊字符传输问题,添加评论提示信息和发布提示信息。完善评论判断逻辑

huangct 8 년 전
부모
커밋
e5971754e7

+ 68 - 0
jpress-commons/src/main/java/io/jpress/utils/MyEncryptUtils.java

@@ -0,0 +1,68 @@
+package io.jpress.utils;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import java.security.SecureRandom;
+
+/**
+ * Created by 黄诚天 on 2017-09-15.
+ */
+public class MyEncryptUtils {
+
+    /**
+     * 对用DES加密过的数据进行解密.
+     *
+     * @param data DES加密数据
+     * @return 返回解密后的数据
+     * @throws Exception
+     * @author <a href="mailto:xiexingxing1121@126.com" mce_href="mailto:xiexingxing1121@126.com">AmigoXie</a>
+     * Creation date: 2007-7-31 - 下午12:07:54
+     */
+    public final static String encrypt(String data) throws Exception {
+        return byte2hex(encrypt(data.getBytes(), "kEHrDooxWHCWtfeSxvDvgqZq".getBytes()));
+    }
+
+    private static byte[] encrypt(byte[] data, byte[] key) throws Exception {
+        // DES算法要求有一个可信任的随机数源
+        SecureRandom sr = new SecureRandom();
+        // 从原始密匙数据创建DESKeySpec对象
+        DESKeySpec dks = new DESKeySpec(key);
+        // 创建一个密匙工厂,然后用它把DESKeySpec转换成
+        // 一个SecretKey对象
+        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+        SecretKey securekey = keyFactory.generateSecret(dks);
+        // Cipher对象实际完成加密操作
+        Cipher cipher = Cipher.getInstance("DES");
+        // 用密匙初始化Cipher对象
+        cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
+        // 现在,获取数据并加密
+        // 正式执行加密操作
+        return cipher.doFinal(data);
+    }
+
+    public static byte[] hex2byte(byte[] b) {
+        if ((b.length % 2) != 0)
+            throw new IllegalArgumentException("长度不是偶数");
+        byte[] b2 = new byte[b.length / 2];
+        for (int n = 0; n < b.length; n += 2) {
+            String item = new String(b, n, 2);
+            b2[n / 2] = (byte) Integer.parseInt(item, 16);
+        }
+        return b2;
+    }
+
+    public static String byte2hex(byte[] b) {
+        String hs = "";
+        String stmp = "";
+        for (int n = 0; n < b.length; n++) {
+            stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
+            if (stmp.length() == 1)
+                hs = hs + "0" + stmp;
+            else
+                hs = hs + stmp;
+        }
+        return hs.toUpperCase();
+    }
+}

+ 21 - 5
jpress-web-admin/src/main/java/io/jpress/admin/controller/_ContentController.java

@@ -37,6 +37,7 @@ import io.jpress.template.TplModule;
 import io.jpress.template.TplTaxonomyType;
 import io.jpress.utils.HttpUtils;
 import io.jpress.utils.JsoupUtils;
+import io.jpress.utils.MyEncryptUtils;
 import io.jpress.utils.StringUtils;
 
 import java.math.BigInteger;
@@ -458,21 +459,33 @@ public class _ContentController extends JBaseCRUDController<Content> {
 			return;
 		}
 
+		String pushResult = null;
 		if ("uuhelper".equals(content.getModule()) && Content.STATUS_NORMAL.equals(content.getStatus())) {
-			pushUuHelper(content);
+			pushResult = pushUuHelper(content);
 		}
 
 		AjaxResult ar = new AjaxResult();
 		ar.setErrorCode(0);
 		ar.setData(content.getId());
-		renderAjaxResult("save ok", 0, content.getId());
+		renderAjaxResult(pushResult, 0, content.getId());
 	}
 
-	private void pushUuHelper(Content content) {
+	private String pushUuHelper(Content content) {
+		String result = "";
 		Map<String, String> map = new HashMap<>();
 		String requestUrlMessage = this.getRequest().getScheme() +"://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort();
 		JSONObject bodyJO = new JSONObject(true);
-		bodyJO.put("content", content.getTitle());
+		String title = null;
+		String summary = null;
+		try {
+			title = MyEncryptUtils.encrypt(content.getTitle());
+			summary = MyEncryptUtils.encrypt(content.getSummary());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		bodyJO.put("title", title);
+		bodyJO.put("content", summary);
 		bodyJO.put("fromUserId", "10000");
 		bodyJO.put("fromUserName", "系统消息");
 		bodyJO.put("type", 1);
@@ -498,9 +511,12 @@ public class _ContentController extends JBaseCRUDController<Content> {
 
 		try {
 			String response = HttpUtils.post(url);
-			System.out.println(response);
+			result = "软文推送成功";
 		} catch (Exception e) {
 			e.printStackTrace();
+			result = "软文推送失败,联系管理员检查接口";
+		} finally {
+			return result;
 		}
 	}
 

+ 1 - 0
jpress-web-admin/src/main/webapp/WEB-INF/admin/content/edit.html

@@ -145,6 +145,7 @@ function turnPage(){
 				}else{
 					toastr.error(data.message,'操作失败');
 				}
+				toastr.success(data.message);
 			},
 			error : function() {
 				alert("信息提交错误");

+ 8 - 0
jpress-web-front/src/main/java/io/jpress/front/controller/CommentController.java

@@ -100,6 +100,14 @@ public class CommentController extends BaseFrontController {
 			return;
 		}
 
+		//后台加判断用户是否回复过
+		if ((content.isUserReplied(userId) || content.isUuUserReplied(uuUserId)) && "uuhelper".equals(content.getModule())) {
+			if (isAjaxRequest()) {
+				renderAjaxResult("success", 1, null);
+				return;
+			}
+		}
+
 		if (!content.isCommentEnable()) {
 			renderForCommentError("the comment function of the content has been closed.", 1);
 			return;

+ 65 - 2
jpress-web-template-usoftchina/src/main/webapp/templates/usoftchina/content_uuhelper.html

@@ -5,7 +5,10 @@
 <head lang="en">
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0,maximum-scale=1.0, user-scalable=no">
+    <link rel="stylesheet" href="${CPATH}/static/plugins/toastr/toastr.css">
     <script type="text/javascript" src="${CTPATH}/assets/js/jquery.min.js"></script>
+    <script type="text/javascript" src="${CPATH}/static/plugins/jquery/jquery.form.min.js"></script>
+    <script src="${CPATH}/static/plugins/toastr/toastr.js"></script>
     <script src="${CPATH}/counter?cid=${content.id!}"></script>
     <title></title>
     <style>
@@ -249,6 +252,16 @@
             background: #5078cb;
             color: #fff;
         }
+
+        .toast-title {
+            font-weight: bold;
+            font-size: 24px;
+        }
+        .toast-message {
+            -ms-word-wrap: break-word;
+            word-wrap: break-word;
+            font-size: 24px;
+        }
     </style>
     <script>
     </script>
@@ -282,8 +295,8 @@
                     <div class="footer-header">
                         <div class="infoMessage"><span>写留言</span><img src="${CPATH}/static/jpress/admin/image/pen.png" alt=""/></div>
                         <div class="writeMessage">
-                            <textarea name="text" id="" cols="30" rows="10"></textarea>
-                            <div><button class="cancel">取消</button><button type="submit">提交</button></div>
+                            <textarea name="text" id="textareaUas" cols="30" rows="10"></textarea>
+                            <div><button class="cancel">取消</button><button class="submitUas" type="button" onclick="doSubmit()">提交</button></div>
                         </div>
                     </div>
                 </form>
@@ -363,6 +376,8 @@
         userId = "${userId!0}"
         uuUserId = "${userid!0}";
         $('.voted').attr("src","${CPATH}/static/jpress/admin/image/support.png");
+
+        initToast();
     });
 
     var scrollResultMessage = "初始化状态";
@@ -411,5 +426,53 @@
         });
     }
 
+    function doSubmit(){
+        var text = $('#textareaUas').val();
+        if (text != null && "" != text.trim(text)) {
+            $("#comment").ajaxSubmit({
+                type : "post",
+                dataType : "json",
+                success : function(data) {
+                    if(data.errorCode == 0){
+                        toastr.success('等待管理员审核!','留言成功');
+                        $('.footer-header').css('display','none');
+                    }else if(data.errorCode == 1){
+                        toastr.error('您已经留言,不能重复留言!','留言失败');
+                        $('.footer-header').css('display','none');
+                    }else{
+                        toastr.error(data.message,'留言失败');
+                    }
+                },
+                error : function() {
+                    toastr.error("留言提交失败,可能是网络错误或者服务器没有响应",'操作失败');
+                }
+            });
+        } else {
+            toastr.info('您输入的信息为空!');
+        }
+
+    }
+
+    function initToast(){
+        toastr.options = {
+            "closeButton": true,
+            "debug": false,
+            "newestOnTop": false,
+            "progressBar": true,
+            "positionClass": "toast-top-center",
+            "preventDuplicates": false,
+            "onclick": null,
+            "showDuration": "300",
+            "hideDuration": "1000",
+            "timeOut": "2000",
+            "extendedTimeOut": "1000",
+            "showEasing": "swing",
+            "hideEasing": "linear",
+            "showMethod": "fadeIn",
+            "hideMethod": "fadeOut"
+        }
+
+    }
+
 </script>
 </html>