質問編集履歴
1
ソースの追加。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,9 +2,181 @@
|
|
2
2
|
|
3
3
|
送信することはかないまいしたが、配信失敗時のエラーをcatchすることができず、調べたところcloudwatchというサービスからJson形式の配信ステータスを取得できるようです。
|
4
4
|
|
5
|
-
|
5
|
+
```Java
|
6
|
+
|
6
|
-
|
7
|
+
/**
|
8
|
+
|
9
|
+
* SMS送信
|
10
|
+
|
11
|
+
* @param customerId 顧客ID
|
12
|
+
|
13
|
+
* @param agreementNo 同意情報NO
|
14
|
+
|
15
|
+
* @param telephon 電話番号
|
16
|
+
|
17
|
+
* @return 検索結果のHTML
|
18
|
+
|
19
|
+
* @throws Exception
|
20
|
+
|
21
|
+
*/
|
22
|
+
|
23
|
+
@POST
|
24
|
+
|
25
|
+
@GET
|
26
|
+
|
27
|
+
@Path("sms")
|
28
|
+
|
29
|
+
@Consumes({ "application/json"})
|
30
|
+
|
31
|
+
@Produces({ "application/json; charset=UTF-8" })
|
32
|
+
|
33
|
+
//public RestApiResponse smssend(@PathParam("customerId") String customerId, SendSmsForm form, Long agreementNo) throws Exception{
|
34
|
+
|
35
|
+
public RestApiResponse authenticate (@PathParam("customerId")String customerId, String Telephone) throws Exception {
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
RestApiResponse result = new RestApiResponse();
|
42
|
+
|
43
|
+
String Message = reloadableConfig.getString("message");
|
44
|
+
|
45
|
+
String Time = reloadableConfig.getString("time");
|
46
|
+
|
47
|
+
int Count = reloadableConfig.getInt("count");
|
48
|
+
|
49
|
+
int smsflag;
|
50
|
+
|
51
|
+
int i = Count;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
if(Telephone == null){
|
56
|
+
|
57
|
+
// パラメータなし → エラー
|
58
|
+
|
59
|
+
result.setNG("The phone number isn't input yet.");
|
60
|
+
|
61
|
+
return result; // 結果を返却
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
try {
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
String telephone = null;
|
72
|
+
|
73
|
+
String test = null;
|
74
|
+
|
75
|
+
/*メッセージ内容*/
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
JSONObject json = new JSONObject(Telephone);
|
80
|
+
|
81
|
+
telephone = json.getString("Telephone");
|
82
|
+
|
83
|
+
System.out.println(telephone);
|
84
|
+
|
85
|
+
if(telephone.length() == 0){
|
86
|
+
|
87
|
+
result.setNG("The phone number isn't input yet.");
|
88
|
+
|
89
|
+
return result; // 結果を返却
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
String message = Message;//reloadable.properties参照
|
96
|
+
|
97
|
+
String phoneNumber = "+1" + telephone;//固定の"+1"を付ける
|
98
|
+
|
99
|
+
System.out.println(message);
|
100
|
+
|
101
|
+
System.out.println(phoneNumber);
|
102
|
+
|
103
|
+
Map<String, MessageAttributeValue> smsAttributes =
|
104
|
+
|
105
|
+
new HashMap<String, MessageAttributeValue>();
|
106
|
+
|
107
|
+
//<set SMS attributes>
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
String status = sendSMSMessage(snsClient, message, phoneNumber, smsAttributes);
|
112
|
+
|
113
|
+
if (status == "FAILURE"){
|
114
|
+
|
115
|
+
result.setNG("Sending the message is failed.");
|
116
|
+
|
117
|
+
return result;
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
result.setOK();
|
126
|
+
|
127
|
+
smsflag = 1;
|
128
|
+
|
129
|
+
agreementService.smsupdate(smsflag,telephone);
|
130
|
+
|
131
|
+
}catch(Exception e){
|
132
|
+
|
133
|
+
//result.setNG("Sending the message is failed.");
|
134
|
+
|
135
|
+
System.out.println(e.getMessage());
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
return result;
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
public static String sendSMSMessage(AmazonSNSClient snsClient, String message,
|
148
|
+
|
149
|
+
String phoneNumber, Map<String, MessageAttributeValue> smsAttributes) {
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
try{
|
154
|
+
|
155
|
+
PublishResult result = snsClient.publish(new PublishRequest()
|
156
|
+
|
157
|
+
.withMessage(message)
|
158
|
+
|
159
|
+
.withPhoneNumber(phoneNumber)
|
160
|
+
|
161
|
+
.withMessageAttributes(smsAttributes));
|
162
|
+
|
163
|
+
System.out.println(result); // Prints the message ID.
|
164
|
+
|
165
|
+
String id = result.getMessageId();
|
166
|
+
|
167
|
+
System.out.println(id);
|
168
|
+
|
169
|
+
int statusCode = result .getSdkHttpMetadata().getHttpStatusCode();
|
170
|
+
|
171
|
+
System.out.println(statusCode);
|
172
|
+
|
173
|
+
ResponseMetadata response = result.getSdkResponseMetadata();
|
174
|
+
|
175
|
+
System.out.println(response);
|
176
|
+
|
177
|
+
|
178
|
+
|
7
|
-
SetPlatformApplicationAttributesRequest setPlatformApplicationAttributesRequest = new SetPlatformApplicationAttributesRequest();
|
179
|
+
SetPlatformApplicationAttributesRequest setPlatformApplicationAttributesRequest = new SetPlatformApplicationAttributesRequest();
|
8
180
|
|
9
181
|
Map<String, String> attributes = new HashMap<>();
|
10
182
|
|
@@ -14,7 +186,7 @@
|
|
14
186
|
|
15
187
|
attributes.put("SuccessFeedbackSampleRate", "5");
|
16
188
|
|
17
|
-
|
189
|
+
attributes.put("MessageID", id);
|
18
190
|
|
19
191
|
setPlatformApplicationAttributesRequest.withAttributes(attributes);
|
20
192
|
|
@@ -22,6 +194,22 @@
|
|
22
194
|
|
23
195
|
setPlatformApplicationAttributesRequest.setPlatformApplicationArn("arn:aws:sns:us-west-2:111122223333:app/GCM/GCMPushApp");
|
24
196
|
|
197
|
+
SetPlatformApplicationAttributesResult res = snsClient.setPlatformApplicationAttributes(setPlatformApplicationAttributesRequest);
|
198
|
+
|
199
|
+
ResponseMetadata obj = res.getSdkResponseMetadata();
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
String status = null;
|
204
|
+
|
205
|
+
JSONObject json = new JSONObject(obj);
|
206
|
+
|
207
|
+
status = json.getString("status");
|
208
|
+
|
209
|
+
System.out.println(status);
|
210
|
+
|
211
|
+
```
|
212
|
+
|
25
213
|
|
26
214
|
|
27
215
|
上記太字の部分を追加し、指定したメッセージの配信ステータスを取得したいのですが取得することが出来ません。
|