From 2d531699d26ce46d4b13e71a9356f8828de9b24a Mon Sep 17 00:00:00 2001 From: jiekechoo Date: Thu, 27 Oct 2016 00:38:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E5=8A=9F=E8=83=BD=EF=BC=88253.com?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=87=8D=E7=BD=AE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 33 ++-- .../sectong/controller/NewsController.java | 4 + .../controller/ThirdPartyController.java | 69 ++++++++ .../sectong/controller/UserController.java | 92 ++++++++-- .../com/sectong/domain/ResetPasswordForm.java | 42 +++++ src/main/java/com/sectong/domain/Sms.java | 65 +++++++ .../com/sectong/domain/UserCreateForm.java | 11 ++ .../com/sectong/repository/SmsRepository.java | 11 ++ .../com/sectong/service/SendSMSService.java | 11 ++ .../sectong/service/SendSMSServiceImpl.java | 80 +++++++++ .../java/com/sectong/service/UserService.java | 3 + .../com/sectong/service/UserServiceImpl.java | 15 ++ .../java/com/sectong/thirdparty/README.md | 1 + .../com/sectong/thirdparty/sms/SendSMS.java | 61 +++++++ .../com/sectong/validator/ValidatorUtil.java | 167 ++++++++++++++++++ 15 files changed, 642 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/sectong/controller/ThirdPartyController.java create mode 100644 src/main/java/com/sectong/domain/ResetPasswordForm.java create mode 100644 src/main/java/com/sectong/domain/Sms.java create mode 100644 src/main/java/com/sectong/repository/SmsRepository.java create mode 100644 src/main/java/com/sectong/service/SendSMSService.java create mode 100644 src/main/java/com/sectong/service/SendSMSServiceImpl.java create mode 100644 src/main/java/com/sectong/thirdparty/README.md create mode 100644 src/main/java/com/sectong/thirdparty/sms/SendSMS.java create mode 100644 src/main/java/com/sectong/validator/ValidatorUtil.java diff --git a/pom.xml b/pom.xml index c3ce681..33d08ca 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.sectong yidongyi - 0.1.0-RELEASE + 0.2.0-SNAPSHOT jar yidongyi @@ -47,28 +47,35 @@ spring-boot-starter-thymeleaf - org.springframework - spring-jdbc - + org.springframework + spring-jdbc + - com.h2database - h2 - + com.h2database + h2 + - io.springfox - springfox-swagger2 - ${swagger.version} + io.springfox + springfox-swagger2 + ${swagger.version} - io.springfox - springfox-swagger-ui - ${swagger.version} + io.springfox + springfox-swagger-ui + ${swagger.version} org.springframework.boot spring-boot-starter-undertow + + + commons-httpclient + commons-httpclient + 3.1 + + -
- - -
- diff --git a/src/main/resources/templates/admin/content/thirdparty.html b/src/main/resources/templates/admin/content/thirdparty.html new file mode 100644 index 0000000..c756f42 --- /dev/null +++ b/src/main/resources/templates/admin/content/thirdparty.html @@ -0,0 +1,119 @@ + + + +header + + + +
+
+ + + + + + + +
+
+
+
+

+ 第三方配置 +

+
+
+ +
+
+
+
+
+
+ +
+ +
+
+
+ + 账号异常,请注册一个新账号。 +
+
+ + 账号增加正常。 +
+
+ + 请初始化短信平台账号。 +
+

+ 请输入创蓝·253短信平台用户名密码,如果还没有账号,请注册一个。 +

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+

I'm in Section 2.

+
+
+
+ +
+ +
+ +
+ +
+ +
+
+ + + +
+ + +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/admin/content/user.html b/src/main/resources/templates/admin/content/user.html index dfefc75..3ad70a8 100644 --- a/src/main/resources/templates/admin/content/user.html +++ b/src/main/resources/templates/admin/content/user.html @@ -9,45 +9,12 @@
- -
- - -
- diff --git a/src/main/resources/templates/admin/layouts/sidebar.html b/src/main/resources/templates/admin/layouts/sidebar.html index a822382..bde2bd8 100644 --- a/src/main/resources/templates/admin/layouts/sidebar.html +++ b/src/main/resources/templates/admin/layouts/sidebar.html @@ -33,6 +33,12 @@
  • 新闻管理
  • + +
  • 第三方配置 +
  • diff --git a/src/main/resources/templates/admin/thirdparty.html b/src/main/resources/templates/admin/thirdparty.html new file mode 100644 index 0000000..e35ed87 --- /dev/null +++ b/src/main/resources/templates/admin/thirdparty.html @@ -0,0 +1,14 @@ + + + + + +
    ...
    +
    +
    ...
    +
    ...
    +
    + + \ No newline at end of file -- Gitee From ff62c5bc9bc1d733d291588929829bfb0b5bad75 Mon Sep 17 00:00:00 2001 From: jiekechoo Date: Mon, 14 Nov 2016 23:26:23 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=AA=E6=8E=A8APP-PUS?= =?UTF-8?q?H=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=9C=A8=E7=BA=BF=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 13 ++ .../sectong/controller/AdminController.java | 66 ++++++- .../com/sectong/service/AppPushService.java | 11 ++ .../sectong/service/AppPushServiceImpl.java | 67 +++++++ .../com/sectong/thirdparty/push/AppPush.java | 43 ++++ .../sectong/thirdparty/push/AppPushTest.java | 48 +++++ .../com/sectong/thirdparty/sms/SendSMS.java | 17 +- src/main/resources/application.properties | 2 +- .../templates/admin/content/thirdparty.html | 185 +++++++++++++----- 9 files changed, 389 insertions(+), 63 deletions(-) create mode 100644 src/main/java/com/sectong/service/AppPushService.java create mode 100644 src/main/java/com/sectong/service/AppPushServiceImpl.java create mode 100644 src/main/java/com/sectong/thirdparty/push/AppPush.java create mode 100644 src/main/java/com/sectong/thirdparty/push/AppPushTest.java diff --git a/pom.xml b/pom.xml index eb9770c..82e78de 100644 --- a/pom.xml +++ b/pom.xml @@ -72,10 +72,23 @@ 3.1 + + + com.gexin.platform + gexin-rp-sdk-http + 4.0.1.2 + + + + + getui-nexus + http://mvn.gt.igexin.com/nexus/content/repositories/releases/ + + diff --git a/src/main/java/com/sectong/controller/AdminController.java b/src/main/java/com/sectong/controller/AdminController.java index 8ed6a6e..12100be 100644 --- a/src/main/java/com/sectong/controller/AdminController.java +++ b/src/main/java/com/sectong/controller/AdminController.java @@ -1,7 +1,10 @@ package com.sectong.controller; +import java.io.IOException; import java.util.Date; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; @@ -16,8 +19,10 @@ import com.sectong.domain.User; import com.sectong.repository.NewsRepository; import com.sectong.repository.ThirdpartyRepository; import com.sectong.repository.UserRepository; +import com.sectong.service.AppPushService; import com.sectong.service.SendSMSService; import com.sectong.service.UserService; +import com.sectong.thirdparty.push.AppPush; /** * 后台管理控制器 @@ -29,20 +34,24 @@ import com.sectong.service.UserService; @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminController { + private static final Logger LOGGER = LoggerFactory.getLogger(AdminController.class); + private UserRepository userRepository; private NewsRepository newsRepository; private UserService userService; private SendSMSService sendSMSService; private ThirdpartyRepository thirdpartyRepository; + private AppPushService appPushService;; @Autowired public AdminController(NewsRepository newsRepository, UserRepository userRepository, UserService userService, - SendSMSService sendSMSService, ThirdpartyRepository thirdpartyRepository) { + SendSMSService sendSMSService, ThirdpartyRepository thirdpartyRepository, AppPushService appPushService) { this.userRepository = userRepository; this.newsRepository = newsRepository; this.userService = userService; this.sendSMSService = sendSMSService; this.thirdpartyRepository = thirdpartyRepository; + this.appPushService = appPushService; } /** @@ -158,7 +167,7 @@ public class AdminController { @GetMapping("/admin/thirdparty") public String thirdparty(Model model) { model.addAttribute("thirdparty", true); - String smsUsername = null, smsPassword = null; + String smsUsername = null, smsPassword = null, pushAppID = null, pushAppKey = null, pushMasterSecret = null; try { smsUsername = thirdpartyRepository.findOne("smsUsername").getValue(); } catch (Exception e) { @@ -170,6 +179,24 @@ public class AdminController { // TODO: handle exception } + try { + pushAppID = thirdpartyRepository.findOne("pushAppID").getValue(); + } catch (Exception e) { + // TODO: handle exception + } + + try { + pushAppKey = thirdpartyRepository.findOne("pushAppKey").getValue(); + } catch (Exception e) { + // TODO: handle exception + } + + try { + pushMasterSecret = thirdpartyRepository.findOne("pushMasterSecret").getValue(); + } catch (Exception e) { + // TODO: handle exception + } + if (!sendSMSService.checkSmsAccountStatus(smsUsername, smsPassword)) { model.addAttribute("error", true);// 状态不正常 } @@ -177,8 +204,15 @@ public class AdminController { model.addAttribute("init", true);// 第一次初始化 model.addAttribute("error", false); } + + if (pushAppID == null && pushAppKey == null && pushMasterSecret == null) { + model.addAttribute("initpush", true);// 第一次初始化 + } model.addAttribute("smsUsername", smsUsername); model.addAttribute("smsPassword", smsPassword); + model.addAttribute("pushAppID", pushAppID); + model.addAttribute("pushAppKey", pushAppKey); + model.addAttribute("pushMasterSecret", pushMasterSecret); return "admin/thirdparty"; } @@ -199,4 +233,32 @@ public class AdminController { } } + + /** + * 提交推送平台信息 + * + * @param appID + * @param appKey + * @param masterSecret + * @return + */ + @PostMapping("/admin/thirdpartypush") + public String thirdPartyPush(@RequestParam String pushAppID, @RequestParam String pushAppKey, + @RequestParam String pushMasterSecret) { + appPushService.savePushConfig(pushAppID, pushAppKey, pushMasterSecret); + + return "redirect:/admin/thirdparty?pok#push"; + } + + @PostMapping("/admin/thirdpartypushtest") + public String thirdPartyPushTest(@RequestParam String title, @RequestParam String text, + @RequestParam String openUrl) throws IOException { + if (appPushService.sendPushMsg(title, text, openUrl)) { + return "redirect:/admin/thirdparty?testok#push"; + }else { + return "redirect:/admin/thirdparty?testerror#push"; + } + + + } } diff --git a/src/main/java/com/sectong/service/AppPushService.java b/src/main/java/com/sectong/service/AppPushService.java new file mode 100644 index 0000000..c56d844 --- /dev/null +++ b/src/main/java/com/sectong/service/AppPushService.java @@ -0,0 +1,11 @@ +package com.sectong.service; + +import java.io.IOException; + +public interface AppPushService { + + void savePushConfig(String appID, String appKey, String masterSecret); + + Boolean sendPushMsg(String title, String text, String openUrl) throws IOException; + +} diff --git a/src/main/java/com/sectong/service/AppPushServiceImpl.java b/src/main/java/com/sectong/service/AppPushServiceImpl.java new file mode 100644 index 0000000..f9cb550 --- /dev/null +++ b/src/main/java/com/sectong/service/AppPushServiceImpl.java @@ -0,0 +1,67 @@ +package com.sectong.service; + +import java.io.IOException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.sectong.domain.ThirdParty; +import com.sectong.repository.ThirdpartyRepository; +import com.sectong.thirdparty.push.AppPush; + +@Service +public class AppPushServiceImpl implements AppPushService { + + private static final Logger LOGGER = LoggerFactory.getLogger(AppPushServiceImpl.class); + + private ThirdpartyRepository thirdpartyRepository; + + @Autowired + public AppPushServiceImpl(ThirdpartyRepository thirdpartyRepository) { + this.thirdpartyRepository = thirdpartyRepository; + } + + @Override + public void savePushConfig(String appID, String appKey, String masterSecret) { + ThirdParty thirdParty = new ThirdParty(); + thirdParty.createConfig("pushAppID", appID); + thirdpartyRepository.save(thirdParty); + thirdParty.createConfig("pushAppKey", appKey); + thirdpartyRepository.save(thirdParty); + thirdParty.createConfig("pushMasterSecret", masterSecret); + thirdpartyRepository.save(thirdParty); + + } + + /** + * 发送测试推送信息 + * + * @param title + * @param text + * @param openUrl + * @return + * @throws IOException + */ + @Override + public Boolean sendPushMsg(String title, String text, String openUrl) throws IOException { + + Boolean ret = false; + + String pushAppID = null, pushAppKey = null, pushMasterSecret = null; + try { + pushAppID = thirdpartyRepository.findOne("pushAppID").getValue(); + pushAppKey = thirdpartyRepository.findOne("pushAppKey").getValue(); + pushMasterSecret = thirdpartyRepository.findOne("pushMasterSecret").getValue(); + ret = true; + LOGGER.info("appID: {}, appKey: {}, masterSecret: {}", pushAppID, pushAppKey, pushMasterSecret); + AppPush.SendAppPush(pushAppID, pushAppKey, pushMasterSecret, title, text, openUrl); + ret = true; + } catch (Exception e) { + ret = false; + } + return ret; + } + +} diff --git a/src/main/java/com/sectong/thirdparty/push/AppPush.java b/src/main/java/com/sectong/thirdparty/push/AppPush.java new file mode 100644 index 0000000..22266c5 --- /dev/null +++ b/src/main/java/com/sectong/thirdparty/push/AppPush.java @@ -0,0 +1,43 @@ +package com.sectong.thirdparty.push; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.gexin.rp.sdk.base.IPushResult; +import com.gexin.rp.sdk.base.impl.AppMessage; +import com.gexin.rp.sdk.http.IGtPush; +import com.gexin.rp.sdk.template.LinkTemplate; + +public class AppPush { + + private static String url = "http://sdk.open.api.igexin.com/apiex.htm";// 推送服务器地址 + + public static void SendAppPush(String appId, String appKey, String masterSecret, String title, String text, + String openUrl) throws IOException { + + IGtPush push = new IGtPush(url, appKey, masterSecret); + push.connect(); + + // 定义"点击链接打开通知模板",并设置标题、内容、链接 + LinkTemplate template = new LinkTemplate(); + template.setAppId(appId); + template.setAppkey(appKey); + template.setTitle(title); + template.setText(text); + template.setUrl(openUrl); + + List appIds = new ArrayList(); + appIds.add(appId); + + // 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒) + AppMessage message = new AppMessage(); + message.setData(template); + message.setAppIdList(appIds); + message.setOffline(true); + message.setOfflineExpireTime(1000 * 600); + + IPushResult ret = push.pushMessageToApp(message); + System.out.println(ret.getResponse().toString()); + } +} diff --git a/src/main/java/com/sectong/thirdparty/push/AppPushTest.java b/src/main/java/com/sectong/thirdparty/push/AppPushTest.java new file mode 100644 index 0000000..c82fdfc --- /dev/null +++ b/src/main/java/com/sectong/thirdparty/push/AppPushTest.java @@ -0,0 +1,48 @@ +package com.sectong.thirdparty.push; + + +import com.gexin.rp.sdk.base.IPushResult; +import com.gexin.rp.sdk.base.impl.AppMessage; +import com.gexin.rp.sdk.http.IGtPush; +import com.gexin.rp.sdk.template.LinkTemplate; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + + +public class AppPushTest { + + //定义常量, appId、appKey、masterSecret 采用本文档 "第二步 获取访问凭证 "中获得的应用配置 + private static String appId = "1dEURGOBQc9qLn423WOXL"; + private static String appKey = "nYFEUxlXL7AmWCm1UvqOs"; + private static String masterSecret = "DzJsgmcj1wArGiaY4Ntob7"; + private static String url = "http://sdk.open.api.igexin.com/apiex.htm"; + + public static void main(String[] args) throws IOException { + + IGtPush push = new IGtPush(url, appKey, masterSecret); + push.connect(); + + // 定义"点击链接打开通知模板",并设置标题、内容、链接 + LinkTemplate template = new LinkTemplate(); + template.setAppId(appId); + template.setAppkey(appKey); + template.setTitle("欢迎使用移动易!"); + template.setText("这是一条测试推送消息"); + template.setUrl("http://www.mobileeasy.cc"); + + List appIds = new ArrayList(); + appIds.add(appId); + + // 定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒) + AppMessage message = new AppMessage(); + message.setData(template); + message.setAppIdList(appIds); + message.setOffline(true); + message.setOfflineExpireTime(1000 * 600); + + IPushResult ret = push.pushMessageToApp(message); + System.out.println(ret.getResponse().toString()); + } +} \ No newline at end of file diff --git a/src/main/java/com/sectong/thirdparty/sms/SendSMS.java b/src/main/java/com/sectong/thirdparty/sms/SendSMS.java index eae6401..7ebd517 100644 --- a/src/main/java/com/sectong/thirdparty/sms/SendSMS.java +++ b/src/main/java/com/sectong/thirdparty/sms/SendSMS.java @@ -13,21 +13,10 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpClientParams; /** + * 短信平台 * - * @param url - * 应用地址,类似于http://ip:port/msg/ - * @param account - * 账号 - * @param pswd - * 密码 - * @param mobile - * 手机号码,多个号码使用","分割 - * @param msg - * 短信内容 - * @param needstatus - * 是否需要状态报告,需要true,不需要false - * @return 返回值定义参见HTTP协议文档 - * @throws Exception + * @author jiekechoo + * */ public class SendSMS { /** diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4071d28..0950ebb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,7 +4,7 @@ spring.datasource.test-on-borrow=true #日志文件设置 logging.level.*=DEBUG -logging.file=/logs/server.log +logging.file=/tmp/logs/server.log image.file.upload.dir=static/upload/ diff --git a/src/main/resources/templates/admin/content/thirdparty.html b/src/main/resources/templates/admin/content/thirdparty.html index c756f42..cb80cf4 100644 --- a/src/main/resources/templates/admin/content/thirdparty.html +++ b/src/main/resources/templates/admin/content/thirdparty.html @@ -37,62 +37,155 @@
    -
    +
    -
    -
    - - 账号异常,请注册一个新账号。 -
    -
    - - 账号增加正常。 -
    -
    - - 请初始化短信平台账号。 -
    -

    - 请输入创蓝·253短信平台用户名密码,如果还没有账号,请注册一个。 -

    -
    -
    - -
    - + +
    +
    +
    + + 账号异常,请注册一个新账号。 +
    +
    + + 账号增加正常。 +
    +
    + + 请初始化短信平台账号。 +
    +

    + 请输入创蓝·253短信平台用户名密码,如果还没有账号,请注册一个。 +

    + +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    +
    + +
    +
    +
    + + 推送账号增加正常。
    -
    - -
    - +
    + + 请初始化推送平台账号。 +
    +

    请输入个推平台信息,如果还没有账号,请注册一个。

    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    + +
    +
    +
    + +
    +
    + + 推送测试发送成功。
    -
    - +
    + + 推送测试发送失败。
    - -
    -
    -

    I'm in Section 2.

    +

    测试推送

    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    +
    -- Gitee From 3a5dfcae4c0b4857350a5f56e6a008ec5c09a9a2 Mon Sep 17 00:00:00 2001 From: jiekechoo Date: Sat, 19 Nov 2016 10:58:55 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Controller=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sectong/controller/AdminController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sectong/controller/AdminController.java b/src/main/java/com/sectong/controller/AdminController.java index 12100be..49a022e 100644 --- a/src/main/java/com/sectong/controller/AdminController.java +++ b/src/main/java/com/sectong/controller/AdminController.java @@ -22,7 +22,6 @@ import com.sectong.repository.UserRepository; import com.sectong.service.AppPushService; import com.sectong.service.SendSMSService; import com.sectong.service.UserService; -import com.sectong.thirdparty.push.AppPush; /** * 后台管理控制器 @@ -65,6 +64,7 @@ public class AdminController { model.addAttribute("dashboard", true); model.addAttribute("userscount", userRepository.count()); model.addAttribute("newscount", newsRepository.count()); + LOGGER.info("access admin /"); return "admin/index"; } -- Gitee From 90c78dc3cd412b8cbaa791c238f07ad61a2cbb6a Mon Sep 17 00:00:00 2001 From: jiekechoo Date: Sat, 19 Nov 2016 11:01:10 +0800 Subject: [PATCH 6/6] v0.2.0 release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 82e78de..b7f2883 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.sectong yidongyi - 0.2.0-SNAPSHOT + 0.2.0 jar yidongyi -- Gitee