├── .gitignore
├── LICENSE
├── README.md
├── dependency-reduced-pom.xml
├── docs
├── allclasses-frame.html
├── allclasses-noframe.html
├── com
│ └── github
│ │ └── qcloudsms
│ │ ├── FileVoiceSender.html
│ │ ├── FileVoiceSenderResult.html
│ │ ├── SmsBase.html
│ │ ├── SmsMobileStatusPuller.html
│ │ ├── SmsMultiSender.html
│ │ ├── SmsMultiSenderResult.Detail.html
│ │ ├── SmsMultiSenderResult.html
│ │ ├── SmsResultBase.html
│ │ ├── SmsSenderUtil.html
│ │ ├── SmsSingleSender.html
│ │ ├── SmsSingleSenderResult.html
│ │ ├── SmsStatusPullCallbackResult.Callback.html
│ │ ├── SmsStatusPullCallbackResult.html
│ │ ├── SmsStatusPullReplyResult.Reply.html
│ │ ├── SmsStatusPullReplyResult.html
│ │ ├── SmsStatusPuller.html
│ │ ├── SmsVoicePromptSender.html
│ │ ├── SmsVoicePromptSenderResult.html
│ │ ├── SmsVoiceVerifyCodeSender.html
│ │ ├── SmsVoiceVerifyCodeSenderResult.html
│ │ ├── TtsVoiceSender.html
│ │ ├── TtsVoiceSenderResult.html
│ │ ├── VoiceFileStatus.html
│ │ ├── VoiceFileStatusResult.html
│ │ ├── VoiceFileUploader.ContentType.html
│ │ ├── VoiceFileUploader.html
│ │ ├── VoiceFileUploaderResult.html
│ │ ├── class-use
│ │ ├── FileVoiceSender.html
│ │ ├── FileVoiceSenderResult.html
│ │ ├── SmsBase.html
│ │ ├── SmsMobileStatusPuller.html
│ │ ├── SmsMultiSender.html
│ │ ├── SmsMultiSenderResult.Detail.html
│ │ ├── SmsMultiSenderResult.html
│ │ ├── SmsResultBase.html
│ │ ├── SmsSenderUtil.html
│ │ ├── SmsSingleSender.html
│ │ ├── SmsSingleSenderResult.html
│ │ ├── SmsStatusPullCallbackResult.Callback.html
│ │ ├── SmsStatusPullCallbackResult.html
│ │ ├── SmsStatusPullReplyResult.Reply.html
│ │ ├── SmsStatusPullReplyResult.html
│ │ ├── SmsStatusPuller.html
│ │ ├── SmsVoicePromptSender.html
│ │ ├── SmsVoicePromptSenderResult.html
│ │ ├── SmsVoiceVerifyCodeSender.html
│ │ ├── SmsVoiceVerifyCodeSenderResult.html
│ │ ├── TtsVoiceSender.html
│ │ ├── TtsVoiceSenderResult.html
│ │ ├── VoiceFileStatus.html
│ │ ├── VoiceFileStatusResult.html
│ │ ├── VoiceFileUploader.ContentType.html
│ │ ├── VoiceFileUploader.html
│ │ └── VoiceFileUploaderResult.html
│ │ ├── httpclient
│ │ ├── DefaultHTTPClient.html
│ │ ├── HTTPClient.html
│ │ ├── HTTPException.html
│ │ ├── HTTPMethod.html
│ │ ├── HTTPRequest.html
│ │ ├── HTTPResponse.html
│ │ ├── PoolingHTTPClient.html
│ │ ├── ProxyHTTPClient.html
│ │ ├── class-use
│ │ │ ├── DefaultHTTPClient.html
│ │ │ ├── HTTPClient.html
│ │ │ ├── HTTPException.html
│ │ │ ├── HTTPMethod.html
│ │ │ ├── HTTPRequest.html
│ │ │ ├── HTTPResponse.html
│ │ │ ├── PoolingHTTPClient.html
│ │ │ └── ProxyHTTPClient.html
│ │ ├── package-frame.html
│ │ ├── package-summary.html
│ │ ├── package-tree.html
│ │ └── package-use.html
│ │ ├── package-frame.html
│ │ ├── package-summary.html
│ │ ├── package-tree.html
│ │ └── package-use.html
├── constant-values.html
├── deprecated-list.html
├── help-doc.html
├── index-all.html
├── index.html
├── overview-frame.html
├── overview-summary.html
├── overview-tree.html
├── package-list
├── script.js
├── serialized-form.html
└── stylesheet.css
├── pom.xml
├── releases
├── qcloudsms-1.0.6-javadoc.jar
├── qcloudsms-1.0.6-javadoc.jar.asc
├── qcloudsms-1.0.6-sources.jar
├── qcloudsms-1.0.6-sources.jar.asc
├── qcloudsms-1.0.6.jar
└── qcloudsms-1.0.6.jar.asc
└── src
├── main
└── java
│ └── com
│ └── github
│ └── qcloudsms
│ ├── FileVoiceSender.java
│ ├── FileVoiceSenderResult.java
│ ├── SmsBase.java
│ ├── SmsMobileStatusPuller.java
│ ├── SmsMultiSender.java
│ ├── SmsMultiSenderResult.java
│ ├── SmsResultBase.java
│ ├── SmsSenderUtil.java
│ ├── SmsSingleSender.java
│ ├── SmsSingleSenderResult.java
│ ├── SmsStatusPullCallbackResult.java
│ ├── SmsStatusPullReplyResult.java
│ ├── SmsStatusPuller.java
│ ├── SmsVoicePromptSender.java
│ ├── SmsVoicePromptSenderResult.java
│ ├── SmsVoiceVerifyCodeSender.java
│ ├── SmsVoiceVerifyCodeSenderResult.java
│ ├── TtsVoiceSender.java
│ ├── TtsVoiceSenderResult.java
│ ├── VoiceFileStatus.java
│ ├── VoiceFileStatusResult.java
│ ├── VoiceFileUploader.java
│ ├── VoiceFileUploaderResult.java
│ └── httpclient
│ ├── DefaultHTTPClient.java
│ ├── HTTPClient.java
│ ├── HTTPException.java
│ ├── HTTPMethod.java
│ ├── HTTPRequest.java
│ ├── HTTPResponse.java
│ ├── PoolingHTTPClient.java
│ └── ProxyHTTPClient.java
└── test
└── java
└── QcloudSmsTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | .settings/
3 | .classpath
4 | .project
5 | target/
6 | pkg.sh
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 qcloudsms
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/dependency-reduced-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.github.qcloudsms
5 | sms
6 | qcloudsms_java
7 | 1.0.0
8 | qcloudsms Java SDK
9 |
10 |
11 | cubin lai
12 | cubinlai@tencent.com
13 | tencent
14 | https://cloud.tencent.com
15 |
16 |
17 |
18 |
19 | The Apache Software License, Version 2.0
20 | http://www.apache.org/licenses/LICENSE-2.0.txt
21 |
22 |
23 |
24 | scm:git:git://github.com/simpligility/ossrh-demo.git
25 | scm:git:ssh://github.com:simpligility/ossrh-demo.git
26 | http://github.com/simpligility/ossrh-demo/tree/master
27 |
28 |
29 |
30 |
31 | maven-source-plugin
32 | 2.2.1
33 |
34 |
35 | attach-sources
36 |
37 | jar-no-fork
38 |
39 |
40 |
41 |
42 |
43 | maven-javadoc-plugin
44 | 2.9.1
45 |
46 |
47 | attach-javadocs
48 |
49 | jar
50 |
51 |
52 |
53 |
54 |
55 | maven-gpg-plugin
56 | 1.5
57 |
58 |
59 | sign-artifacts
60 | verify
61 |
62 | sign
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | junit
72 | junit
73 | 3.8.1
74 | test
75 |
76 |
77 |
78 |
79 | ossrh
80 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
81 |
82 |
83 | ossrh
84 | https://oss.sonatype.org/content/repositories/snapshots
85 |
86 |
87 |
88 | UTF-8
89 |
90 |
91 |
--------------------------------------------------------------------------------
/docs/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 | All Classes
14 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/docs/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 | All Classes
14 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/FileVoiceSender.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.FileVoiceSender (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.FileVoiceSender
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsMobileStatusPuller.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsMobileStatusPuller (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsMobileStatusPuller
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsMultiSender.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsMultiSender (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsMultiSender
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsSenderUtil.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsSenderUtil (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsSenderUtil
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsSingleSender.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsSingleSender (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsSingleSender
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsStatusPuller.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsStatusPuller (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsStatusPuller
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsVoicePromptSender.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsVoicePromptSender (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsVoicePromptSender
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/SmsVoiceVerifyCodeSender.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.SmsVoiceVerifyCodeSender (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.SmsVoiceVerifyCodeSender
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/TtsVoiceSender.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.TtsVoiceSender (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.TtsVoiceSender
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/VoiceFileStatus.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.VoiceFileStatus (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.VoiceFileStatus
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/VoiceFileStatusResult.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.VoiceFileStatusResult (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 |
77 |
78 | -
79 |
92 |
93 | -
94 |
120 |
121 |
122 |
123 |
124 |
142 |
143 |
144 | - Prev
145 | - Next
146 |
147 |
151 |
154 |
155 |
165 |
166 |
167 |
168 |
169 |
170 | Copyright © 2018. All rights reserved.
171 |
172 |
173 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/VoiceFileUploader.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.VoiceFileUploader (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.VoiceFileUploader
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/class-use/VoiceFileUploaderResult.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.VoiceFileUploaderResult (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 |
77 |
78 | -
79 |
92 |
93 | -
94 |
121 |
122 |
123 |
124 |
125 |
143 |
144 |
145 | - Prev
146 | - Next
147 |
148 |
152 |
155 |
156 |
166 |
167 |
168 |
169 |
170 |
171 | Copyright © 2018. All rights reserved.
172 |
173 |
174 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/httpclient/class-use/DefaultHTTPClient.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.httpclient.DefaultHTTPClient (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.httpclient.DefaultHTTPClient
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/httpclient/class-use/PoolingHTTPClient.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.httpclient.PoolingHTTPClient (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.httpclient.PoolingHTTPClient
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/httpclient/class-use/ProxyHTTPClient.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class com.github.qcloudsms.httpclient.ProxyHTTPClient (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of com.github.qcloudsms.httpclient.ProxyHTTPClient
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/httpclient/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.github.qcloudsms.httpclient (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Interfaces
16 |
19 |
Classes
20 |
27 |
Enums
28 |
31 |
Exceptions
32 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/docs/com/github/qcloudsms/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | com.github.qcloudsms (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Classes
16 |
41 |
Enums
42 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/docs/constant-values.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Constant Field Values (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Deprecated List (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
77 |
78 |
96 |
97 |
98 | - Prev
99 | - Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 | Copyright © 2018. All rights reserved.
125 |
126 |
127 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | qcloud sms java sdk 1.0.6 API
8 |
61 |
62 |
76 |
77 |
--------------------------------------------------------------------------------
/docs/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview List (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/overview-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 |
95 |
96 |
114 |
115 |
116 | - Prev
117 | - Next
118 |
119 |
123 |
126 |
127 |
137 |
138 |
139 |
140 |
141 |
142 | Copyright © 2018. All rights reserved.
143 |
144 |
145 |
--------------------------------------------------------------------------------
/docs/package-list:
--------------------------------------------------------------------------------
1 | com.github.qcloudsms
2 | com.github.qcloudsms.httpclient
3 |
--------------------------------------------------------------------------------
/docs/script.js:
--------------------------------------------------------------------------------
1 | function show(type)
2 | {
3 | count = 0;
4 | for (var key in methods) {
5 | var row = document.getElementById(key);
6 | if ((methods[key] & type) != 0) {
7 | row.style.display = '';
8 | row.className = (count++ % 2) ? rowColor : altColor;
9 | }
10 | else
11 | row.style.display = 'none';
12 | }
13 | updateTabs(type);
14 | }
15 |
16 | function updateTabs(type)
17 | {
18 | for (var value in tabs) {
19 | var sNode = document.getElementById(tabs[value][0]);
20 | var spanNode = sNode.firstChild;
21 | if (value == type) {
22 | sNode.className = activeTableTab;
23 | spanNode.innerHTML = tabs[value][1];
24 | }
25 | else {
26 | sNode.className = tableTab;
27 | spanNode.innerHTML = "" + tabs[value][1] + "";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/docs/serialized-form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Serialized Form (qcloud sms java sdk 1.0.6 API)
8 |
9 |
10 |
11 |
12 |
13 |
23 |
26 |
27 |
45 |
72 |
73 |
76 |
105 |
106 |
124 |
125 |
126 | - Prev
127 | - Next
128 |
129 |
133 |
136 |
137 |
147 |
148 |
149 |
150 |
151 |
152 | Copyright © 2018. All rights reserved.
153 |
154 |
155 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | com.github.qcloudsms
4 | qcloudsms
5 | 1.0.6
6 | qcloud sms java sdk
7 | https://github.com/qcloudsms/qcloudsms_java/
8 | this Repository is responsible for qlcoud sms sdk
9 |
10 |
11 | MIT License
12 | http://www.apache.org/licenses/LICENSE-2.0.txt
13 |
14 |
15 |
16 |
17 |
18 | qcloudsms
19 | qcloudsms@gmail.com
20 | tencent
21 | https://cloud.tencent.com
22 |
23 |
24 |
25 |
26 | scm:git:git://github.com/qcloudsms/qcloudsms_java.git
27 | scm:git:git://github.com/qcloudsms/qcloudsms_java.git
28 | https://github.com/qcloudsms/qcloudsms_java/blob/master/LICENSE
29 |
30 |
31 |
32 |
33 | ossrh
34 | https://oss.sonatype.org/content/repositories/snapshots
35 |
36 |
37 | ossrh
38 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
39 |
40 |
41 |
42 |
43 | UTF-8
44 |
45 |
46 |
47 |
48 | junit
49 | junit
50 | 3.8.1
51 | test
52 |
53 |
54 |
55 | org.json
56 | json
57 | 20170516
58 |
59 |
60 |
61 | org.apache.httpcomponents
62 | httpclient
63 | 4.5.3
64 |
65 |
66 |
67 | org.apache.httpcomponents
68 | httpmime
69 | 4.5.3
70 |
71 |
72 |
73 | commons-codec
74 | commons-codec
75 | 1.11
76 | compile
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | org.sonatype.plugins
85 | nexus-staging-maven-plugin
86 | 1.6.7
87 | true
88 |
89 | ossrh
90 | https://oss.sonatype.org/
91 | true
92 |
93 |
94 |
95 | org.apache.maven.plugins
96 | maven-source-plugin
97 | 2.2.1
98 |
99 |
100 | attach-sources
101 |
102 | jar-no-fork
103 |
104 |
105 |
106 |
107 |
108 | org.apache.maven.plugins
109 | maven-javadoc-plugin
110 | 2.9.1
111 |
112 |
113 | attach-javadocs
114 |
115 | jar
116 |
117 |
118 |
119 |
120 |
121 | org.apache.maven.plugins
122 | maven-gpg-plugin
123 | 1.5
124 |
125 |
126 | sign-artifacts
127 | verify
128 |
129 | sign
130 |
131 |
132 |
133 |
134 |
135 | maven-assembly-plugin
136 |
137 | false
138 |
139 | jar-with-dependencies
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/releases/qcloudsms-1.0.6-javadoc.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qcloudsms/qcloudsms_java/26a7cef0ebc2b18cf847010b6f11e13412507908/releases/qcloudsms-1.0.6-javadoc.jar
--------------------------------------------------------------------------------
/releases/qcloudsms-1.0.6-javadoc.jar.asc:
--------------------------------------------------------------------------------
1 | -----BEGIN PGP SIGNATURE-----
2 | Version: GnuPG v2.0.22 (GNU/Linux)
3 |
4 | iQIcBAABAgAGBQJbrZsiAAoJEA9/gfDVUTLg6OIP/2awlLJm9IUfg96pvVWGB4u5
5 | nGJogdbdilOwxGbv3TY7m3jilETNdLcitfVBxrUP9szF0mjECh7S2/IXXFzx4H+6
6 | Ct8BbMJAJHMDSk899N9eh0ciUXYaccQNPfhlJCfD4v/Pt+7rq3r3ulu6PQTn3qgZ
7 | VLTE87XkMnEWwNjbghlJ1qmm45HvMp5Nc5/mErlIS8N95/9H83JwkizwsUlT+hka
8 | sHFbf3WEA/rde1ajYWsS4AnXILJd940f7M6Jdtpnqn+XZV88V1aYYbkyCO4a4mzM
9 | 2+s75k6T7wFA7VdbYCWSrLrl9gIvy2Vi3rYkKiq32r6ooqLzbvaEl5LTy1Sf70Py
10 | K54AD0HDJHdP7XJ3A39dt66ZY8gFf8vudoSrYAjuSBKJrbEiCmUs9Jm5vBnRbrVc
11 | kRw+M2+AObR8Qkm547O4g+POcwv3NHrE1vYT2Xk0pSx8cHp/75qdT94NYJtWOX23
12 | pBq+4cfRMiQacpoCckq5liNQf0+ISH+78juXmbXZyYbTGDjT+6r6mYX6i5p/Asf9
13 | 2ZKQs6+ngklDvqeuRQ4r9s8Ygo8CcilZkVfUCmgo6GmNovW/fnPe4XevgVWVdXuB
14 | kY6UBiGEu0UyuV8KBuCe8zEyTgCn8OYi9k6KaVTefigDneDhT3gVsLGYgprPfEAE
15 | LAzWnJJOFIH1V4tCNSpB
16 | =jta9
17 | -----END PGP SIGNATURE-----
18 |
--------------------------------------------------------------------------------
/releases/qcloudsms-1.0.6-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qcloudsms/qcloudsms_java/26a7cef0ebc2b18cf847010b6f11e13412507908/releases/qcloudsms-1.0.6-sources.jar
--------------------------------------------------------------------------------
/releases/qcloudsms-1.0.6-sources.jar.asc:
--------------------------------------------------------------------------------
1 | -----BEGIN PGP SIGNATURE-----
2 | Version: GnuPG v2.0.22 (GNU/Linux)
3 |
4 | iQIcBAABAgAGBQJbrZsiAAoJEA9/gfDVUTLg3FsP/1GRLH4bOyppGBskYK8CsuTI
5 | asZuPxthNd3awH8Oj4dn1SI15tzmmxkxKWEbIxcgYn63PIx371LpL32X0mRe4wiM
6 | 4BjK0CegypsvAs/CM3sLU79bwf27rdp1rng7r7s7LeXfowYJ2tB3kWnd4uGGXefz
7 | pWFWe82rGaYD+saiBScLmqgUEv9TWahqEboLxBMrzMFk0NX7WJNsYNkDr1y4db0X
8 | GMo1YCwVT1sLRt9o8AEeABTzR6Ep9N0s3MSSTdQ11f8Nrs6YIS5apvrui+cT7NV5
9 | QiuYFj1ogy+UkUG1H4PenOd78FfjZK+A7Ad1yqHDTQyuKzM/N5jhGQjgU1bT0UaD
10 | moxF9owyIXtbn0i18OQaJ2olErCvwqj85gPcmELpDUgIPFs80otQJVaygNW7tcRF
11 | XWur0tZoOsESOUBIaIjm0wYme3PVG6o3/qdK74PjQ3hD0WHUYq3xDNRs6Xii34+u
12 | pVZc+NRcTrkqsdxPRaKYpjveSgnCdjR3qQNDVVAl3RTKMLSOd2k5waYy7swCfqIa
13 | MVgTdB2oAmUlRIQecpHYHkOZJplzpvx+Xa5+SSKgeY6Qdfc24r29nDYz5GWnbvJs
14 | EUMMEINfGQps/joL7Le07Cjg3i661wq1GNtvyFfEUM/y6OuEKQRjD70czcx38JRl
15 | Kze1e/wqjiAf7/lajyeG
16 | =yGZt
17 | -----END PGP SIGNATURE-----
18 |
--------------------------------------------------------------------------------
/releases/qcloudsms-1.0.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qcloudsms/qcloudsms_java/26a7cef0ebc2b18cf847010b6f11e13412507908/releases/qcloudsms-1.0.6.jar
--------------------------------------------------------------------------------
/releases/qcloudsms-1.0.6.jar.asc:
--------------------------------------------------------------------------------
1 | -----BEGIN PGP SIGNATURE-----
2 | Version: GnuPG v2.0.22 (GNU/Linux)
3 |
4 | iQIcBAABAgAGBQJbrZshAAoJEA9/gfDVUTLgp7MP/2NmGAUPKXeJc1ebXrUe/K/g
5 | S4RJuNpZdAghU5ioDDJz/sVYZ6kuR0VJ+EI6nsoO3OodPwHHVihrhsMISJ3sSGs3
6 | 6L/ZqzMbuukERCipRJaMUj3tRzTn2kp4Hq43swVK8K35CSIVktvLOmqFqh4d7PyA
7 | l4vV3bkpNcS1anuY26+3RZcjH53+MzuBfV8/BVYuPCo0kLCLfVtrJU6OuUZ6YQ7c
8 | aKyMCx1JEP0gAjx5HFJ00XDGMNJCIvOem3UStu4PuT0pszSKuCOQsT4ZX6U/EBi7
9 | hC4IYaH9ltvG/EZV3tEuRLuS4zv/JLe8R9tXtvAD0rTVkjwIFZrlD/pGLksC6q8H
10 | mbByk5gxaMFmhgsXufHDcv8FzMG4r04+NSzXT2nHiq6PzQ7rcU19XzbRkprfrxgS
11 | 80qw1CP9GnPyabxUTL3Dc1FoIkN/eJudvSff2gabb4XzsOzgLehVpUc2Wtyh4fzr
12 | 7m9OSzVRUEjZkz6/Wcs3jBgegVomxypfvSswbH6AFTft9a9/j8XQhfPS+POPCH/9
13 | VHnZ6nCCB45PYn/sS7ppZnZ8xUJH18HBTGcM+M7el5epL7LHkgjgK+Odd8Crfj6X
14 | PtKhF7O7Zz3LYRcO6vBLl6qUYGt9V4tJgmzuGlMxdjBXDsv5WDxyuDKVqma1+eCr
15 | UEjtjtridee+WNXmDxM/
16 | =qdZS
17 | -----END PGP SIGNATURE-----
18 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/FileVoiceSender.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 | import java.util.ArrayList;
16 |
17 |
18 | public class FileVoiceSender extends SmsBase {
19 |
20 | private String url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/sendfvoice";
21 |
22 | public FileVoiceSender(int appid, String appkey) {
23 | super(appid, appkey, new DefaultHTTPClient());
24 | }
25 |
26 | public FileVoiceSender(int appid, String appkey, HTTPClient httpclient) {
27 | super(appid, appkey, httpclient);
28 | }
29 |
30 | /**
31 | * 发送文件语音
32 | *
33 | * @param nationCode 国家码,如 86 为中国
34 | * @param phoneNumber 不带国家码的手机号
35 | * @param fid 语音文件fid
36 | * @param playtimes 播放次数
37 | * @param ext 扩展字段,原样返回
38 | * @return {@link}FileVoiceSenderResult
39 | * @throws HTTPException http status exception
40 | * @throws JSONException json parse exception
41 | * @throws IOException network problem
42 | */
43 | public FileVoiceSenderResult send(String nationCode, String phoneNumber,
44 | String fid, int playtimes, String ext)
45 | throws HTTPException, JSONException, IOException {
46 |
47 | long random = SmsSenderUtil.getRandom();
48 | long now = SmsSenderUtil.getCurrentTime();
49 | JSONObject body = new JSONObject()
50 | .put("tel", (new JSONObject()).put("nationcode", nationCode).put("mobile", phoneNumber))
51 | .put("fid", fid)
52 | .put("playtimes", playtimes)
53 | .put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber))
54 | .put("time", now)
55 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
56 |
57 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
58 | .addHeader("Conetent-Type", "application/json")
59 | .addQueryParameter("sdkappid", this.appid)
60 | .addQueryParameter("random", random)
61 | .setConnectionTimeout(60 * 1000)
62 | .setRequestTimeout(60 * 1000)
63 | .setBody(body.toString());
64 |
65 | try {
66 | // May throw IOException and URISyntaxexception
67 | HTTPResponse res = httpclient.fetch(req);
68 |
69 | // May throw HTTPException
70 | handleError(res);
71 |
72 | // May throw JSONException
73 | return (new FileVoiceSenderResult()).parseFromHTTPResponse(res);
74 | } catch(URISyntaxException e) {
75 | throw new RuntimeException("API url has been modified, current url: " + url);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/FileVoiceSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONObject;
6 | import org.json.JSONException;
7 |
8 |
9 | public class FileVoiceSenderResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public String ext;
14 | public String callid;
15 |
16 | public FileVoiceSenderResult() {
17 | this.errMsg = "";
18 | this.ext = "";
19 | this.callid = "";
20 | }
21 |
22 | @Override
23 | public FileVoiceSenderResult parseFromHTTPResponse(HTTPResponse response)
24 | throws JSONException {
25 |
26 | JSONObject json = parseToJson(response);
27 |
28 | result = json.getInt("result");
29 | errMsg = json.getString("errmsg");
30 |
31 | if (json.has("ext")) {
32 | ext = json.getString("ext");
33 | }
34 | if (json.has("callid")) {
35 | callid = json.getString("callid");
36 | }
37 |
38 | return this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsBase.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPResponse;
6 |
7 |
8 | public class SmsBase {
9 |
10 | protected int appid;
11 | protected String appkey;
12 | protected HTTPClient httpclient;
13 |
14 | /**
15 | * SmsBase constructor
16 | *
17 | * @param appid sdk appid
18 | * @param appkey sdk appkey
19 | * @param httpclient http client
20 | */
21 | public SmsBase(int appid, String appkey, HTTPClient httpclient) {
22 | this.appid = appid;
23 | this.appkey = appkey;
24 | this.httpclient = httpclient;
25 | }
26 |
27 | /**
28 | * Handle http status error
29 | *
30 | * @param response raw http response
31 | * @return response raw http response
32 | * @throws HTTPException http status exception
33 | */
34 | public HTTPResponse handleError(HTTPResponse response) throws HTTPException {
35 | if (response.statusCode < 200 || response.statusCode >= 300) {
36 | throw new HTTPException(response.statusCode, response.reason);
37 | }
38 | return response;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsMobileStatusPuller.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import org.json.JSONObject;
4 | import org.json.JSONException;
5 |
6 | import com.github.qcloudsms.httpclient.HTTPClient;
7 | import com.github.qcloudsms.httpclient.HTTPException;
8 | import com.github.qcloudsms.httpclient.HTTPMethod;
9 | import com.github.qcloudsms.httpclient.HTTPRequest;
10 | import com.github.qcloudsms.httpclient.HTTPResponse;
11 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
12 |
13 | import org.json.JSONObject;
14 |
15 | import java.io.IOException;
16 | import java.net.URISyntaxException;
17 |
18 |
19 | public class SmsMobileStatusPuller extends SmsBase {
20 |
21 | private String url = "https://yun.tim.qq.com/v5/tlssmssvr/pullstatus4mobile";
22 |
23 | public SmsMobileStatusPuller(int appid, String appkey) {
24 | super(appid, appkey, new DefaultHTTPClient());
25 | }
26 |
27 | public SmsMobileStatusPuller(int appid, String appkey, HTTPClient httpclient) {
28 | super(appid, appkey, httpclient);
29 | }
30 |
31 | private HTTPResponse pull(int type, String nationCode, String mobile, long beginTime,
32 | long endTime, int max) throws IOException {
33 |
34 | long random = SmsSenderUtil.getRandom();
35 | long now = SmsSenderUtil.getCurrentTime();
36 | JSONObject body = new JSONObject();
37 | body.put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now))
38 | .put("type", type)
39 | .put("time", now)
40 | .put("max", max)
41 | .put("begin_time", beginTime)
42 | .put("end_time", endTime)
43 | .put("nationcode", nationCode)
44 | .put("mobile", mobile);
45 |
46 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
47 | .addHeader("Conetent-Type", "application/json")
48 | .addQueryParameter("sdkappid", this.appid)
49 | .addQueryParameter("random", random)
50 | .setConnectionTimeout(60 * 1000)
51 | .setRequestTimeout(60 * 10000)
52 | .setBody(body.toString());
53 |
54 | // May throw IOException
55 | try {
56 | return httpclient.fetch(req);
57 | } catch(URISyntaxException e) {
58 | throw new RuntimeException("API url has been modified, current url: " + url);
59 | }
60 | }
61 |
62 | public SmsStatusPullCallbackResult pullCallback(String nationCode, String mobile,
63 | long beginTime, long endTime, int max)
64 | throws HTTPException, JSONException, IOException {
65 |
66 | // May throw IOException
67 | HTTPResponse res = pull(0, nationCode, mobile, beginTime, endTime, max);
68 |
69 | // May throw HTTPException
70 | handleError(res);
71 |
72 | // May throw JSONException
73 | return (new SmsStatusPullCallbackResult()).parseFromHTTPResponse(res);
74 | }
75 |
76 | public SmsStatusPullReplyResult pullReply(String nationCode, String mobile,
77 | long beginTime, long endTime, int max)
78 | throws HTTPException, JSONException, IOException {
79 |
80 | // May throw IOException
81 | HTTPResponse res = pull(1, nationCode, mobile, beginTime, endTime, max);
82 |
83 | // May throw HTTPException
84 | handleError(res);
85 |
86 | // May throw JSONException
87 | return (new SmsStatusPullReplyResult()).parseFromHTTPResponse(res);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsMultiSender.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 | import java.util.ArrayList;
16 | import java.util.Arrays;
17 |
18 |
19 | public class SmsMultiSender extends SmsBase {
20 |
21 | private String url = "https://yun.tim.qq.com/v5/tlssmssvr/sendmultisms2";
22 |
23 | public SmsMultiSender(int appid, String appkey) {
24 | super(appid, appkey, new DefaultHTTPClient());
25 | }
26 |
27 | public SmsMultiSender(int appid, String appkey, HTTPClient httpclient) {
28 | super(appid, appkey, httpclient);
29 | }
30 |
31 | /**
32 | * 普通群发
33 | *
34 | * 明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
35 | *
36 | * @param type 短信类型,0 为普通短信,1 营销短信
37 | * @param nationCode 国家码,如 86 为中国
38 | * @param phoneNumbers 不带国家码的手机号列表
39 | * @param msg 信息内容,必须与申请的模板格式一致,否则将返回错误
40 | * @param extend 扩展码,可填空
41 | * @param ext 服务端原样返回的参数,可填空
42 | * @return {@link}SmsMultiSenderResult
43 | * @throws HTTPException http status exception
44 | * @throws JSONException json parse exception
45 | * @throws IOException network problem
46 | */
47 | public SmsMultiSenderResult send(int type, String nationCode, ArrayList phoneNumbers,
48 | String msg, String extend, String ext)
49 | throws HTTPException, JSONException, IOException {
50 |
51 | long random = SmsSenderUtil.getRandom();
52 | long now = SmsSenderUtil.getCurrentTime();
53 | JSONObject body = new JSONObject();
54 | body.put("tel", toTel(nationCode, phoneNumbers))
55 | .put("type", type)
56 | .put("msg", msg)
57 | .put("sig", SmsSenderUtil.calculateSignature(appkey, random, now, phoneNumbers))
58 | .put("time", now)
59 | .put("extend", SmsSenderUtil.isNotEmpty(extend) ? extend : "")
60 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
61 |
62 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
63 | .addHeader("Conetent-Type", "application/json")
64 | .addQueryParameter("sdkappid", this.appid)
65 | .addQueryParameter("random", random)
66 | .setConnectionTimeout(60 * 1000)
67 | .setRequestTimeout(60 * 1000)
68 | .setBody(body.toString());
69 |
70 | try {
71 | // May throw IOException and URISyntaxexception
72 | HTTPResponse res = httpclient.fetch(req);
73 |
74 | // May throw HTTPException
75 | handleError(res);
76 |
77 | // May throw JSONException
78 | return (new SmsMultiSenderResult()).parseFromHTTPResponse(res);
79 | } catch(URISyntaxException e) {
80 | throw new RuntimeException("API url has been modified, current url: " + url);
81 | }
82 | }
83 |
84 | public SmsMultiSenderResult send(int type, String nationCode, String[] phoneNumbers,
85 | String msg, String extend, String ext)
86 | throws HTTPException, JSONException, IOException {
87 |
88 | return send(type, nationCode, new ArrayList(Arrays.asList(phoneNumbers)),
89 | msg, extend, ext);
90 | }
91 |
92 | /**
93 | * 指定模板群发
94 | *
95 | * @param nationCode 国家码,如 86 为中国
96 | * @param phoneNumbers 不带国家码的手机号列表
97 | * @param templateId 模板 id
98 | * @param params 模板参数列表
99 | * @param sign 签名,如果填空,系统会使用默认签名
100 | * @param extend 扩展码,可以填空
101 | * @param ext 服务端原样返回的参数,可以填空
102 | * @return {@link}SmsMultiSenderResult
103 | * @throws HTTPException http status exception
104 | * @throws JSONException json parse exception
105 | * @throws IOException network problem
106 | */
107 | public SmsMultiSenderResult sendWithParam(String nationCode, ArrayList phoneNumbers,
108 | int templateId, ArrayList params, String sign, String extend, String ext)
109 | throws HTTPException, JSONException, IOException {
110 |
111 | long random = SmsSenderUtil.getRandom();
112 | long now = SmsSenderUtil.getCurrentTime();
113 | JSONObject body = new JSONObject()
114 | .put("tel", toTel(nationCode, phoneNumbers))
115 | .put("sign", sign)
116 | .put("tpl_id", templateId)
117 | .put("params", params)
118 | .put("sig", SmsSenderUtil.calculateSignature(appkey, random, now, phoneNumbers))
119 | .put("time", now)
120 | .put("extend", SmsSenderUtil.isNotEmpty(extend) ? extend : "")
121 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
122 |
123 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
124 | .addHeader("Conetent-Type", "application/json")
125 | .addQueryParameter("sdkappid", this.appid)
126 | .addQueryParameter("random", random)
127 | .setConnectionTimeout(60 * 1000)
128 | .setRequestTimeout(60 * 1000)
129 | .setBody(body.toString());
130 |
131 | try {
132 | // May throw IOException and URISyntaxexception
133 | HTTPResponse res = httpclient.fetch(req);
134 |
135 | // May throw HTTPException
136 | handleError(res);
137 |
138 | // May throw JSONException
139 | return (new SmsMultiSenderResult()).parseFromHTTPResponse(res);
140 | } catch (URISyntaxException e) {
141 | throw new RuntimeException("API url has been modified, current url: " + url);
142 | }
143 | }
144 |
145 | public SmsMultiSenderResult sendWithParam(String nationCode, String[] phoneNumbers,
146 | int templateId, String[] params, String sign, String extend, String ext)
147 | throws HTTPException, JSONException, IOException {
148 |
149 | return sendWithParam(nationCode, new ArrayList(Arrays.asList(phoneNumbers)),
150 | templateId, new ArrayList(Arrays.asList(params)),
151 | sign, extend, ext);
152 | }
153 |
154 | private ArrayList toTel(String nationCode, ArrayList phoneNumbers) {
155 | ArrayList phones = new ArrayList();
156 | for (String phoneNumber: phoneNumbers) {
157 | JSONObject phone = new JSONObject();
158 | phone.put("nationcode", nationCode);
159 | phone.put("mobile", phoneNumber);
160 | phones.add(phone);
161 | }
162 | return phones;
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsMultiSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONObject;
7 | import org.json.JSONException;
8 |
9 | import java.util.ArrayList;
10 |
11 |
12 | public class SmsMultiSenderResult extends SmsResultBase {
13 |
14 | public class Detail {
15 |
16 | public int result;
17 | public String errmsg = "";
18 | public String mobile = "";
19 | public String nationcode = "";
20 | public String sid = "";
21 | public int fee = 0;
22 |
23 | public String toString() {
24 | String[] fields = {"result", "errmsg", "mobile", "nationcode", "sid", "fee"};
25 | return (new JSONObject(this, fields)).toString();
26 | }
27 |
28 | public Detail parse(JSONObject json) throws JSONException {
29 |
30 | result = json.getInt("result");
31 | errmsg = json.getString("errmsg");
32 |
33 | if (json.has("mobile")) {
34 | mobile = json.getString("mobile");
35 | }
36 | if (json.has("nationcode")) {
37 | nationcode = json.getString("nationcode");
38 | }
39 | if (json.has("sid")) {
40 | sid = json.getString("sid");
41 | }
42 | if (json.has("fee")) {
43 | fee = json.getInt("fee");
44 | }
45 |
46 | return this;
47 | }
48 | }
49 |
50 | public int result;
51 | public String errMsg;
52 | public String ext;
53 | public ArrayList details;
54 |
55 | public SmsMultiSenderResult() {
56 | this.errMsg = "";
57 | this.ext = "";
58 | this.details = new ArrayList();
59 | }
60 |
61 | @Override
62 | public SmsMultiSenderResult parseFromHTTPResponse(HTTPResponse response)
63 | throws JSONException {
64 |
65 | JSONObject json = parseToJson(response);
66 |
67 | result = json.getInt("result");
68 | errMsg = json.getString("errmsg");
69 |
70 | if (json.has("ext")) {
71 | ext = json.getString("ext");
72 | }
73 | if (json.has("detail") && !json.isNull("detail")) {
74 | JSONArray jsonDetail = json.getJSONArray("detail");
75 | for (int i = 0; i < jsonDetail.length(); i++) {
76 | details.add((new Detail()).parse(jsonDetail.getJSONObject(i)));
77 | }
78 | }
79 |
80 |
81 | return this;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsResultBase.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import org.json.JSONObject;
4 | import org.json.JSONException;
5 |
6 | import com.github.qcloudsms.httpclient.HTTPResponse;
7 |
8 |
9 | /**
10 | * Sms result base class
11 | *
12 | * @since 1.0.0
13 | */
14 | public abstract class SmsResultBase {
15 |
16 | protected HTTPResponse response;
17 |
18 | /**
19 | * Parse result from HTTPResponse
20 | *
21 | * @param response HTTP response from api return
22 | * @return SmsResultbase
23 | * @throws JSONException json parse exception
24 | */
25 | public abstract SmsResultBase parseFromHTTPResponse(HTTPResponse response)
26 | throws JSONException;
27 |
28 | /**
29 | * Parse HTTP response to JSONObject
30 | *
31 | * @param response HTTP response
32 | * @return JSONObject
33 | * @throws JSONException json parse exception
34 | */
35 | public JSONObject parseToJson(HTTPResponse response) throws JSONException {
36 | // Set raw response
37 | this.response = response;
38 | // May throw JSONException
39 | return new JSONObject(response.body);
40 | }
41 |
42 | /**
43 | * Get raw response
44 | *
45 | * @return HTTPResponse
46 | */
47 | public HTTPResponse getResponse() {
48 | return response;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return response.body;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsSenderUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import java.lang.StringBuffer;
4 | import java.util.Random;
5 | import java.util.ArrayList;
6 |
7 | import org.apache.commons.codec.digest.DigestUtils;
8 |
9 |
10 | public class SmsSenderUtil {
11 |
12 | public static boolean isNotEmpty(String s) {
13 | if (s == null || s.isEmpty())
14 | return false;
15 | return true;
16 | }
17 |
18 | public static long getCurrentTime() {
19 | return System.currentTimeMillis() / 1000;
20 | }
21 |
22 | public static long getRandom() {
23 | return (new Random(SmsSenderUtil.getCurrentTime())).nextInt(900000) + 100000;
24 | }
25 |
26 | public static String calculateSignature(String appkey, long random, long time,
27 | String phoneNumber) {
28 |
29 | StringBuffer buffer = new StringBuffer("appkey=")
30 | .append(appkey)
31 | .append("&random=")
32 | .append(random)
33 | .append("&time=")
34 | .append(time)
35 | .append("&mobile=")
36 | .append(phoneNumber);
37 |
38 | return sha256(buffer.toString());
39 | }
40 |
41 | public static String calculateSignature(String appkey, long random, long time,
42 | String[] phoneNumbers) {
43 |
44 | StringBuffer buffer = new StringBuffer("appkey=")
45 | .append(appkey)
46 | .append("&random=")
47 | .append(random)
48 | .append("&time=")
49 | .append(time)
50 | .append("&mobile=");
51 |
52 | if (phoneNumbers.length > 0) {
53 | buffer.append(phoneNumbers[0]);
54 | for (int i = 1; i < phoneNumbers.length; i++) {
55 | buffer.append(",");
56 | buffer.append(phoneNumbers[i]);
57 | }
58 | }
59 |
60 | return sha256(buffer.toString());
61 | }
62 |
63 | public static String calculateSignature(String appkey, long random, long time,
64 | ArrayList phoneNumbers) {
65 | return calculateSignature(appkey, random, time, phoneNumbers.toArray(new String[0]));
66 | }
67 |
68 | public static String calculateSignature(String appkey, long random, long time) {
69 |
70 | StringBuffer buffer = new StringBuffer("appkey=")
71 | .append(appkey)
72 | .append("&random=")
73 | .append(random)
74 | .append("&time=")
75 | .append(time);
76 |
77 | return sha256(buffer.toString());
78 | }
79 |
80 | public static String calculateFStatusSignature(String appkey, long random,
81 | long time, String fid) {
82 |
83 | StringBuffer buffer = new StringBuffer("appkey=")
84 | .append(appkey)
85 | .append("&random=")
86 | .append(random)
87 | .append("&time=")
88 | .append(time)
89 | .append("&fid=")
90 | .append(fid);
91 |
92 | return sha256(buffer.toString());
93 | }
94 |
95 | public static String calculateAuth(String appkey, long random, long time, String fileSha1Sum) {
96 | StringBuffer buffer = new StringBuffer("appkey=")
97 | .append(appkey)
98 | .append("&random=")
99 | .append(random)
100 | .append("&time=")
101 | .append(time)
102 | .append("&content-sha1=")
103 | .append(fileSha1Sum);
104 |
105 | return sha256(buffer.toString());
106 | }
107 |
108 | public static String sha1sum(String rawString) {
109 | return DigestUtils.sha1Hex(rawString);
110 | }
111 |
112 | public static String sha1sum(byte[] bytes) {
113 | return DigestUtils.sha1Hex(bytes);
114 | }
115 |
116 | public static String sha256(String rawString) {
117 | return DigestUtils.sha256Hex(rawString);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsSingleSender.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 | import java.util.ArrayList;
16 | import java.util.Arrays;
17 |
18 |
19 | public class SmsSingleSender extends SmsBase {
20 |
21 | private String url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms";
22 |
23 | public SmsSingleSender(int appid, String appkey) {
24 | super(appid, appkey, new DefaultHTTPClient());
25 | }
26 |
27 | public SmsSingleSender(int appid, String appkey, HTTPClient httpclient) {
28 | super(appid, appkey, httpclient);
29 | }
30 |
31 | /**
32 | * 普通单发
33 | *
34 | * 普通单发短信接口,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
35 | *
36 | * @param type 短信类型,0 为普通短信,1 营销短信
37 | * @param nationCode 国家码,如 86 为中国
38 | * @param phoneNumber 不带国家码的手机号
39 | * @param msg 信息内容,必须与申请的模板格式一致,否则将返回错误
40 | * @param extend 扩展码,可填空
41 | * @param ext 服务端原样返回的参数,可填空
42 | * @return {@link}SmsSingleSenderResult
43 | * @throws HTTPException http status exception
44 | * @throws JSONException json parse exception
45 | * @throws IOException network problem
46 | */
47 | public SmsSingleSenderResult send(int type, String nationCode, String phoneNumber,
48 | String msg, String extend, String ext)
49 | throws HTTPException, JSONException, IOException {
50 |
51 | long random = SmsSenderUtil.getRandom();
52 | long now = SmsSenderUtil.getCurrentTime();
53 | JSONObject body = new JSONObject()
54 | .put("tel", (new JSONObject()).put("nationcode", nationCode).put("mobile", phoneNumber))
55 | .put("type", type)
56 | .put("msg", msg)
57 | .put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber))
58 | .put("time", now)
59 | .put("extend", SmsSenderUtil.isNotEmpty(extend) ? extend : "")
60 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
61 |
62 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
63 | .addHeader("Conetent-Type", "application/json")
64 | .addQueryParameter("sdkappid", this.appid)
65 | .addQueryParameter("random", random)
66 | .setConnectionTimeout(60 * 1000)
67 | .setRequestTimeout(60 * 1000)
68 | .setBody(body.toString());
69 |
70 | // TODO Handle timeout exception
71 | try {
72 | // May throw IOException and URISyntaxexception
73 | HTTPResponse res = httpclient.fetch(req);
74 |
75 | // May throw HTTPException
76 | handleError(res);
77 |
78 | // May throw JSONException
79 | return (new SmsSingleSenderResult()).parseFromHTTPResponse(res);
80 | } catch(URISyntaxException e) {
81 | throw new RuntimeException("API url has been modified, current url: " + url);
82 | }
83 | }
84 |
85 | /**
86 | * 指定模板单发
87 | *
88 | * @param nationCode 国家码,如 86 为中国
89 | * @param phoneNumber 不带国家码的手机号
90 | * @param templateId 信息内容
91 | * @param params 模板参数列表,如模板 {1}...{2}...{3},那么需要带三个参数
92 | * @param sign 签名,如果填空,系统会使用默认签名
93 | * @param extend 扩展码,可填空
94 | * @param ext 服务端原样返回的参数,可填空
95 | * @return {@link}SmsSingleSenderResult
96 | * @throws HTTPException http status exception
97 | * @throws JSONException json parse exception
98 | * @throws IOException network problem
99 | */
100 | public SmsSingleSenderResult sendWithParam(String nationCode, String phoneNumber, int templateId,
101 | ArrayList params, String sign, String extend, String ext)
102 | throws HTTPException, JSONException, IOException {
103 |
104 | long random = SmsSenderUtil.getRandom();
105 | long now = SmsSenderUtil.getCurrentTime();
106 |
107 | JSONObject body = new JSONObject()
108 | .put("tel", (new JSONObject()).put("nationcode", nationCode).put("mobile", phoneNumber))
109 | .put("sig", SmsSenderUtil.calculateSignature(appkey, random, now, phoneNumber))
110 | .put("tpl_id", templateId)
111 | .put("params", params)
112 | .put("sign", sign)
113 | .put("time", now)
114 | .put("extend", SmsSenderUtil.isNotEmpty(extend) ? extend : "")
115 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
116 |
117 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
118 | .addHeader("Conetent-Type", "application/json")
119 | .addQueryParameter("sdkappid", this.appid)
120 | .addQueryParameter("random", random)
121 | .setConnectionTimeout(60 * 1000)
122 | .setRequestTimeout(60 * 1000)
123 | .setBody(body.toString());
124 |
125 | try {
126 | // May throw IOException and URISyntaxexception
127 | HTTPResponse res = httpclient.fetch(req);
128 |
129 | // May throw HTTPException
130 | handleError(res);
131 |
132 | // May throw JSONException
133 | return (new SmsSingleSenderResult()).parseFromHTTPResponse(res);
134 | } catch(URISyntaxException e) {
135 | throw new RuntimeException("API url has been modified, current url: " + url);
136 | }
137 | }
138 |
139 | public SmsSingleSenderResult sendWithParam(String nationCode, String phoneNumber, int templateId,
140 | String[] params, String sign, String extend, String ext)
141 | throws HTTPException, JSONException, IOException {
142 |
143 | return sendWithParam(nationCode, phoneNumber, templateId,
144 | new ArrayList(Arrays.asList(params)), sign, extend, ext);
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsSingleSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import org.json.JSONObject;
4 | import org.json.JSONException;
5 |
6 | import com.github.qcloudsms.httpclient.HTTPResponse;
7 |
8 |
9 | public class SmsSingleSenderResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public String ext;
14 | public String sid;
15 | public int fee;
16 |
17 | public SmsSingleSenderResult() {
18 | this.errMsg = "";
19 | this.ext = "";
20 | this.sid = "";
21 | this.fee = 0;
22 | }
23 |
24 | @Override
25 | public SmsSingleSenderResult parseFromHTTPResponse(HTTPResponse response)
26 | throws JSONException {
27 |
28 | JSONObject json = parseToJson(response);
29 |
30 | result = json.getInt("result");
31 | errMsg = json.getString("errmsg");
32 | if (json.has("sid")) {
33 | sid = json.getString("sid");
34 | }
35 | if (json.has("fee")) {
36 | fee = json.getInt("fee");
37 | }
38 | if (json.has("ext")) {
39 | ext = json.getString("ext");
40 | }
41 |
42 | return this;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsStatusPullCallbackResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONObject;
7 | import org.json.JSONException;
8 |
9 | import java.util.ArrayList;
10 |
11 |
12 | public class SmsStatusPullCallbackResult extends SmsResultBase {
13 |
14 | public class Callback {
15 | public String user_receive_time;
16 | public String nationcode;
17 | public String mobile;
18 | public String report_status;
19 | public String errmsg;
20 | public String description;
21 | public String sid;
22 |
23 | @Override
24 | public String toString() {
25 | String[] fields = {
26 | "user_receive_time", "nationcode", "mobile",
27 | "report_status", "errmsg", "description",
28 | "sid"
29 | };
30 | return (new JSONObject(this, fields)).toString();
31 | }
32 |
33 | public Callback parse(JSONObject json) throws JSONException {
34 |
35 | if (json.has("user_receive_time")) {
36 | user_receive_time = json.getString("user_receive_time");
37 | }
38 | if (json.has("nationcode")) {
39 | nationcode = json.getString("nationcode");
40 | }
41 | if (json.has("mobile")) {
42 | mobile = json.getString("mobile");
43 | }
44 | if (json.has("report_status")) {
45 | report_status = json.getString("report_status");
46 | }
47 | if (json.has("errmsg")) {
48 | errmsg = json.getString("errmsg");
49 | }
50 | if (json.has("description")) {
51 | description = json.getString("description");
52 | }
53 | if (json.has("sid")) {
54 | sid = json.getString("sid");
55 | }
56 |
57 | return this;
58 | }
59 | }
60 |
61 | public int result;
62 | public String errMsg;
63 | public int count;
64 | public ArrayList callbacks;
65 |
66 | public SmsStatusPullCallbackResult() {
67 | this.errMsg = "";
68 | this.count = 0;
69 | this.callbacks = new ArrayList();
70 | }
71 |
72 | @Override
73 | public SmsStatusPullCallbackResult parseFromHTTPResponse(HTTPResponse response)
74 | throws JSONException {
75 |
76 | JSONObject json = parseToJson(response);
77 |
78 | result = json.getInt("result");
79 | errMsg = json.getString("errmsg");
80 | if (json.has("count")) {
81 | count = json.getInt("count");
82 | }
83 |
84 | if (json.has("data") && !json.isNull("data")) {
85 | JSONArray data = json.getJSONArray("data");
86 | for (int i = 0; i < data.length(); i++) {
87 | callbacks.add((new Callback()).parse(data.getJSONObject(i)));
88 | }
89 | }
90 |
91 | return this;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsStatusPullReplyResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONObject;
7 | import org.json.JSONException;
8 |
9 | import java.util.ArrayList;
10 |
11 |
12 | public class SmsStatusPullReplyResult extends SmsResultBase {
13 |
14 | public class Reply {
15 |
16 | public String nationcode;
17 | public String mobile;
18 | public String text;
19 | public String sign;
20 | public long time;
21 | public String extend;
22 |
23 | @Override
24 | public String toString(){
25 | String[] fields = {"nationcode", "mobile", "text", "sign", "time", "extend"};
26 | return (new JSONObject(this, fields)).toString();
27 | }
28 |
29 | public Reply parse(JSONObject json) throws JSONException {
30 |
31 | if (json.has("nationcode")) {
32 | nationcode = json.getString("nationcode");
33 | }
34 | if (json.has("mobile")) {
35 | mobile = json.getString("mobile");
36 | }
37 | if (json.has("text")) {
38 | text = json.getString("text");
39 | }
40 | if (json.has("text")) {
41 | sign = json.getString("text");
42 | }
43 | if (json.has("time")) {
44 | time = json.getLong("time");
45 | }
46 | if (json.has("extend")) {
47 | extend = json.getString("extend");
48 | }
49 |
50 | return this;
51 | }
52 | }
53 |
54 | public int result;
55 | public String errMsg;
56 | public int count;
57 | public ArrayList replys;
58 |
59 | public SmsStatusPullReplyResult() {
60 | this.errMsg = "";
61 | this.count = 0;
62 | this.replys = new ArrayList();
63 | }
64 |
65 | @Override
66 | public SmsStatusPullReplyResult parseFromHTTPResponse(HTTPResponse response)
67 | throws JSONException {
68 |
69 | JSONObject json = parseToJson(response);
70 |
71 | result = json.getInt("result");
72 | errMsg = json.getString("errmsg");
73 | if (json.has("count")) {
74 | count = json.getInt("count");
75 | }
76 |
77 | if (json.has("data") && !json.isNull("data")) {
78 | JSONArray data = json.getJSONArray("data");
79 | for (int i = 0; i < data.length(); i++) {
80 | replys.add((new Reply()).parse(data.getJSONObject(i)));
81 | }
82 | }
83 |
84 | return this;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsStatusPuller.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 |
16 |
17 | public class SmsStatusPuller extends SmsBase {
18 |
19 | private String url = "https://yun.tim.qq.com/v5/tlssmssvr/pullstatus";
20 |
21 | public SmsStatusPuller(int appid, String appkey) {
22 | super(appid, appkey, new DefaultHTTPClient());
23 | }
24 |
25 | public SmsStatusPuller(int appid, String appkey, HTTPClient httpclient) {
26 | super(appid, appkey, httpclient);
27 | }
28 |
29 | private HTTPResponse pull(int type, int max) throws IOException {
30 |
31 | long random = SmsSenderUtil.getRandom();
32 | long now = SmsSenderUtil.getCurrentTime();
33 | JSONObject body = new JSONObject()
34 | .put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now))
35 | .put("time", now)
36 | .put("type", type)
37 | .put("max", max);
38 |
39 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
40 | .addHeader("Conetent-Type", "application/json")
41 | .addQueryParameter("sdkappid", this.appid)
42 | .addQueryParameter("random", random)
43 | .setConnectionTimeout(60 * 1000)
44 | .setRequestTimeout(60 * 10000)
45 | .setBody(body.toString());
46 |
47 | try {
48 | // May throw IOException and URISyntaxexception
49 | return httpclient.fetch(req);
50 | } catch(URISyntaxException e) {
51 | throw new RuntimeException("API url has been modified, current url: " + url);
52 | }
53 | }
54 |
55 | /**
56 | * 拉取回执结果
57 | *
58 | * @param max 最大条数, 最多100
59 | * @return {@link}SmsStatusPullCallbackResult
60 | * @throws HTTPException http status exception
61 | * @throws JSONException json parse exception
62 | * @throws IOException network problem
63 | */
64 | public SmsStatusPullCallbackResult pullCallback(int max)
65 | throws HTTPException, JSONException, IOException {
66 |
67 | // May throw IOException
68 | HTTPResponse res = pull(0, max);
69 |
70 | // May throw HTTPException
71 | handleError(res);
72 |
73 | // May throw JSONException
74 | return (new SmsStatusPullCallbackResult()).parseFromHTTPResponse(res);
75 | }
76 |
77 |
78 | /**
79 | * 拉取回复信息
80 | *
81 | * @param max 最大条数, 最多100
82 | * @return {@link}SmsStatusPullReplyResult
83 | * @throws HTTPException http status exception
84 | * @throws JSONException json parse exception
85 | * @throws IOException network problem
86 | */
87 | public SmsStatusPullReplyResult pullReply(int max)
88 | throws HTTPException, JSONException, IOException {
89 |
90 | // May throw IOException
91 | HTTPResponse res = pull(1, max);
92 |
93 | // May throw HTTPException
94 | handleError(res);
95 |
96 | // May throw JSONException
97 | return (new SmsStatusPullReplyResult()).parseFromHTTPResponse(res);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsVoicePromptSender.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 | import java.util.ArrayList;
16 |
17 |
18 | public class SmsVoicePromptSender extends SmsBase {
19 |
20 | private String url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/sendvoiceprompt";
21 |
22 | public SmsVoicePromptSender(int appid, String appkey) {
23 | super(appid, appkey, new DefaultHTTPClient());
24 | }
25 |
26 | public SmsVoicePromptSender(int appid, String appkey, HTTPClient httpclient) {
27 | super(appid, appkey, httpclient);
28 | }
29 |
30 | /**
31 | * 发送语音短信
32 | *
33 | * @param nationCode 国家码,如 86 为中国
34 | * @param phoneNumber 不带国家码的手机号
35 | * @param prompttype 类型,目前固定值为2
36 | * @param playtimes 播放次数
37 | * @param msg 语音通知消息内容
38 | * @param ext "扩展字段,原样返回"
39 | * @return {@link}SmsVoicePromptSenderResult
40 | * @throws HTTPException http status exception
41 | * @throws JSONException json parse exception
42 | * @throws IOException network problem
43 | */
44 | public SmsVoicePromptSenderResult send(String nationCode, String phoneNumber, int prompttype,
45 | int playtimes, String msg, String ext)
46 | throws HTTPException, JSONException, IOException {
47 |
48 | long random = SmsSenderUtil.getRandom();
49 | long now = SmsSenderUtil.getCurrentTime();
50 | JSONObject body = new JSONObject()
51 | .put("tel", (new JSONObject()).put("nationcode", nationCode).put("mobile", phoneNumber))
52 | .put("prompttype", prompttype)
53 | .put("promptfile", msg)
54 | .put("playtimes", playtimes)
55 | .put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber))
56 | .put("time", now)
57 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
58 |
59 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
60 | .addHeader("Conetent-Type", "application/json")
61 | .addQueryParameter("sdkappid", this.appid)
62 | .addQueryParameter("random", random)
63 | .setConnectionTimeout(60 * 1000)
64 | .setRequestTimeout(60 * 1000)
65 | .setBody(body.toString());
66 |
67 |
68 | try {
69 | // May throw IOException and URISyntaxexception
70 | HTTPResponse res = httpclient.fetch(req);
71 |
72 | // May throw HTTPException
73 | handleError(res);
74 |
75 | // May throw JSONException
76 | return (new SmsVoicePromptSenderResult()).parseFromHTTPResponse(res);
77 | } catch(URISyntaxException e) {
78 | throw new RuntimeException("API url has been modified, current url: " + url);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsVoicePromptSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONObject;
6 | import org.json.JSONException;
7 |
8 |
9 | public class SmsVoicePromptSenderResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public String ext;
14 | public String callid;
15 |
16 | public SmsVoicePromptSenderResult() {
17 | this.errMsg = "";
18 | this.ext = "";
19 | this.callid = "";
20 | }
21 |
22 | @Override
23 | public SmsVoicePromptSenderResult parseFromHTTPResponse(HTTPResponse response)
24 | throws JSONException {
25 |
26 | JSONObject json = parseToJson(response);
27 |
28 | result = json.getInt("result");
29 | errMsg = json.getString("errmsg");
30 |
31 | if (json.has("ext")) {
32 | ext = json.getString("ext");
33 | }
34 | if (json.has("callid")) {
35 | callid = json.getString("callid");
36 | }
37 |
38 | return this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsVoiceVerifyCodeSender.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 |
16 |
17 | public class SmsVoiceVerifyCodeSender extends SmsBase {
18 |
19 | private String url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/sendcvoice";
20 |
21 | public SmsVoiceVerifyCodeSender(int appid, String appkey) {
22 | super(appid, appkey, new DefaultHTTPClient());
23 | }
24 |
25 | public SmsVoiceVerifyCodeSender(int appid, String appkey, HTTPClient httpclient) {
26 | super(appid, appkey, httpclient);
27 | }
28 |
29 | /**
30 | * 发送语音短信
31 | *
32 | * @param nationCode 国家码,如 86 为中国
33 | * @param phoneNumber 不带国家码的手机号
34 | * @param msg 消息类型
35 | * @param playtimes 播放次数
36 | * @param ext 服务端原样返回的参数,可填空
37 | * @return {@link}SmsVoiceVerifyCodeSenderResult
38 | * @throws HTTPException http status exception
39 | * @throws JSONException json parse exception
40 | * @throws IOException network problem
41 | */
42 | public SmsVoiceVerifyCodeSenderResult send(String nationCode, String phoneNumber, String msg,
43 | int playtimes, String ext)
44 | throws HTTPException, JSONException, IOException {
45 |
46 | long random = SmsSenderUtil.getRandom();
47 | long now = SmsSenderUtil.getCurrentTime();
48 | JSONObject body = new JSONObject();
49 | body.put("tel", (new JSONObject()).put("nationcode", nationCode).put("mobile", phoneNumber))
50 | .put("msg", msg)
51 | .put("playtimes", playtimes)
52 | .put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber))
53 | .put("time", now)
54 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
55 |
56 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
57 | .addHeader("Conetent-Type", "application/json")
58 | .addQueryParameter("sdkappid", this.appid)
59 | .addQueryParameter("random", random)
60 | .setConnectionTimeout(60 * 1000)
61 | .setRequestTimeout(60 * 1000)
62 | .setBody(body.toString());
63 |
64 | try {
65 | // May throw IOException
66 | HTTPResponse res = httpclient.fetch(req);
67 |
68 | // May throw HTTPException
69 | handleError(res);
70 |
71 | // May throw JSONException
72 | return (new SmsVoiceVerifyCodeSenderResult()).parseFromHTTPResponse(res);
73 | } catch(URISyntaxException e) {
74 | throw new RuntimeException("API url has been modified, current url: " + url);
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/SmsVoiceVerifyCodeSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONObject;
6 | import org.json.JSONException;
7 |
8 |
9 | public class SmsVoiceVerifyCodeSenderResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public String ext;
14 | public String callid;
15 |
16 | public SmsVoiceVerifyCodeSenderResult() {
17 | this.errMsg = "";
18 | this.ext = "";
19 | this.callid = "";
20 | }
21 |
22 | @Override
23 | public SmsVoiceVerifyCodeSenderResult parseFromHTTPResponse(HTTPResponse response)
24 | throws JSONException {
25 |
26 | JSONObject json = parseToJson(response);
27 |
28 | result = json.getInt("result");
29 | errMsg = json.getString("errmsg");
30 |
31 | if (json.has("ext")) {
32 | ext = json.getString("ext");
33 | }
34 | if (json.has("callid")) {
35 | callid = json.getString("callid");
36 | }
37 |
38 | return this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/TtsVoiceSender.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.net.URISyntaxException;
15 | import java.util.ArrayList;
16 | import java.util.Arrays;
17 |
18 |
19 | public class TtsVoiceSender extends SmsBase {
20 |
21 | private String url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/sendtvoice";
22 |
23 | public TtsVoiceSender(int appid, String appkey) {
24 | super(appid, appkey, new DefaultHTTPClient());
25 | }
26 |
27 | public TtsVoiceSender(int appid, String appkey, HTTPClient httpclient) {
28 | super(appid, appkey, httpclient);
29 | }
30 |
31 | /**
32 | * 指定模板发送语音短信
33 | *
34 | * @param nationCode 国家码,如86为中国
35 | * @param phoneNumber 不带国家码的手机号
36 | * @param templateId 信息内容
37 | * @param params 模板参数列表
38 | * @param playtimes 播放次数
39 | * @param ext 扩展字段,原样返回
40 | * @return {@link}TtsVoiceSenderResult
41 | * @throws HTTPException http status exception
42 | * @throws JSONException json parse exception
43 | * @throws IOException network problem
44 | */
45 | public TtsVoiceSenderResult send(String nationCode, String phoneNumber,
46 | int templateId, ArrayList params,
47 | int playtimes, String ext)
48 | throws HTTPException, JSONException, IOException {
49 |
50 | long random = SmsSenderUtil.getRandom();
51 | long now = SmsSenderUtil.getCurrentTime();
52 | JSONObject body = new JSONObject()
53 | .put("tel", (new JSONObject()).put("nationcode", nationCode).put("mobile", phoneNumber))
54 | .put("tpl_id", templateId)
55 | .put("params", params)
56 | .put("playtimes", playtimes)
57 | .put("sig", SmsSenderUtil.calculateSignature(this.appkey, random, now, phoneNumber))
58 | .put("time", now)
59 | .put("ext", SmsSenderUtil.isNotEmpty(ext) ? ext : "");
60 |
61 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
62 | .addHeader("Conetent-Type", "application/json")
63 | .addQueryParameter("sdkappid", this.appid)
64 | .addQueryParameter("random", random)
65 | .setConnectionTimeout(60 * 1000)
66 | .setRequestTimeout(60 * 1000)
67 | .setBody(body.toString());
68 |
69 | try {
70 | // May throw IOException and URISyntaxexception
71 | HTTPResponse res = httpclient.fetch(req);
72 |
73 | // May throw HTTPException
74 | handleError(res);
75 |
76 | // May throw JSONException
77 | return (new TtsVoiceSenderResult()).parseFromHTTPResponse(res);
78 | } catch(URISyntaxException e) {
79 | throw new RuntimeException("API url has been modified, current url: " + url);
80 | }
81 | }
82 |
83 | public TtsVoiceSenderResult send(String nationCode, String phoneNumber,
84 | int templateId, String[] params,
85 | int playtimes, String ext)
86 | throws HTTPException, JSONException, IOException {
87 |
88 | return send(nationCode, phoneNumber, templateId,
89 | new ArrayList(Arrays.asList(params)), playtimes, ext);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/TtsVoiceSenderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONObject;
6 | import org.json.JSONException;
7 |
8 |
9 | public class TtsVoiceSenderResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public String ext;
14 | public String callid;
15 |
16 | public TtsVoiceSenderResult() {
17 | this.errMsg = "";
18 | this.ext = "";
19 | this.callid = "";
20 | }
21 |
22 | @Override
23 | public TtsVoiceSenderResult parseFromHTTPResponse(HTTPResponse response)
24 | throws JSONException {
25 |
26 | JSONObject json = parseToJson(response);
27 |
28 | result = json.getInt("result");
29 | errMsg = json.getString("errmsg");
30 |
31 | if (json.has("ext")) {
32 | ext = json.getString("ext");
33 | }
34 | if (json.has("callid")) {
35 | callid = json.getString("callid");
36 | }
37 |
38 | return this;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/VoiceFileStatus.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.nio.charset.StandardCharsets;
15 | import java.net.URISyntaxException;
16 |
17 |
18 | public class VoiceFileStatus extends SmsBase {
19 |
20 | private String url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/statusvoicefile";
21 |
22 | public VoiceFileStatus(int appid, String appkey) {
23 | super(appid, appkey, new DefaultHTTPClient());
24 | }
25 |
26 | public VoiceFileStatus(int appid, String appkey, HTTPClient httpclient) {
27 | super(appid, appkey, httpclient);
28 | }
29 |
30 | /**
31 | * 查询语音文件审核状态
32 | *
33 | * @param fid 语音文件fid
34 | * @return {@link}VoiceFileStatusResult
35 | * @throws HTTPException http status exception
36 | * @throws JSONException json parse exception
37 | * @throws IOException network problem
38 | */
39 | public VoiceFileStatusResult get(String fid)
40 | throws HTTPException, JSONException, IOException {
41 |
42 | long random = SmsSenderUtil.getRandom();
43 | long now = SmsSenderUtil.getCurrentTime();
44 | JSONObject body = new JSONObject()
45 | .put("fid", fid)
46 | .put("sig", SmsSenderUtil.calculateFStatusSignature(
47 | this.appkey, random, now, fid))
48 | .put("time", now);
49 |
50 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
51 | .addHeader("Conetent-Type", "application/json")
52 | .addQueryParameter("sdkappid", this.appid)
53 | .addQueryParameter("random", random)
54 | .setConnectionTimeout(60 * 1000)
55 | .setRequestTimeout(60 * 1000)
56 | .setBody(body.toString());
57 |
58 | try {
59 | // May throw IOException and URISyntaxexception
60 | HTTPResponse res = httpclient.fetch(req);
61 |
62 | // May throw HTTPException
63 | handleError(res);
64 |
65 | // May throw JSONException
66 | return (new VoiceFileStatusResult()).parseFromHTTPResponse(res);
67 | } catch(URISyntaxException e) {
68 | throw new RuntimeException("API url has been modified, current url: " + url);
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/VoiceFileStatusResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONObject;
6 | import org.json.JSONException;
7 |
8 |
9 | public class VoiceFileStatusResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public int status;
14 |
15 | public VoiceFileStatusResult() {
16 | this.errMsg = "";
17 | }
18 |
19 | @Override
20 | public VoiceFileStatusResult parseFromHTTPResponse(HTTPResponse response)
21 | throws JSONException {
22 |
23 | JSONObject json = parseToJson(response);
24 |
25 | result = json.getInt("result");
26 | errMsg = json.getString("errmsg");
27 |
28 | if (json.has("status")) {
29 | status = json.getInt("status");
30 | }
31 |
32 | return this;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/VoiceFileUploader.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPClient;
4 | import com.github.qcloudsms.httpclient.HTTPException;
5 | import com.github.qcloudsms.httpclient.HTTPMethod;
6 | import com.github.qcloudsms.httpclient.HTTPRequest;
7 | import com.github.qcloudsms.httpclient.HTTPResponse;
8 | import com.github.qcloudsms.httpclient.DefaultHTTPClient;
9 |
10 | import org.json.JSONObject;
11 | import org.json.JSONException;
12 |
13 | import java.io.IOException;
14 | import java.nio.charset.StandardCharsets;
15 | import java.net.URISyntaxException;
16 |
17 |
18 | public class VoiceFileUploader extends SmsBase {
19 |
20 | public enum ContentType {
21 | WAV, MP3
22 | }
23 |
24 | private String url = "https://cloud.tim.qq.com/v5/tlsvoicesvr/uploadvoicefile";
25 |
26 | public VoiceFileUploader(int appid, String appkey) {
27 | super(appid, appkey, new DefaultHTTPClient());
28 | }
29 |
30 | public VoiceFileUploader(int appid, String appkey, HTTPClient httpclient) {
31 | super(appid, appkey, httpclient);
32 | }
33 |
34 | /**
35 | * 上传语音文件
36 | *
37 | * @param fileContent 语音文件内容
38 | * @param contentType 语音文件类型
39 | * @return {@link}VoiceFileUploaderResult
40 | * @throws HTTPException http status exception
41 | * @throws JSONException json parse exception
42 | * @throws IOException network problem
43 | */
44 | public VoiceFileUploaderResult upload(byte[] fileContent, ContentType contentType)
45 | throws HTTPException, JSONException, IOException {
46 |
47 | long random = SmsSenderUtil.getRandom();
48 | long now = SmsSenderUtil.getCurrentTime();
49 | String fileSha1Sum = SmsSenderUtil.sha1sum(fileContent);
50 | String auth = SmsSenderUtil.calculateAuth(this.appkey, random, now, fileSha1Sum);
51 | String type;
52 | if (contentType == ContentType.WAV) {
53 | type = "audio/wav";
54 | } else {
55 | type = "audio/mpeg";
56 | }
57 |
58 | HTTPRequest req = new HTTPRequest(HTTPMethod.POST, this.url)
59 | .addHeader("Content-Type", type)
60 | .addHeader("x-content-sha1", fileSha1Sum)
61 | .addHeader("Authorization", auth)
62 | .addQueryParameter("sdkappid", this.appid)
63 | .addQueryParameter("random", random)
64 | .addQueryParameter("time", now)
65 | .setConnectionTimeout(60 * 1000)
66 | .setRequestTimeout(60 * 1000)
67 | .setBody(new String(fileContent, StandardCharsets.ISO_8859_1))
68 | .setBodyCharset(StandardCharsets.ISO_8859_1);
69 |
70 | try {
71 | // May throw IOException and URISyntaxexception
72 | HTTPResponse res = httpclient.fetch(req);
73 |
74 | // May throw HTTPException
75 | handleError(res);
76 |
77 | // May throw JSONException
78 | return (new VoiceFileUploaderResult()).parseFromHTTPResponse(res);
79 | } catch(URISyntaxException e) {
80 | throw new RuntimeException("API url has been modified, current url: " + url);
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/VoiceFileUploaderResult.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms;
2 |
3 | import com.github.qcloudsms.httpclient.HTTPResponse;
4 |
5 | import org.json.JSONObject;
6 | import org.json.JSONException;
7 |
8 |
9 | public class VoiceFileUploaderResult extends SmsResultBase {
10 |
11 | public int result;
12 | public String errMsg;
13 | public String fid;
14 |
15 | public VoiceFileUploaderResult() {
16 | this.errMsg = "";
17 | this.fid = "";
18 | }
19 |
20 | @Override
21 | public VoiceFileUploaderResult parseFromHTTPResponse(HTTPResponse response)
22 | throws JSONException {
23 |
24 | JSONObject json = parseToJson(response);
25 |
26 | result = json.getInt("result");
27 | errMsg = json.getString("errmsg");
28 |
29 | if (json.has("fid")) {
30 | fid = json.getString("fid");
31 | }
32 |
33 | return this;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/DefaultHTTPClient.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | import org.apache.http.Header;
4 | import org.apache.http.entity.ByteArrayEntity;
5 | import org.apache.http.util.EntityUtils;
6 | import org.apache.http.client.config.RequestConfig;
7 | import org.apache.http.client.methods.CloseableHttpResponse;
8 | import org.apache.http.client.methods.RequestBuilder;
9 | import org.apache.http.client.utils.URIBuilder;
10 | import org.apache.http.impl.client.CloseableHttpClient;
11 | import org.apache.http.impl.client.HttpClients;
12 |
13 |
14 | import java.io.IOException;
15 | import java.net.URISyntaxException;
16 | import java.util.Map;
17 |
18 |
19 | public class DefaultHTTPClient implements HTTPClient {
20 |
21 | public HTTPResponse fetch(HTTPRequest request) throws IOException, URISyntaxException {
22 | // Build URI
23 | URIBuilder uriBuilder = new URIBuilder(request.url);
24 | for (Map.Entry entry: request.parameters.entrySet()) {
25 | uriBuilder.addParameter(entry.getKey(), entry.getValue());
26 | }
27 |
28 | // Build request
29 | RequestConfig reqConfig = RequestConfig.custom()
30 | .setSocketTimeout(5 * 60 * 1000)
31 | .setConnectTimeout(request.connectTimeout)
32 | .setConnectionRequestTimeout(request.requestTimeout)
33 | .build();
34 | RequestBuilder reqBuilder = RequestBuilder.create(request.method.name())
35 | .setUri(uriBuilder.build())
36 | .setEntity(new ByteArrayEntity(request.body.getBytes(request.bodyCharset)))
37 | .setConfig(reqConfig);
38 | for (Map.Entry entry: request.headers.entrySet()) {
39 | reqBuilder.setHeader(entry.getKey(), entry.getValue());
40 | }
41 |
42 | // Create http client
43 | CloseableHttpClient client = HttpClients.createDefault();
44 |
45 | // Fetch http response
46 | try {
47 | CloseableHttpResponse response = client.execute(reqBuilder.build());
48 | try {
49 | // May throw IOException
50 | HTTPResponse res = new HTTPResponse()
51 | .setRequest(request)
52 | .setStatusCode(response.getStatusLine().getStatusCode())
53 | .setReason(response.getStatusLine().getReasonPhrase())
54 | .setBody(EntityUtils.toString(response.getEntity(), "UTF-8"));
55 | for (Header header: response.getAllHeaders()) {
56 | res.addHeader(header.getName(), header.getValue());
57 | }
58 |
59 | return res;
60 | } finally {
61 | response.close();
62 | }
63 | } finally {
64 | client.close();
65 | }
66 | }
67 |
68 | public void close() {
69 | // Do nothing
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/HTTPClient.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | import java.io.IOException;
4 | import java.net.URISyntaxException;
5 |
6 | /**
7 | * HTTPClient interface
8 | *
9 | * @since 1.0.0
10 | */
11 | public interface HTTPClient {
12 |
13 | /**
14 | * Fetch HTTP response by given HTTP request,
15 | *
16 | * @param request Specify which to be fetched.
17 | *
18 | * @return the response to the request.
19 | * @throws IOException connection problem.
20 | * @throws URISyntaxException url syntax problem.
21 | */
22 | HTTPResponse fetch(HTTPRequest request)
23 | throws IOException, URISyntaxException;
24 |
25 | /**
26 | * Close http client and release resource
27 | *
28 | */
29 | void close();
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/HTTPException.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 |
4 | public class HTTPException extends Exception {
5 |
6 | private final int statusCode;
7 | private final String reason;
8 |
9 | public HTTPException(final int statusCode, final String reason) {
10 | super("HTTP statusCode: " + statusCode + ", reasons: " + reason);
11 | this.reason = reason;
12 | this.statusCode = statusCode;
13 | }
14 |
15 | public int getStatusCode() {
16 | return statusCode;
17 | }
18 |
19 | public String getReason() {
20 | return reason;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/HTTPMethod.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | public enum HTTPMethod {
4 | GET, POST, HEAD, PATCH,
5 | PUT, DLETE, OPTIONS
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/HTTPRequest.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | import java.util.HashMap;
4 | import java.nio.charset.Charset;
5 | import java.nio.charset.StandardCharsets;
6 |
7 |
8 | public class HTTPRequest {
9 |
10 | public String url;
11 | public HTTPMethod method;
12 | public String body;
13 | public HashMap headers;
14 | public HashMap parameters;
15 | public int connectTimeout;
16 | public int requestTimeout;
17 | public Charset bodyCharset;
18 |
19 | public HTTPRequest(final HTTPMethod method, final String url) {
20 | super();
21 | this.method = method;
22 | this.url = url;
23 |
24 | this.headers = new HashMap();
25 | this.parameters = new HashMap();
26 | this.bodyCharset = StandardCharsets.UTF_8;
27 | }
28 |
29 | public HTTPRequest setBody(String body) {
30 | this.body = body;
31 | return this;
32 | }
33 |
34 | public HTTPRequest setBodyCharset(Charset charset) {
35 | this.bodyCharset = charset;
36 | return this;
37 | }
38 |
39 | public HTTPRequest addHeader(String name, String value) {
40 | headers.put(name, value);
41 | return this;
42 | }
43 |
44 | public HTTPRequest addQueryParameter(String name, String value) {
45 | parameters.put(name, value);
46 | return this;
47 | }
48 |
49 | public HTTPRequest addQueryParameter(String name, int value) {
50 | parameters.put(name, String.valueOf(value));
51 | return this;
52 | }
53 |
54 | public HTTPRequest addQueryParameter(String name, long value) {
55 | parameters.put(name, String.valueOf(value));
56 | return this;
57 | }
58 |
59 | public HTTPRequest setConnectionTimeout(int connectionTimeout) {
60 | this.connectTimeout = connectionTimeout;
61 | return this;
62 | }
63 |
64 | public HTTPRequest setRequestTimeout(int requestTimeout) {
65 | this.requestTimeout = requestTimeout;
66 | return this;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/HTTPResponse.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | import java.util.HashMap;
4 |
5 |
6 | public class HTTPResponse {
7 |
8 | public HTTPRequest request;
9 | public int statusCode;
10 | public String reason;
11 | public String body;
12 | public HashMap headers;
13 |
14 | public HTTPResponse() {
15 | this.headers = new HashMap();
16 | }
17 |
18 | public HTTPResponse(final int statusCode) {
19 | this();
20 | this.statusCode = statusCode;
21 | }
22 |
23 | public HTTPResponse(final int statusCode, final String body) {
24 | super();
25 | this.statusCode = statusCode;
26 | this.body = body;
27 | }
28 |
29 | public HTTPResponse(final int statusCode, final String body, final String reason) {
30 | super();
31 | this.statusCode = statusCode;
32 | this.body = body;
33 | this.reason = reason;
34 | }
35 |
36 | public HTTPResponse setStatusCode(int statusCode) {
37 | this.statusCode = statusCode;
38 | return this;
39 | }
40 |
41 | public HTTPResponse setBody(String body) {
42 | this.body = body;
43 | return this;
44 | }
45 |
46 | public HTTPResponse setReason(String reason) {
47 | this.reason = reason;
48 | return this;
49 | }
50 |
51 | public HTTPResponse addHeader(String name, String value) {
52 | headers.put(name, value);
53 | return this;
54 | }
55 |
56 | public HTTPResponse setRequest(HTTPRequest request) {
57 | this.request = request;
58 | return this;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/PoolingHTTPClient.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | import org.apache.http.Header;
4 | import org.apache.http.entity.ByteArrayEntity;
5 | import org.apache.http.util.EntityUtils;
6 | import org.apache.http.client.config.RequestConfig;
7 | import org.apache.http.client.methods.CloseableHttpResponse;
8 | import org.apache.http.client.methods.RequestBuilder;
9 | import org.apache.http.client.protocol.HttpClientContext;
10 | import org.apache.http.client.utils.URIBuilder;
11 | import org.apache.http.impl.client.CloseableHttpClient;
12 | import org.apache.http.impl.client.HttpClients;
13 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
14 |
15 | import java.io.IOException;
16 | import java.net.URISyntaxException;
17 | import java.util.Map;
18 |
19 |
20 | public class PoolingHTTPClient implements HTTPClient {
21 |
22 | private PoolingHttpClientConnectionManager connMgr;
23 | private CloseableHttpClient client;
24 |
25 | public PoolingHTTPClient(int maxConnection) {
26 | this.connMgr = new PoolingHttpClientConnectionManager();
27 | connMgr.setMaxTotal(maxConnection);
28 |
29 | this.client = HttpClients.custom()
30 | .setConnectionManager(this.connMgr)
31 | .build();
32 | }
33 |
34 | public PoolingHTTPClient() {
35 | this(100);
36 | }
37 |
38 | public HTTPResponse fetch(HTTPRequest request) throws IOException, URISyntaxException {
39 | // Build URI
40 | URIBuilder uriBuilder = new URIBuilder(request.url);
41 | for (Map.Entry entry: request.parameters.entrySet()) {
42 | uriBuilder.addParameter(entry.getKey(), entry.getValue());
43 | }
44 |
45 | // Build request
46 | RequestConfig reqConfig = RequestConfig.custom()
47 | .setConnectTimeout(request.connectTimeout)
48 | .setConnectionRequestTimeout(request.requestTimeout)
49 | .build();
50 | RequestBuilder reqBuilder = RequestBuilder.create(request.method.name())
51 | .setUri(uriBuilder.build())
52 | .setEntity(new ByteArrayEntity(request.body.getBytes(request.bodyCharset)))
53 | .setConfig(reqConfig);
54 | for (Map.Entry entry: request.headers.entrySet()) {
55 | reqBuilder.setHeader(entry.getKey(), entry.getValue());
56 | }
57 |
58 | // Fetch http response
59 | HttpClientContext ctx = HttpClientContext.create();
60 | CloseableHttpResponse response = client.execute(reqBuilder.build(), ctx);
61 | try {
62 | // May throw IOException
63 | HTTPResponse res = new HTTPResponse()
64 | .setRequest(request)
65 | .setStatusCode(response.getStatusLine().getStatusCode())
66 | .setReason(response.getStatusLine().getReasonPhrase())
67 | .setBody(EntityUtils.toString(response.getEntity(), "UTF-8"));
68 | for (Header header: response.getAllHeaders()) {
69 | res.addHeader(header.getName(), header.getValue());
70 | }
71 |
72 | return res;
73 | } finally {
74 | response.close();
75 | }
76 | }
77 |
78 | public synchronized void close() {
79 | if (client != null) {
80 | try {
81 | client.close();
82 | } catch (IOException e) {
83 | // in case of a problem or the connection was aborted
84 | }
85 | client = null;
86 | }
87 | if (connMgr != null) {
88 | connMgr.close();
89 | connMgr = null;
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/github/qcloudsms/httpclient/ProxyHTTPClient.java:
--------------------------------------------------------------------------------
1 | package com.github.qcloudsms.httpclient;
2 |
3 | import org.apache.http.HttpHost;
4 | import org.apache.http.Header;
5 | import org.apache.http.entity.ByteArrayEntity;
6 | import org.apache.http.util.EntityUtils;
7 | import org.apache.http.client.config.RequestConfig;
8 | import org.apache.http.client.methods.CloseableHttpResponse;
9 | import org.apache.http.client.methods.RequestBuilder;
10 | import org.apache.http.client.utils.URIBuilder;
11 | import org.apache.http.impl.client.CloseableHttpClient;
12 | import org.apache.http.impl.client.HttpClients;
13 |
14 |
15 | import java.io.IOException;
16 | import java.net.URISyntaxException;
17 | import java.util.Map;
18 |
19 |
20 | public class ProxyHTTPClient implements HTTPClient {
21 |
22 | private HttpHost proxy;
23 |
24 | public ProxyHTTPClient(String host) {
25 | this.proxy = new HttpHost(host);
26 | }
27 |
28 | public ProxyHTTPClient(String host, int port) {
29 | this.proxy = new HttpHost(host, port);
30 | }
31 |
32 | public ProxyHTTPClient(String host, int port, String scheme) {
33 | this.proxy = new HttpHost(host, port, scheme);
34 | }
35 |
36 | public HTTPResponse fetch(HTTPRequest request) throws IOException, URISyntaxException {
37 | // Build URI
38 | URIBuilder uriBuilder = new URIBuilder(request.url);
39 | for (Map.Entry entry: request.parameters.entrySet()) {
40 | uriBuilder.addParameter(entry.getKey(), entry.getValue());
41 | }
42 |
43 | // Build request
44 | RequestConfig reqConfig = RequestConfig.custom()
45 | .setSocketTimeout(5 * 60 * 1000)
46 | .setConnectTimeout(request.connectTimeout)
47 | .setConnectionRequestTimeout(request.requestTimeout)
48 | .setProxy(this.proxy)
49 | .build();
50 |
51 | RequestBuilder reqBuilder = RequestBuilder.create(request.method.name())
52 | .setUri(uriBuilder.build())
53 | .setEntity(new ByteArrayEntity(request.body.getBytes(request.bodyCharset)))
54 | .setConfig(reqConfig);
55 | for (Map.Entry entry: request.headers.entrySet()) {
56 | reqBuilder.setHeader(entry.getKey(), entry.getValue());
57 | }
58 |
59 | // Create http client
60 | CloseableHttpClient client = HttpClients.createDefault();
61 |
62 | // Fetch http response
63 | try {
64 | CloseableHttpResponse response = client.execute(reqBuilder.build());
65 | try {
66 | // May throw IOException
67 | HTTPResponse res = new HTTPResponse()
68 | .setRequest(request)
69 | .setStatusCode(response.getStatusLine().getStatusCode())
70 | .setReason(response.getStatusLine().getReasonPhrase())
71 | .setBody(EntityUtils.toString(response.getEntity(), "UTF-8"));
72 | for (Header header: response.getAllHeaders()) {
73 | res.addHeader(header.getName(), header.getValue());
74 | }
75 |
76 | return res;
77 | } finally {
78 | response.close();
79 | }
80 | } finally {
81 | client.close();
82 | }
83 | }
84 |
85 | public void close() {
86 | // Do nothing
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/QcloudSmsTest.java:
--------------------------------------------------------------------------------
1 | import com.github.qcloudsms.SmsSingleSender;
2 | import com.github.qcloudsms.SmsSingleSenderResult;
3 | import com.github.qcloudsms.SmsMultiSender;
4 | import com.github.qcloudsms.SmsMultiSenderResult;
5 | import com.github.qcloudsms.SmsStatusPuller;
6 | import com.github.qcloudsms.SmsMobileStatusPuller;
7 | import com.github.qcloudsms.SmsStatusPullCallbackResult;
8 | import com.github.qcloudsms.SmsStatusPullReplyResult;
9 | import com.github.qcloudsms.SmsVoiceVerifyCodeSender;
10 | import com.github.qcloudsms.SmsVoiceVerifyCodeSenderResult;
11 | import com.github.qcloudsms.SmsVoicePromptSender;
12 | import com.github.qcloudsms.SmsVoicePromptSenderResult;
13 | import com.github.qcloudsms.httpclient.HTTPException;
14 |
15 | import org.json.JSONException;
16 |
17 | import java.io.IOException;
18 |
19 |
20 | public class QcloudSmsTest {
21 |
22 | public static void main(String[] args) {
23 | // 短信应用SDK AppID
24 | int appid = 1400009099; // 1400开头
25 |
26 | // 短信应用SDK AppKey
27 | String appkey = "9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad";
28 |
29 | // 需要发送短信的手机号码
30 | String[] phoneNumbers = {"21212313123", "12345678902", "12345678903"};
31 |
32 | // 短信模板ID,需要在短信应用中申请
33 | // NOTE: 这里的模板ID`7839`只是一个示例,
34 | // 真实的模板ID需要在短信控制台中申请
35 | int templateId = 7839;
36 |
37 | // 签名
38 | // NOTE: 这里的签名"腾讯云"只是一个示例,
39 | // 真实的签名需要在短信控制台中申请,另外
40 | // 签名参数使用的是`签名内容`,而不是`签名ID`
41 | String smsSign = "腾讯云";
42 |
43 | // 单发短信
44 | try {
45 | SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
46 | SmsSingleSenderResult result = ssender.send(0, "86", phoneNumbers[0],
47 | "【腾讯云】您的验证码是: 5678", "", "");
48 | System.out.print(result);
49 | } catch (HTTPException e) {
50 | // HTTP响应码错误
51 | e.printStackTrace();
52 | } catch (JSONException e) {
53 | // json解析错误
54 | e.printStackTrace();
55 | } catch (IOException e) {
56 | // 网络IO错误
57 | e.printStackTrace();
58 | }
59 |
60 | // 指定模板ID单发短信
61 | try {
62 | String[] params = {"5678"};
63 | SmsMultiSender msender = new SmsMultiSender(appid, appkey);
64 | SmsMultiSenderResult result = msender.sendWithParam("86", phoneNumbers,
65 | templateId, params, smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
66 | System.out.print(result);
67 | } catch (HTTPException e) {
68 | // HTTP响应码错误
69 | e.printStackTrace();
70 | } catch (JSONException e) {
71 | // json解析错误
72 | e.printStackTrace();
73 | } catch (IOException e) {
74 | // 网络IO错误
75 | e.printStackTrace();
76 | }
77 |
78 | // 发送语音验证码
79 | try {
80 | SmsVoiceVerifyCodeSender vvcsender = new SmsVoiceVerifyCodeSender(appid,appkey);
81 | SmsVoiceVerifyCodeSenderResult result = vvcsender.send("86", phoneNumbers[0],
82 | "5678", 2, "");
83 | System.out.print(result);
84 | } catch (HTTPException e) {
85 | // HTTP响应码错误
86 | e.printStackTrace();
87 | } catch (JSONException e) {
88 | // json解析错误
89 | e.printStackTrace();
90 | } catch (IOException e) {
91 | // 网络IO错误
92 | e.printStackTrace();
93 | }
94 |
95 | // 发送语音通知
96 | try {
97 | SmsVoicePromptSender vpsender = new SmsVoicePromptSender(appid, appkey);
98 | SmsVoicePromptSenderResult result = vpsender.send("86", phoneNumbers[0],
99 | 2, 2, "5678", "");
100 | System.out.print(result);
101 | } catch (HTTPException e) {
102 | // HTTP响应码错误
103 | e.printStackTrace();
104 | } catch (JSONException e) {
105 | // json解析错误
106 | e.printStackTrace();
107 | } catch (IOException e) {
108 | // 网络IO错误
109 | e.printStackTrace();
110 | }
111 |
112 | // 拉取短信回执以及回复
113 | try {
114 | // Note: 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387)开通权限
115 | int maxNum = 10; // 单次拉取最大量
116 | SmsStatusPuller spuller = new SmsStatusPuller(appid, appkey);
117 |
118 | // 拉取短信回执
119 | SmsStatusPullCallbackResult callbackResult = spuller.pullCallback(maxNum);
120 | System.out.println(callbackResult);
121 |
122 | // 拉取回复
123 | SmsStatusPullReplyResult replyResult = spuller.pullReply(maxNum);
124 | System.out.println(replyResult);
125 | } catch (HTTPException e) {
126 | // HTTP响应码错误
127 | e.printStackTrace();
128 | } catch (JSONException e) {
129 | // json解析错误
130 | e.printStackTrace();
131 | } catch (IOException e) {
132 | // 网络IO错误
133 | e.printStackTrace();
134 | }
135 |
136 | // 拉取单个手机短信状态
137 | try {
138 | int beginTime = 1511125600; // 开始时间(unix timestamp)
139 | int endTime = 1511841600; // 结束时间(unix timestamp)
140 | int maxNum = 10; // 单次拉取最大量
141 | SmsMobileStatusPuller mspuller = new SmsMobileStatusPuller(appid, appkey);
142 |
143 | // 拉取短信回执
144 | SmsStatusPullCallbackResult callbackResult = mspuller.pullCallback("86",
145 | phoneNumbers[0], beginTime, endTime, maxNum);
146 | System.out.println(callbackResult);
147 |
148 | // 拉取回复
149 | SmsStatusPullReplyResult replyResult = mspuller.pullReply("86",
150 | phoneNumbers[0], beginTime, endTime, maxNum);
151 | System.out.println(replyResult);
152 | } catch (HTTPException e) {
153 | // HTTP响应码错误
154 | e.printStackTrace();
155 | } catch (JSONException e) {
156 | // json解析错误
157 | e.printStackTrace();
158 | } catch (IOException e) {
159 | // 网络IO错误
160 | e.printStackTrace();
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------