Skip to content

Commit

Permalink
sms json SerializedName
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Jun 28, 2019
1 parent 36a75d0 commit a3258eb
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 160 deletions.
68 changes: 37 additions & 31 deletions examples/SendMessageDemo.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
import java.util.HashMap;
import java.util.Map;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;

public class SendMessageDemo {
public static void main(String args[]) {
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "test";
String SECRET_KEY = "test";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);


//实例化一个SmsManager对象
SmsManager smsManager = new SmsManager(auth);



try {
// Map<String,String> map = new HashMap<String,String>();
// Response resp = smsManager.sendMessage("templateId", new String[] {"10086"}, map);
// Response resp = smsManager.describeSignature("passed",0,0);
// SignatureInfo sinfo = smsManager.describeSignatureItems("rejected",0,0);
// Response resp = smsManager.createSignature("signature", "app", new String[] {"data:image/gif;base64,xxxxxxxxxx"});
Response resp = smsManager.describeTemplate("passed",0,0);
// Response resp = smsManager.createTemplate("name","template","notification","test","signatureId");
// Response resp = smsManager.modifyTemplate("templateId","name","template","test","signatureId");
// Response resp = smsManager.modifySignature("SignatureId","signature");
// Response resp = smsManager.deleteSignature("signatureId");
// Response resp = smsManager.deleteTemplate("templateId");
System.out.println(resp.bodyString());
} catch (QiniuException e) {
System.out.println(e);
}


}
public static void main(String args[]) {
// 设置需要操作的账号的AK和SK
String ACCESS_KEY = "";
String SECRET_KEY = "";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

// 实例化一个SmsManager对象
SmsManager smsManager = new SmsManager(auth);

try {
Map<String, String> map = new HashMap<String, String>();
Response resp = smsManager.sendMessage("templateId", new String[] { "10086" }, map);
// Response resp = smsManager.describeSignature("passed", 0, 0);
// Response resp = smsManager.createSignature("signature", "app",
// new String[] { "data:image/gif;base64,xxxxxxxxxx" });
// Response resp = smsManager.describeTemplate("passed", 0, 0);
// Response resp = smsManager.createTemplate("name", "template", "notification", "test", "signatureId");
// Response resp = smsManager.modifyTemplate("templateId", "name", "template", "test", "signatureId");
// Response resp = smsManager.modifySignature("SignatureId", "signature");
// Response resp = smsManager.deleteSignature("signatureId");
// Response resp = smsManager.deleteTemplate("templateId");
System.out.println(resp.bodyString());

// SignatureInfo sinfo = smsManager.describeSignatureItems("", 0, 0);
// System.out.println(sinfo.getItems().get(0).getAuditStatus());
// TemplateInfo tinfo = smsManager.describeTemplateItems("", 0, 0);
// System.out.println(tinfo.getItems().get(0).getAuditStatus());


} catch (QiniuException e) {
System.out.println(e);
}

}
}
84 changes: 47 additions & 37 deletions src/main/java/com/qiniu/sms/model/SignatureInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.qiniu.sms.model;

import java.util.List;
import com.google.gson.annotations.SerializedName;

import java.util.List;

public final class SignatureInfo {
private List<Item> items;
Expand All @@ -10,51 +11,24 @@ public final class SignatureInfo {

private int page;

@SerializedName("page_size")
private int pageSize;

public static Class<Item> getItemClass() {
return Item.class;
}

public List<Item> getItems() {
return items;
}

public void setItems(List<Item> items) {
this.items = items;
}

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public int getPage() {
return page;
}

public void setPage(int page) {
this.page = page;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public class Item {
private String id;
private String signature;
private String source;

@SerializedName("audit_status")
private String auditStatus;

@SerializedName("reject_reason")
private String rejectReason;

@SerializedName("created_at")
private Long createdAt;

@SerializedName("updated_at")
private Long updatedAt;

public String getId() {
Expand Down Expand Up @@ -115,4 +89,40 @@ public void setUpdatedAt(Long updatedAt) {

}

public List<Item> getItems() {
return items;
}

public static Class<Item> getItemClass() {
return Item.class;
}

public void setItems(List<Item> items) {
this.items = items;
}

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public int getPage() {
return page;
}

public void setPage(int page) {
this.page = page;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

}
81 changes: 48 additions & 33 deletions src/main/java/com/qiniu/sms/model/TemplateInfo.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,43 @@
package com.qiniu.sms.model;

import java.util.List;
import com.google.gson.annotations.SerializedName;

import java.util.List;

public class TemplateInfo {

private int total;

private int page;

@SerializedName("page_size")
private int pageSize;

private List<Item> items;

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public int getPage() {
return page;
}

public void setPage(int page) {
this.page = page;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public List<Item> getItems() {
return items;
}

public void setItems(List<Item> items) {
this.items = items;
}

public class Item {
private String id;
private String name;
private String template;

@SerializedName("audit_status")
private String auditStatus;

@SerializedName("reject_reason")
private String rejectReason;

private String type;

@SerializedName("signature_id")
private String signatureId;

@SerializedName("signature_text")
private String signatureText;

@SerializedName("created_at")
private int createdAt;

@SerializedName("updated_at")
private int updatedAt;

public String getId() {
Expand Down Expand Up @@ -139,4 +122,36 @@ public void setUpdatedAt(int updated_at) {

}

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public int getPage() {
return page;
}

public void setPage(int page) {
this.page = page;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public List<Item> getItems() {
return items;
}

public void setItems(List<Item> items) {
this.items = items;
}

}
1 change: 1 addition & 0 deletions src/main/java/com/qiniu/util/StringMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Object get(String key) {
public Set<String> keySet() {
return map.keySet();
}

public String formString() {
final StringBuilder b = new StringBuilder();
forEach(new Consumer() {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/test/com/qiniu/CdnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public void testCreateTimestampAntiLeechUrlSimple() {
long deadline2 = deadline1;
long deadline3 = 1551966091; // 2019-03-07 21:41:31 +0800 CST
String testUrl_z0_timeStamp_outdate =
"http://javasdk-timestamp.peterpy.cn/do_not_delete/1.png?sign=50d05540eea4ea8ab905b57006edef7a&t=5c811f8b";
"http://javasdk-timestamp.peterpy.cn/do_not_delete/1.png?"
+ "sign=50d05540eea4ea8ab905b57006edef7a&t=5c811f8b";
try {
URL url = new URL(TestConfig.testUrl_z0_timeStamp);
Assert.assertEquals(403, getResponse(url.toString()).statusCode);
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/test/com/qiniu/ResCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package test.com.qiniu;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

public class ResCode {
public static boolean find(int code, int ...codes) {
System.out.println("response code is: " + code + ", expected code is in: " + Arrays.toString(codes));
for (int i : codes) {
if (code == i) {
return true;
}
}
return false;
}

public static int[] getPossibleResCode(int ...codes) {
return getPossibleResCode(TestConfig.isTravis(), codes);
}

public static int[] getPossibleResCode(boolean isTravis, int ...codes) {
if (isTravis) {
int[] n = new int[codes.length + 1];
System.arraycopy(codes, 0, n, 0, codes.length);
n[codes.length] = -1; // add code -1 for networking failed.
return n;
}
return codes;
}

@Test
public void testAddCode() {
Assert.assertArrayEquals(new int[]{401, -1}, ResCode.getPossibleResCode(true, 401));
Assert.assertArrayEquals(new int[]{401}, ResCode.getPossibleResCode(false, 401));
}


}
Loading

0 comments on commit a3258eb

Please sign in to comment.