张延森 il y a 4 ans
révision
92125154d9

+ 27
- 0
.gitignore Voir le fichier

@@ -0,0 +1,27 @@
1
+/target/
2
+!.mvn/wrapper/maven-wrapper.jar
3
+
4
+### STS ###
5
+.apt_generated
6
+.classpath
7
+.factorypath
8
+.project
9
+.settings
10
+.springBeans
11
+.sts4-cache
12
+
13
+### IntelliJ IDEA ###
14
+.idea
15
+*.iws
16
+*.iml
17
+*.ipr
18
+
19
+.mvn
20
+
21
+### NetBeans ###
22
+/nbproject/private/
23
+/build/
24
+/nbbuild/
25
+/dist/
26
+/nbdist/
27
+/.nb-gradle/

+ 225
- 0
mvnw Voir le fichier

@@ -0,0 +1,225 @@
1
+#!/bin/sh
2
+# ----------------------------------------------------------------------------
3
+# Licensed to the Apache Software Foundation (ASF) under one
4
+# or more contributor license agreements.  See the NOTICE file
5
+# distributed with this work for additional information
6
+# regarding copyright ownership.  The ASF licenses this file
7
+# to you under the Apache License, Version 2.0 (the
8
+# "License"); you may not use this file except in compliance
9
+# with the License.  You may obtain a copy of the License at
10
+#
11
+#    http://www.apache.org/licenses/LICENSE-2.0
12
+#
13
+# Unless required by applicable law or agreed to in writing,
14
+# software distributed under the License is distributed on an
15
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+# KIND, either express or implied.  See the License for the
17
+# specific language governing permissions and limitations
18
+# under the License.
19
+# ----------------------------------------------------------------------------
20
+
21
+# ----------------------------------------------------------------------------
22
+# Maven2 Start Up Batch script
23
+#
24
+# Required ENV vars:
25
+# ------------------
26
+#   JAVA_HOME - location of a JDK home dir
27
+#
28
+# Optional ENV vars
29
+# -----------------
30
+#   M2_HOME - location of maven2's installed home dir
31
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
32
+#     e.g. to debug Maven itself, use
33
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35
+# ----------------------------------------------------------------------------
36
+
37
+if [ -z "$MAVEN_SKIP_RC" ] ; then
38
+
39
+  if [ -f /etc/mavenrc ] ; then
40
+    . /etc/mavenrc
41
+  fi
42
+
43
+  if [ -f "$HOME/.mavenrc" ] ; then
44
+    . "$HOME/.mavenrc"
45
+  fi
46
+
47
+fi
48
+
49
+# OS specific support.  $var _must_ be set to either true or false.
50
+cygwin=false;
51
+darwin=false;
52
+mingw=false
53
+case "`uname`" in
54
+  CYGWIN*) cygwin=true ;;
55
+  MINGW*) mingw=true;;
56
+  Darwin*) darwin=true
57
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59
+    if [ -z "$JAVA_HOME" ]; then
60
+      if [ -x "/usr/libexec/java_home" ]; then
61
+        export JAVA_HOME="`/usr/libexec/java_home`"
62
+      else
63
+        export JAVA_HOME="/Library/Java/Home"
64
+      fi
65
+    fi
66
+    ;;
67
+esac
68
+
69
+if [ -z "$JAVA_HOME" ] ; then
70
+  if [ -r /etc/gentoo-release ] ; then
71
+    JAVA_HOME=`java-config --jre-home`
72
+  fi
73
+fi
74
+
75
+if [ -z "$M2_HOME" ] ; then
76
+  ## resolve links - $0 may be a link to maven's home
77
+  PRG="$0"
78
+
79
+  # need this for relative symlinks
80
+  while [ -h "$PRG" ] ; do
81
+    ls=`ls -ld "$PRG"`
82
+    link=`expr "$ls" : '.*-> \(.*\)$'`
83
+    if expr "$link" : '/.*' > /dev/null; then
84
+      PRG="$link"
85
+    else
86
+      PRG="`dirname "$PRG"`/$link"
87
+    fi
88
+  done
89
+
90
+  saveddir=`pwd`
91
+
92
+  M2_HOME=`dirname "$PRG"`/..
93
+
94
+  # make it fully qualified
95
+  M2_HOME=`cd "$M2_HOME" && pwd`
96
+
97
+  cd "$saveddir"
98
+  # echo Using m2 at $M2_HOME
99
+fi
100
+
101
+# For Cygwin, ensure paths are in UNIX format before anything is touched
102
+if $cygwin ; then
103
+  [ -n "$M2_HOME" ] &&
104
+    M2_HOME=`cygpath --unix "$M2_HOME"`
105
+  [ -n "$JAVA_HOME" ] &&
106
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107
+  [ -n "$CLASSPATH" ] &&
108
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109
+fi
110
+
111
+# For Migwn, ensure paths are in UNIX format before anything is touched
112
+if $mingw ; then
113
+  [ -n "$M2_HOME" ] &&
114
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
115
+  [ -n "$JAVA_HOME" ] &&
116
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117
+  # TODO classpath?
118
+fi
119
+
120
+if [ -z "$JAVA_HOME" ]; then
121
+  javaExecutable="`which javac`"
122
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123
+    # readlink(1) is not available as standard on Solaris 10.
124
+    readLink=`which readlink`
125
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126
+      if $darwin ; then
127
+        javaHome="`dirname \"$javaExecutable\"`"
128
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129
+      else
130
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
131
+      fi
132
+      javaHome="`dirname \"$javaExecutable\"`"
133
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134
+      JAVA_HOME="$javaHome"
135
+      export JAVA_HOME
136
+    fi
137
+  fi
138
+fi
139
+
140
+if [ -z "$JAVACMD" ] ; then
141
+  if [ -n "$JAVA_HOME"  ] ; then
142
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143
+      # IBM's JDK on AIX uses strange locations for the executables
144
+      JAVACMD="$JAVA_HOME/jre/sh/java"
145
+    else
146
+      JAVACMD="$JAVA_HOME/bin/java"
147
+    fi
148
+  else
149
+    JAVACMD="`which java`"
150
+  fi
151
+fi
152
+
153
+if [ ! -x "$JAVACMD" ] ; then
154
+  echo "Error: JAVA_HOME is not defined correctly." >&2
155
+  echo "  We cannot execute $JAVACMD" >&2
156
+  exit 1
157
+fi
158
+
159
+if [ -z "$JAVA_HOME" ] ; then
160
+  echo "Warning: JAVA_HOME environment variable is not set."
161
+fi
162
+
163
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164
+
165
+# traverses directory structure from process work directory to filesystem root
166
+# first directory with .mvn subdirectory is considered project base directory
167
+find_maven_basedir() {
168
+
169
+  if [ -z "$1" ]
170
+  then
171
+    echo "Path not specified to find_maven_basedir"
172
+    return 1
173
+  fi
174
+
175
+  basedir="$1"
176
+  wdir="$1"
177
+  while [ "$wdir" != '/' ] ; do
178
+    if [ -d "$wdir"/.mvn ] ; then
179
+      basedir=$wdir
180
+      break
181
+    fi
182
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183
+    if [ -d "${wdir}" ]; then
184
+      wdir=`cd "$wdir/.."; pwd`
185
+    fi
186
+    # end of workaround
187
+  done
188
+  echo "${basedir}"
189
+}
190
+
191
+# concatenates all lines of a file
192
+concat_lines() {
193
+  if [ -f "$1" ]; then
194
+    echo "$(tr -s '\n' ' ' < "$1")"
195
+  fi
196
+}
197
+
198
+BASE_DIR=`find_maven_basedir "$(pwd)"`
199
+if [ -z "$BASE_DIR" ]; then
200
+  exit 1;
201
+fi
202
+
203
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204
+echo $MAVEN_PROJECTBASEDIR
205
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206
+
207
+# For Cygwin, switch paths to Windows format before running java
208
+if $cygwin; then
209
+  [ -n "$M2_HOME" ] &&
210
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
211
+  [ -n "$JAVA_HOME" ] &&
212
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213
+  [ -n "$CLASSPATH" ] &&
214
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217
+fi
218
+
219
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220
+
221
+exec "$JAVACMD" \
222
+  $MAVEN_OPTS \
223
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 143
- 0
mvnw.cmd Voir le fichier

@@ -0,0 +1,143 @@
1
+@REM ----------------------------------------------------------------------------
2
+@REM Licensed to the Apache Software Foundation (ASF) under one
3
+@REM or more contributor license agreements.  See the NOTICE file
4
+@REM distributed with this work for additional information
5
+@REM regarding copyright ownership.  The ASF licenses this file
6
+@REM to you under the Apache License, Version 2.0 (the
7
+@REM "License"); you may not use this file except in compliance
8
+@REM with the License.  You may obtain a copy of the License at
9
+@REM
10
+@REM    http://www.apache.org/licenses/LICENSE-2.0
11
+@REM
12
+@REM Unless required by applicable law or agreed to in writing,
13
+@REM software distributed under the License is distributed on an
14
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+@REM KIND, either express or implied.  See the License for the
16
+@REM specific language governing permissions and limitations
17
+@REM under the License.
18
+@REM ----------------------------------------------------------------------------
19
+
20
+@REM ----------------------------------------------------------------------------
21
+@REM Maven2 Start Up Batch script
22
+@REM
23
+@REM Required ENV vars:
24
+@REM JAVA_HOME - location of a JDK home dir
25
+@REM
26
+@REM Optional ENV vars
27
+@REM M2_HOME - location of maven2's installed home dir
28
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31
+@REM     e.g. to debug Maven itself, use
32
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34
+@REM ----------------------------------------------------------------------------
35
+
36
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37
+@echo off
38
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
40
+
41
+@REM set %HOME% to equivalent of $HOME
42
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43
+
44
+@REM Execute a user defined script before this one
45
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
47
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49
+:skipRcPre
50
+
51
+@setlocal
52
+
53
+set ERROR_CODE=0
54
+
55
+@REM To isolate internal variables from possible post scripts, we use another setlocal
56
+@setlocal
57
+
58
+@REM ==== START VALIDATION ====
59
+if not "%JAVA_HOME%" == "" goto OkJHome
60
+
61
+echo.
62
+echo Error: JAVA_HOME not found in your environment. >&2
63
+echo Please set the JAVA_HOME variable in your environment to match the >&2
64
+echo location of your Java installation. >&2
65
+echo.
66
+goto error
67
+
68
+:OkJHome
69
+if exist "%JAVA_HOME%\bin\java.exe" goto init
70
+
71
+echo.
72
+echo Error: JAVA_HOME is set to an invalid directory. >&2
73
+echo JAVA_HOME = "%JAVA_HOME%" >&2
74
+echo Please set the JAVA_HOME variable in your environment to match the >&2
75
+echo location of your Java installation. >&2
76
+echo.
77
+goto error
78
+
79
+@REM ==== END VALIDATION ====
80
+
81
+:init
82
+
83
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84
+@REM Fallback to current working directory if not found.
85
+
86
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88
+
89
+set EXEC_DIR=%CD%
90
+set WDIR=%EXEC_DIR%
91
+:findBaseDir
92
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
93
+cd ..
94
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
95
+set WDIR=%CD%
96
+goto findBaseDir
97
+
98
+:baseDirFound
99
+set MAVEN_PROJECTBASEDIR=%WDIR%
100
+cd "%EXEC_DIR%"
101
+goto endDetectBaseDir
102
+
103
+:baseDirNotFound
104
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105
+cd "%EXEC_DIR%"
106
+
107
+:endDetectBaseDir
108
+
109
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110
+
111
+@setlocal EnableExtensions EnableDelayedExpansion
112
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114
+
115
+:endReadAdditionalConfig
116
+
117
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118
+
119
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121
+
122
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123
+if ERRORLEVEL 1 goto error
124
+goto end
125
+
126
+:error
127
+set ERROR_CODE=1
128
+
129
+:end
130
+@endlocal & set ERROR_CODE=%ERROR_CODE%
131
+
132
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
134
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136
+:skipRcPost
137
+
138
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
140
+
141
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142
+
143
+exit /B %ERROR_CODE%

+ 84
- 0
pom.xml Voir le fichier

@@ -0,0 +1,84 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+
6
+	<groupId>com.example</groupId>
7
+	<artifactId>huiju_sms</artifactId>
8
+	<version>0.0.1-SNAPSHOT</version>
9
+	<packaging>jar</packaging>
10
+
11
+	<name>huiju_sms</name>
12
+	<description>huiju_sms project for Spring Boot</description>
13
+
14
+	<parent>
15
+		<groupId>org.springframework.boot</groupId>
16
+		<artifactId>spring-boot-starter-parent</artifactId>
17
+		<version>2.0.4.RELEASE</version>
18
+		<relativePath/> <!-- lookup parent from repository -->
19
+	</parent>
20
+
21
+	<properties>
22
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+		<java.version>1.8</java.version>
25
+	</properties>
26
+
27
+	<dependencies>
28
+		<dependency>
29
+			<groupId>org.springframework.boot</groupId>
30
+			<artifactId>spring-boot-starter-web</artifactId>
31
+		</dependency>
32
+
33
+		<dependency>
34
+			<groupId>org.springframework.boot</groupId>
35
+			<artifactId>spring-boot-starter-test</artifactId>
36
+			<scope>test</scope>
37
+		</dependency>
38
+
39
+		<dependency>
40
+			<groupId>org.mybatis.spring.boot</groupId>
41
+			<artifactId>mybatis-spring-boot-starter</artifactId>
42
+			<version>1.3.2</version>
43
+		</dependency>
44
+
45
+		<dependency>
46
+			<groupId>mysql</groupId>
47
+			<artifactId>mysql-connector-java</artifactId>
48
+			<scope>runtime</scope>
49
+		</dependency>
50
+		<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
51
+		<dependency>
52
+			<groupId>com.alibaba</groupId>
53
+			<artifactId>fastjson</artifactId>
54
+			<version>1.2.47</version>
55
+		</dependency>
56
+		<dependency>
57
+			<groupId>commons-httpclient</groupId>
58
+			<artifactId>commons-httpclient</artifactId>
59
+			<version>3.1</version>
60
+		</dependency>
61
+
62
+		<dependency>
63
+			<groupId>commons-codec</groupId>
64
+			<artifactId>commons-codec</artifactId>
65
+			<version>1.10</version><!--$NO-MVN-MAN-VER$-->
66
+		</dependency>
67
+		<dependency>
68
+			<groupId>net.onebean</groupId>
69
+			<artifactId>net.onebean.aliyun.sms</artifactId>
70
+			<version>1.1.0.3.RELEASE</version>
71
+		</dependency>
72
+	</dependencies>
73
+
74
+	<build>
75
+		<plugins>
76
+			<plugin>
77
+				<groupId>org.springframework.boot</groupId>
78
+				<artifactId>spring-boot-maven-plugin</artifactId>
79
+			</plugin>
80
+		</plugins>
81
+	</build>
82
+
83
+
84
+</project>

+ 12
- 0
src/main/java/com/example/sms/SmsApplication.java Voir le fichier

@@ -0,0 +1,12 @@
1
+package com.example.sms;
2
+
3
+import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+
6
+@SpringBootApplication
7
+public class SmsApplication {
8
+
9
+	public static void main(String[] args) {
10
+		SpringApplication.run(SmsApplication.class, args);
11
+	}
12
+}

+ 276
- 0
src/main/java/com/example/sms/common/DingdongCloudApis.java Voir le fichier

@@ -0,0 +1,276 @@
1
+package com.example.sms.common;
2
+
3
+import org.apache.commons.httpclient.HttpClient;
4
+import org.apache.commons.httpclient.NameValuePair;
5
+import org.apache.commons.httpclient.methods.PostMethod;
6
+import org.springframework.util.StringUtils;
7
+
8
+import java.io.IOException;
9
+import java.io.UnsupportedEncodingException;
10
+import java.net.URISyntaxException;
11
+import java.net.URLEncoder;
12
+
13
+public class DingdongCloudApis {
14
+
15
+    // 查账户信息的http地址
16
+    private static String URL_GET_USER_INFO = "https://api.dingdongcloud.com/v1/sms/userinfo";
17
+
18
+    // 查询账户余额的http地址
19
+    private static String URL_GET_BALANCE = "https://api.dingdongcloud.com/v1/sms/querybalance";
20
+
21
+    // 验证码短信发送接口的http地址
22
+    private static String URL_SEND_YZM = "https://api.dingdongcloud.com/v1/sms/sendyzm";
23
+
24
+    private static String URL_SEND_YYYZM = "https://api.dingdongcloud.com/v1/sms/sendyyyzm";
25
+
26
+    // 通知短信发送接口的http地址
27
+    private static String URL_SEND_TZ = "https://api.dingdongcloud.com/v1/sms/sendtz";
28
+
29
+    // 营销短信发送接口的http地址
30
+    private static String URL_SEND_YX = "https://api.dingdongcloud.com/v1/sms/sendyx";
31
+
32
+    // 模板获取
33
+    private static String URL_GET_TPL = "https://api.dingdongcloud.com/v1/template/get";
34
+
35
+    // 模板添加
36
+    private static String URL_ADD_TPL = "https://api.dingdongcloud.com/v1/template/add";
37
+
38
+    // 获取营销短信审核状态
39
+    private static String URL_VERIFY_STATUS_YX = "https://api.dingdongcloud.com/v1/verify/add";
40
+
41
+    // 编码格式。发送编码格式统一用UTF-8
42
+    private static String ENCODING = "UTF-8";
43
+
44
+    /**
45
+     * 查询账户信息接口
46
+     *
47
+     * @param apikey
48
+     * @return
49
+     */
50
+    public static String getUserInfo(String apikey)
51
+    {
52
+
53
+        NameValuePair[] data = {new NameValuePair("apikey", apikey)};
54
+        return doPost(URL_GET_USER_INFO, data);
55
+    }
56
+
57
+    /**
58
+     * 查询账户余额接口
59
+     *
60
+     * @param apikey
61
+     * @return
62
+     */
63
+    public static String getBalance(String apikey)
64
+    {
65
+
66
+        NameValuePair[] data = {new NameValuePair("apikey", apikey)};
67
+        return doPost(URL_GET_BALANCE, data);
68
+    }
69
+
70
+    /**
71
+     * 发送验证码短信
72
+     *
73
+     * @param apikey
74
+     *            apikey
75
+     * @param mobile
76
+     *            手机号码(唯一,不许多个)
77
+     * @param content
78
+     *            短信发送内容(必须经过utf-8格式编码)
79
+     * @return json格式字符串
80
+     */
81
+    public static String sendYzm(String apikey, String mobile, String content)
82
+    {
83
+
84
+        if (!StringUtils.isEmpty(content))
85
+        {
86
+            try
87
+            {
88
+                content = URLEncoder.encode(content, ENCODING);
89
+            }
90
+            catch (UnsupportedEncodingException e)
91
+            {
92
+                e.printStackTrace();
93
+            }
94
+        }
95
+
96
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
97
+
98
+                new NameValuePair("mobile", mobile),
99
+
100
+                new NameValuePair("content", content)};
101
+
102
+        return doPost(URL_SEND_YZM, data);
103
+    }
104
+
105
+    /**
106
+     * 发送语音验证码
107
+     *
108
+     * @param apikey
109
+     * @param mobile
110
+     *            手机号码(唯一,不许多个)
111
+     * @param content
112
+     *            短信发送内容(必须纯数字4-6位)
113
+     * @return
114
+     */
115
+    public static String sendYyYzm(String apikey, String mobile, String content)
116
+    {
117
+
118
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
119
+
120
+                new NameValuePair("mobile", mobile),
121
+
122
+                new NameValuePair("content", content)};
123
+
124
+        return doPost(URL_SEND_YYYZM, data);
125
+    }
126
+
127
+    /**
128
+     * 发送通知短信
129
+     *
130
+     * @param apikey
131
+     *            apikey
132
+     * @param mobile
133
+     *            手机号码(多个号码用英文半角逗号分开,最多可提交1000个)
134
+     * @param content
135
+     *            短信发送内容(必须经过utf-8格式编码)
136
+     * @return json格式字符串
137
+     */
138
+    public static String sendTz(String apikey, String mobile, String content)
139
+    {
140
+
141
+        if (!StringUtils.isEmpty(content))
142
+        {
143
+            try
144
+            {
145
+                content = URLEncoder.encode(content, ENCODING);
146
+            }
147
+            catch (UnsupportedEncodingException e)
148
+            {
149
+                e.printStackTrace();
150
+            }
151
+        }
152
+
153
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
154
+
155
+                new NameValuePair("mobile", mobile),
156
+
157
+                new NameValuePair("content", content)};
158
+
159
+        return doPost(URL_SEND_TZ, data);
160
+    }
161
+
162
+    /**
163
+     * 发送营销短信
164
+     *
165
+     * @param apikey
166
+     *            apikey
167
+     * @param mobile
168
+     *            手机号码(多个号码用英文半角逗号分开,最多可提交1000个)
169
+     * @param content
170
+     *            短信发送内容(必须经过utf-8格式编码,短信末尾必须带有“退订回T”)
171
+     * @return json格式字符串
172
+     */
173
+    public static String sendYx(String apikey, String mobile, String content)
174
+    {
175
+
176
+        if (!StringUtils.isEmpty(content))
177
+        {
178
+            try
179
+            {
180
+                content = URLEncoder.encode(content, ENCODING);
181
+            }
182
+            catch (UnsupportedEncodingException e)
183
+            {
184
+                e.printStackTrace();
185
+            }
186
+        }
187
+
188
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
189
+
190
+                new NameValuePair("mobile", mobile),
191
+
192
+                new NameValuePair("content", content)};
193
+
194
+        return doPost(URL_SEND_YX, data);
195
+    }
196
+
197
+    /**
198
+     * 获取营销短信审核状态
199
+     * @param apikey
200
+     * @param ser_no
201
+     *              短信批次号
202
+     * @return
203
+     */
204
+    public static String getYxStatus(String apikey, String ser_no)
205
+    {
206
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
207
+                new NameValuePair("ser_no", ser_no),};
208
+        return doPost(URL_VERIFY_STATUS_YX, data);
209
+    }
210
+
211
+    /**
212
+     * 获取模板
213
+     * @param apikey
214
+     * @param tpl_id
215
+     *              模板ID
216
+     * @param type
217
+     *              模板类型
218
+     * @return
219
+     */
220
+    public static String getTpl(String apikey, String tpl_id, String type)
221
+    {
222
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
223
+                new NameValuePair("tpl_id", tpl_id), new NameValuePair("type", type)};
224
+        return doPost(URL_GET_TPL, data);
225
+
226
+    }
227
+
228
+    /**
229
+     * 模板添加
230
+     * @param apikey
231
+     * @param tplContent
232
+     *              模板内容
233
+     * @param type
234
+     *              模板类型
235
+     * @return
236
+     */
237
+    public static String addTpl(String apikey, String tplContent, String type)
238
+    {
239
+
240
+        NameValuePair[] data = {new NameValuePair("apikey", apikey),
241
+                new NameValuePair("content", tplContent), new NameValuePair("type", type)};
242
+        return doPost(URL_ADD_TPL, data);
243
+    }
244
+
245
+    /**
246
+     * 基于HttpClient的post函数
247
+     *
248
+     * @param url
249
+     *            提交的URL
250
+     *
251
+     * @param data
252
+     *            提交NameValuePair参数
253
+     * @return 提交响应
254
+     */
255
+    private static String doPost(String url, NameValuePair[] data)
256
+    {
257
+
258
+        HttpClient client = new HttpClient();
259
+        PostMethod method = new PostMethod(url);
260
+        // method.setRequestHeader("ContentType",
261
+        // "application/x-www-form-urlencoded;charset=UTF-8");
262
+        method.setRequestBody(data);
263
+        // client.getParams().setContentCharset("UTF-8");
264
+        client.getParams().setConnectionManagerTimeout(10000);
265
+        try
266
+        {
267
+            client.executeMethod(method);
268
+            return method.getResponseBodyAsString();
269
+        }
270
+        catch (Exception e)
271
+        {
272
+            e.printStackTrace();
273
+        }
274
+        return null;
275
+    }
276
+}

+ 6
- 0
src/main/java/com/example/sms/common/SmsConst.java Voir le fichier

@@ -0,0 +1,6 @@
1
+package com.example.sms.common;
2
+
3
+public class SmsConst {
4
+    public static final String CODE_NOT_FOUND = "不存在的code";
5
+    public static final String SUCCESS = "发送成功";
6
+}

+ 46
- 0
src/main/java/com/example/sms/common/SmsParams.java Voir le fichier

@@ -0,0 +1,46 @@
1
+package com.example.sms.common;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
6
+public class SmsParams {
7
+    /**
8
+     * 业务CODE值
9
+     */
10
+    private String code;
11
+
12
+    /**
13
+     * 电话号码
14
+     */
15
+    private String tel;
16
+
17
+    /**
18
+     * 需要传递的参数值数组类型
19
+     */
20
+    private List<String> params = new ArrayList<String>();
21
+
22
+
23
+    public String getCode() {
24
+        return code;
25
+    }
26
+
27
+    public void setCode(String code) {
28
+        this.code = code;
29
+    }
30
+
31
+    public String getTel() {
32
+        return tel;
33
+    }
34
+
35
+    public void setTel(String tel) {
36
+        this.tel = tel;
37
+    }
38
+
39
+    public List<String> getParams() {
40
+        return params;
41
+    }
42
+
43
+    public void setParams(List<String> params) {
44
+        this.params = params;
45
+    }
46
+}

+ 28
- 0
src/main/java/com/example/sms/controller/SmsController.java Voir le fichier

@@ -0,0 +1,28 @@
1
+package com.example.sms.controller;
2
+
3
+import com.example.sms.common.SmsParams;
4
+import com.example.sms.service.SmsService;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Controller;
7
+import org.springframework.web.bind.annotation.RequestBody;
8
+import org.springframework.web.bind.annotation.RequestMapping;
9
+import org.springframework.web.bind.annotation.RequestMethod;
10
+import org.springframework.web.bind.annotation.ResponseBody;
11
+
12
+@Controller
13
+public class SmsController {
14
+
15
+    @Autowired
16
+    private SmsService smsService;
17
+
18
+    /**
19
+     * 所有短信的入口
20
+     * @param smsParams 参数JSON
21
+     * @return
22
+     */
23
+    @RequestMapping(value = "/sms",method = RequestMethod.POST)
24
+    @ResponseBody
25
+    public String smsControlCenter(@RequestBody SmsParams smsParams){
26
+        return smsService.sendMessage(smsParams);
27
+    }
28
+}

+ 14
- 0
src/main/java/com/example/sms/dao/SmsConfigMapper.java Voir le fichier

@@ -0,0 +1,14 @@
1
+package com.example.sms.dao;
2
+
3
+import com.example.sms.model.SmsConfig;
4
+import org.apache.ibatis.annotations.Mapper;
5
+
6
+@Mapper
7
+public interface SmsConfigMapper {
8
+    /**
9
+     * 根据code获取短信模板信息
10
+     * @param code
11
+     * @return
12
+     */
13
+    SmsConfig getSmsConfigInfo(String code);
14
+}

+ 121
- 0
src/main/java/com/example/sms/model/SmsConfig.java Voir le fichier

@@ -0,0 +1,121 @@
1
+package com.example.sms.model;
2
+
3
+/**
4
+ * @author FXF
5
+ * @date 2018-08-29
6
+ */
7
+public class SmsConfig {
8
+    private Integer id;
9
+
10
+    /**
11
+     * 业务code代码
12
+     */
13
+    private String code;
14
+
15
+    /**
16
+     * 短信签名
17
+     */
18
+    private String signature;
19
+
20
+    /**
21
+     * 短信模板
22
+     */
23
+    private String template;
24
+
25
+    /**
26
+     * 发送类型
27
+     */
28
+    private String type;
29
+
30
+    /**
31
+     * 发送内容模板
32
+     */
33
+    private String content;
34
+
35
+    /**
36
+     * 短信模板描述
37
+     */
38
+    private String description;
39
+
40
+    /**
41
+     * 备选模板
42
+     */
43
+    private String backupCode;
44
+
45
+    /**
46
+     * 叮咚云类型 1是验证码短信 2是通知短信 3 是营销短信
47
+     */
48
+    private String messageType;
49
+
50
+    public Integer getId() {
51
+        return id;
52
+    }
53
+
54
+    public void setId(Integer id) {
55
+        this.id = id;
56
+    }
57
+
58
+    public String getCode() {
59
+        return code;
60
+    }
61
+
62
+    public void setCode(String code) {
63
+        this.code = code;
64
+    }
65
+
66
+    public String getSignature() {
67
+        return signature;
68
+    }
69
+
70
+    public void setSignature(String signature) {
71
+        this.signature = signature;
72
+    }
73
+
74
+    public String getTemplate() {
75
+        return template;
76
+    }
77
+
78
+    public void setTemplate(String template) {
79
+        this.template = template;
80
+    }
81
+
82
+    public String getType() {
83
+        return type;
84
+    }
85
+
86
+    public void setType(String type) {
87
+        this.type = type;
88
+    }
89
+
90
+    public String getContent() {
91
+        return content;
92
+    }
93
+
94
+    public void setContent(String content) {
95
+        this.content = content;
96
+    }
97
+
98
+    public String getDescription() {
99
+        return description;
100
+    }
101
+
102
+    public void setDescription(String description) {
103
+        this.description = description;
104
+    }
105
+
106
+    public String getBackupCode() {
107
+        return backupCode;
108
+    }
109
+
110
+    public void setBackupCode(String backupCode) {
111
+        this.backupCode = backupCode;
112
+    }
113
+
114
+    public String getMessageType() {
115
+        return messageType;
116
+    }
117
+
118
+    public void setMessageType(String messageType) {
119
+        this.messageType = messageType;
120
+    }
121
+}

+ 7
- 0
src/main/java/com/example/sms/service/SmsService.java Voir le fichier

@@ -0,0 +1,7 @@
1
+package com.example.sms.service;
2
+
3
+import com.example.sms.common.SmsParams;
4
+
5
+public interface SmsService {
6
+    String sendMessage(SmsParams smsParams);
7
+}

+ 131
- 0
src/main/java/com/example/sms/service/impl/SmsServiceImpl.java Voir le fichier

@@ -0,0 +1,131 @@
1
+package com.example.sms.service.impl;
2
+
3
+import com.aliyuncs.DefaultAcsClient;
4
+import com.aliyuncs.IAcsClient;
5
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
6
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
7
+import com.aliyuncs.exceptions.ClientException;
8
+import com.aliyuncs.http.MethodType;
9
+import com.aliyuncs.profile.DefaultProfile;
10
+import com.aliyuncs.profile.IClientProfile;
11
+import com.example.sms.common.DingdongCloudApis;
12
+import com.example.sms.common.SmsConst;
13
+import com.example.sms.common.SmsParams;
14
+import com.example.sms.dao.SmsConfigMapper;
15
+import com.example.sms.model.SmsConfig;
16
+import com.example.sms.service.SmsService;
17
+import net.onebean.component.aliyun.AliyunSmsSendResult;
18
+import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.beans.factory.annotation.Value;
20
+import org.springframework.stereotype.Service;
21
+import org.springframework.util.StringUtils;
22
+
23
+import java.util.List;
24
+
25
+@Service("smsService")
26
+public class SmsServiceImpl implements SmsService {
27
+
28
+    @Value("${aliyun.oss.accessKeyId}")
29
+    private String accessKeyId;
30
+
31
+    @Value("${aliyun.oss.secretAccessKey}")
32
+    private String accessKeySecret;
33
+
34
+    @Value("${dingdong.apikey}")
35
+    private String apikey;
36
+
37
+    @Autowired
38
+    private SmsConfigMapper smsConfigMapper;
39
+
40
+    @Override
41
+    public String sendMessage(SmsParams smsParams) {
42
+        String message = "";
43
+        String code = smsParams.getCode();
44
+        //获取短信相关信息
45
+        SmsConfig smsConfigInfo = smsConfigMapper.getSmsConfigInfo(code);
46
+        if (null == smsConfigInfo){
47
+            return SmsConst.CODE_NOT_FOUND;
48
+        }
49
+        String type = smsConfigInfo.getType();
50
+        //阿里云短信发送
51
+        if (type.equals("1")){
52
+            message = sendMessageForAliyun(smsConfigInfo,smsParams);
53
+        }else if (type.equals("2")){
54
+            message = sendMessageForDingDong(smsConfigInfo,smsParams);
55
+        }
56
+        return message;
57
+    }
58
+
59
+    //叮咚云发送短信
60
+    private String sendMessageForDingDong(SmsConfig smsConfigInfo, SmsParams smsParams) {
61
+        String content = smsConfigInfo.getContent();
62
+        if (!StringUtils.isEmpty(content))
63
+        {
64
+            content = getSendMeaasge(content,smsParams.getParams());
65
+
66
+        }
67
+        String message = "";
68
+        if (smsConfigInfo.getMessageType().equals("1")){
69
+            message = DingdongCloudApis.sendYzm(apikey,smsParams.getTel(),content);
70
+        }else if (smsConfigInfo.getMessageType().equals("2")){
71
+            message = DingdongCloudApis.sendTz(apikey,smsParams.getTel(),content);
72
+        }else if (smsConfigInfo.getMessageType().equals("3")){
73
+            message = DingdongCloudApis.sendYx(apikey,smsParams.getTel(),content);
74
+        }
75
+        return message;
76
+    }
77
+
78
+    //阿里云发送短信
79
+    private String sendMessageForAliyun(SmsConfig smsConfigInfo,SmsParams smsParams) {
80
+        List<String> paramsList = smsParams.getParams();
81
+        String sendMessage = getSendMeaasge(smsConfigInfo.getContent(),paramsList);
82
+        AliyunSmsSendResult aliyunSmsSendResult = sendSms(smsConfigInfo.getSignature(),smsConfigInfo.getTemplate(),smsParams.getTel(), sendMessage);
83
+        if("OK".equals(aliyunSmsSendResult.getCode())){
84
+            return SmsConst.SUCCESS;
85
+        }else{
86
+            SmsConfig smsDingdongInfo = smsConfigMapper.getSmsConfigInfo(smsConfigInfo.getBackupCode());
87
+            return sendMessageForDingDong(smsDingdongInfo,smsParams);
88
+        }
89
+    }
90
+
91
+    //把模板和传过来的参数组成发送的内容
92
+    private String getSendMeaasge(String content, List<String> paramsList) {
93
+        for (int i = 0; i < paramsList.size(); i++){
94
+            content = content.replace("#"+i,paramsList.get(i));
95
+        }
96
+        return content;
97
+    }
98
+
99
+    public AliyunSmsSendResult sendSms(String smsSignature, String smsTemplate, String phoneNumber, String templateParamJsonStr) {
100
+        AliyunSmsSendResult aliyunSmsSendResult = new AliyunSmsSendResult();
101
+        aliyunSmsSendResult.setFlag(false);
102
+
103
+        try {
104
+            System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
105
+            System.setProperty("sun.net.client.defaultReadTimeout", "10000");
106
+            String product = "Dysmsapi";
107
+            String domain = "dysmsapi.aliyuncs.com";
108
+            IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
109
+            DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
110
+            IAcsClient acsClient = new DefaultAcsClient(profile);
111
+            SendSmsRequest request = new SendSmsRequest();
112
+            request.setMethod(MethodType.POST);
113
+            request.setPhoneNumbers(phoneNumber);
114
+            request.setSignName(smsSignature);
115
+            request.setTemplateCode(smsTemplate);
116
+            request.setTemplateParam(templateParamJsonStr);
117
+            request.setOutId("yourOutId");
118
+            SendSmsResponse sendSmsResponse = (SendSmsResponse)acsClient.getAcsResponse(request);
119
+            if (sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
120
+                aliyunSmsSendResult.setFlag(true);
121
+            }
122
+
123
+            aliyunSmsSendResult.setMsg(sendSmsResponse.getMessage());
124
+            aliyunSmsSendResult.setCode(sendSmsResponse.getCode());
125
+        } catch (ClientException e) {
126
+            aliyunSmsSendResult.setCode("fail");
127
+            aliyunSmsSendResult.setMsg("程序出错");
128
+        }
129
+        return aliyunSmsSendResult;
130
+    }
131
+}

+ 24
- 0
src/main/resources/application.yml Voir le fichier

@@ -0,0 +1,24 @@
1
+server:
2
+    port: 8088
3
+
4
+## JDBC
5
+spring:
6
+    datasource:
7
+        url: jdbc:mysql://106.14.20.225:3306/huiju_sms?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
8
+        username: root
9
+        password: jingcheng123
10
+        driver-class-name: com.mysql.jdbc.Driver
11
+
12
+
13
+## Mybatis
14
+mybatis:
15
+    typeAliasesPackage: com.example.sms.model
16
+    mapperLocations: classpath:mapper/*.xml
17
+
18
+aliyun:
19
+    oss:
20
+      accessKeyId: LTAIkc75dpkJw8Lb
21
+      secretAccessKey: v4bvXCaix6vSDTCFfwSAdqV53iFEQw
22
+
23
+dingdong:
24
+    apikey: b4fd096f32fceb24559888f3c69cfe91

+ 36
- 0
src/main/resources/mapper/SmsConfigMapper.xml Voir le fichier

@@ -0,0 +1,36 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="com.example.sms.dao.SmsConfigMapper">
4
+
5
+    <parameterMap id="paramMap" type="com.example.sms.model.SmsConfig"></parameterMap>
6
+
7
+    <resultMap id="resultMap" type="com.example.sms.model.SmsConfig">
8
+        <id property="id" column="id"/>
9
+        <result property="code" column="code"/>
10
+        <result property="signature" column="signature"/>
11
+        <result property="template" column="template"/>
12
+        <result property="type" column="type"/>
13
+        <result property="content" column="content"/>
14
+        <result property="description" column="description"/>
15
+        <result property="backupCode" column="backup_code"/>
16
+        <result property="messageType" column="message_type"/>
17
+    </resultMap>
18
+
19
+    <select id="getSmsConfigInfo" parameterType="java.lang.String" resultMap="resultMap">
20
+        SELECT
21
+            id,
22
+            `code`,
23
+            signature,
24
+            template,
25
+            type,
26
+            content,
27
+            description,
28
+            backup_code,
29
+            message_type
30
+        FROM
31
+            sms_config
32
+        WHERE
33
+            `code` = #{code}
34
+    </select>
35
+
36
+</mapper>

+ 16
- 0
src/test/java/com/example/sms/DemoApplicationTests.java Voir le fichier

@@ -0,0 +1,16 @@
1
+package com.example.sms;
2
+
3
+import org.junit.Test;
4
+import org.junit.runner.RunWith;
5
+import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.junit4.SpringRunner;
7
+
8
+@RunWith(SpringRunner.class)
9
+@SpringBootTest
10
+public class DemoApplicationTests {
11
+
12
+	@Test
13
+	public void contextLoads() {
14
+	}
15
+
16
+}