本文整理汇总了Java中com.alibaba.fastjson.util.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于com.alibaba.fastjson.util包,在下文中一共展示了Base64类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bytesValue
import com.alibaba.fastjson.util.Base64; //导入依赖的package包/类
public byte[] bytesValue() {
return Base64.decodeFast(this.buf, this.np + 1, this.sp);
}
示例2: bytesValue
import com.alibaba.fastjson.util.Base64; //导入依赖的package包/类
public byte[] bytesValue() {
return Base64.decodeFast(this.text, this.np + 1, this.sp);
}
示例3: writeByteArray
import com.alibaba.fastjson.util.Base64; //导入依赖的package包/类
public void writeByteArray(byte[] bytes) {
int bytesLen = bytes.length;
boolean singleQuote = isEnabled(SerializerFeature.UseSingleQuotes);
char quote = singleQuote ? '\'' : '\"';
if (bytesLen == 0) {
write(singleQuote ? "''" : "\"\"");
return;
}
int s;
int i;
int left;
char[] CA = Base64.CA;
int eLen = (bytesLen / 3) * 3;
int charsLen = (((bytesLen - 1) / 3) + 1) << 2;
int offset = this.count;
int newcount = (this.count + charsLen) + 2;
if (newcount > this.buf.length) {
if (this.writer != null) {
write(quote);
s = 0;
while (s < eLen) {
int s2 = s + 1;
s = s2 + 1;
s2 = s + 1;
i = (((bytes[s] & 255) << 16) | ((bytes[s2] & 255) << 8)) | (bytes[s] & 255);
write(CA[(i >>> 18) & 63]);
write(CA[(i >>> 12) & 63]);
write(CA[(i >>> 6) & 63]);
write(CA[i & 63]);
s = s2;
}
left = bytesLen - eLen;
if (left > 0) {
i = ((bytes[eLen] & 255) << 10) | (left == 2 ? (bytes[bytesLen - 1] & 255) << 2 : 0);
write(CA[i >> 12]);
write(CA[(i >>> 6) & 63]);
write(left == 2 ? CA[i & 63] : '=');
write('=');
}
write(quote);
return;
}
expandCapacity(newcount);
}
this.count = newcount;
int offset2 = offset + 1;
this.buf[offset] = quote;
int d = offset2;
s = 0;
while (s < eLen) {
s2 = s + 1;
s = s2 + 1;
s2 = s + 1;
i = (((bytes[s] & 255) << 16) | ((bytes[s2] & 255) << 8)) | (bytes[s] & 255);
int i2 = d + 1;
this.buf[d] = CA[(i >>> 18) & 63];
d = i2 + 1;
this.buf[i2] = CA[(i >>> 12) & 63];
i2 = d + 1;
this.buf[d] = CA[(i >>> 6) & 63];
d = i2 + 1;
this.buf[i2] = CA[i & 63];
s = s2;
}
left = bytesLen - eLen;
if (left > 0) {
i = ((bytes[eLen] & 255) << 10) | (left == 2 ? (bytes[bytesLen - 1] & 255) << 2 : 0);
this.buf[newcount - 5] = CA[i >> 12];
this.buf[newcount - 4] = CA[(i >>> 6) & 63];
this.buf[newcount - 3] = left == 2 ? CA[i & 63] : '=';
this.buf[newcount - 2] = '=';
}
this.buf[newcount - 1] = quote;
}
示例4: bytesValue
import com.alibaba.fastjson.util.Base64; //导入依赖的package包/类
public byte[] bytesValue() {
return Base64.decodeFast(buf, np + 1, sp);
}
示例5: bytesValue
import com.alibaba.fastjson.util.Base64; //导入依赖的package包/类
public byte[] bytesValue() {
return Base64.decodeFast(text, np + 1, sp);
}
示例6: checkIAPReceipt
import com.alibaba.fastjson.util.Base64; //导入依赖的package包/类
/**
* Check if the receipt sent by client is for us and valid.
*
* @param json
* @return
*/
public static boolean checkIAPReceipt(User user, String productId, String json) {
try {
String roleName = Constant.EMPTY;
if ( user != null ) {
roleName = user.getRoleName();
}
String decodeJson = new String(Base64.decodeFast(json));
decodeJson = decodeJson.replaceAll("=", ":");
decodeJson = decodeJson.replaceAll(";", ",");
Object obj = com.alibaba.fastjson.JSON.parse(decodeJson);
// String receipt = ((Map)obj).get("receipt-data").toString();
// /**
// * receipt:
// * {
// "signature" = "ApdxJdtNwPU2rA5/cn3kIO1OTk25feDKa0aagyyRveWlcFlglv6RF6znkiBS3um9Uc7pVob+PqZR2T8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0=";
// "pod" = "17";
// "signing-status" = "0";
// }
// */
// String decodeReceipt = new String(Base64.decodeFast(receipt));
// decodeReceipt = decodeReceipt.replaceAll("=", ":");
// decodeReceipt = decodeReceipt.replaceAll(";", ",");
// obj = com.alibaba.fastjson.JSON.parse(decodeReceipt);
String purchaseInfo = ((Map)obj).get("purchase-info").toString();
String decodePurchaseInfo = new String(Base64.decodeFast(purchaseInfo));
/*
{
"original-purchase-date-pst" = "2012-07-12 05:54:35 America/Los_Angeles";
"purchase-date-ms" = "1342097675882";
"original-transaction-id" = "170000029449420";
"bvrs" = "1.4";
"app-item-id" = "450542233";
"transaction-id" = "170000029449420";
"quantity" = "1";
"original-purchase-date-ms" = "1342097675882";
"item-id" = "534185042";
"version-external-identifier" = "9051236";
"product-id" = "com.zeptolab.ctrbonus.superpower1";
"purchase-date" = "2012-07-12 12:54:35 Etc/GMT";
"original-purchase-date" = "2012-07-12 12:54:35 Etc/GMT";
"bid" = "com.zeptolab.ctrexperiments";
"purchase-date-pst" = "2012-07-12 05:54:35 America/Los_Angeles";
}
*/
decodePurchaseInfo = decodePurchaseInfo.replaceAll("=", ":");
decodePurchaseInfo = decodePurchaseInfo.replaceAll(";", ",");
logger.info("User {} decode purchase-info: {}", roleName, decodePurchaseInfo);
obj = com.alibaba.fastjson.JSON.parse(decodePurchaseInfo);
String pid = ((Map)obj).get("product-id").toString();
String purchaseDate = ((Map)obj).get("purchase-date-pst").toString();
Date date = DateUtil.parseApplePurchaseDate(purchaseDate);
if ( productId.equals(pid) ) {
long currentMillis = System.currentTimeMillis();
int timeDiff = (int)(currentMillis - date.getTime());
if ( timeDiff > 0 && timeDiff < 86400000 ) {
return true;
} else {
logger.info("The {} use a fake purchaseDate:{}", roleName, purchaseDate);
}
} else {
logger.info("The {} use a fake productId:{}", roleName, pid);
}
} catch (Exception e) {
logger.warn("Failed to check IAP receipt json:{}, exception:{}", json, e.getMessage());
logger.info("Parse IAP receipt exception: ", e);
}
return false;
}