mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-31 12:59:35 +08:00
补全注释
This commit is contained in:
@@ -10,9 +10,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
/**
|
||||
* LogExceptionHandler 日志处理器
|
||||
* @author egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2016-6-1 11:28:01
|
||||
* @source chanjarster/weixin-java-tools
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016-6-1 11:28:01
|
||||
*
|
||||
*
|
||||
* source chanjarster/weixin-java-tools
|
||||
* </pre>
|
||||
*/
|
||||
public class LogExceptionHandler implements PayErrorExceptionHandler {
|
||||
|
||||
|
||||
@@ -17,8 +17,10 @@ import java.util.Map;
|
||||
/**
|
||||
* 二维码生成工具
|
||||
* @author egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2017/2/7 10:35
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2017/2/7 10:35
|
||||
* </pre>
|
||||
*/
|
||||
public class MatrixToImageWriter {
|
||||
|
||||
@@ -32,7 +34,7 @@ public class MatrixToImageWriter {
|
||||
* 根据二维矩阵的碎片 生成对应的二维码图像缓冲
|
||||
* @param matrix 二维矩阵的碎片 包含 宽高 行,字节
|
||||
* @see com.google.zxing.common.BitMatrix
|
||||
* @return
|
||||
* @return 二维码图像缓冲
|
||||
*/
|
||||
public static BufferedImage toBufferedImage(BitMatrix matrix) {
|
||||
int width = matrix.getWidth();
|
||||
@@ -49,10 +51,10 @@ public class MatrixToImageWriter {
|
||||
|
||||
/**
|
||||
* 二维码生成文件
|
||||
* @param matrix
|
||||
* @param format
|
||||
* @param file
|
||||
* @throws IOException
|
||||
* @param matrix 二维矩阵的碎片 包含 宽高 行,字节
|
||||
* @param format 格式
|
||||
* @param file 保持的文件地址
|
||||
* @throws IOException 文件保存异常
|
||||
*/
|
||||
public static void writeToFile(BitMatrix matrix, String format, File file)
|
||||
throws IOException {
|
||||
@@ -65,10 +67,10 @@ public class MatrixToImageWriter {
|
||||
|
||||
/**
|
||||
* 二维码生成流
|
||||
* @param matrix
|
||||
* @param format
|
||||
* @param stream
|
||||
* @throws IOException
|
||||
* @param matrix 二维矩阵的碎片 包含 宽高 行,字节
|
||||
* @param format 格式
|
||||
* @param stream 保持的文件输出流
|
||||
* @throws IOException 文件保存异常
|
||||
*/
|
||||
public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
|
||||
throws IOException {
|
||||
@@ -81,8 +83,8 @@ public class MatrixToImageWriter {
|
||||
|
||||
/**
|
||||
* 二维码信息写成JPG文件
|
||||
* @param content
|
||||
* @param fileUrl
|
||||
* @param content 二维码信息
|
||||
* @param fileUrl 文件地址
|
||||
*/
|
||||
public static void writeInfoToJpgFile(String content, String fileUrl){
|
||||
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
|
||||
@@ -101,8 +103,8 @@ public class MatrixToImageWriter {
|
||||
|
||||
/**
|
||||
* 二维码信息写成JPG BufferedImage
|
||||
* @param content
|
||||
* @return
|
||||
* @param content 二维码信息
|
||||
* @return JPG BufferedImage
|
||||
*/
|
||||
public static BufferedImage writeInfoToJpgBuff(String content){
|
||||
BufferedImage re=null;
|
||||
|
||||
@@ -18,14 +18,16 @@ import java.util.Map;
|
||||
/**
|
||||
* XML工具
|
||||
* @author egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2016-6-2 19:45:06
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016-6-2 19:45:06
|
||||
* </pre>
|
||||
*/
|
||||
public class XML {
|
||||
/**
|
||||
* 解析xml并转化为Json值
|
||||
* @param content json字符串
|
||||
* @return
|
||||
* @return Json值
|
||||
*/
|
||||
public static JSONObject toJSONObject(String content){
|
||||
|
||||
@@ -45,7 +47,7 @@ public class XML {
|
||||
/**
|
||||
* 解析xml并转化为json值
|
||||
* @param in 输入流
|
||||
* @return
|
||||
* @return Json值
|
||||
*/
|
||||
public static JSONObject toJSONObject(InputStream in) {
|
||||
|
||||
@@ -63,7 +65,13 @@ public class XML {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param in xml输入流
|
||||
* @param m 参数集
|
||||
* @return 整理完成的参数集
|
||||
* @throws IOException xml io转化异常
|
||||
*/
|
||||
public static Map inputStream2Map(InputStream in, Map m) throws IOException {
|
||||
if (null == m){
|
||||
m = new JSONObject();
|
||||
@@ -97,8 +105,8 @@ public class XML {
|
||||
/**
|
||||
* 获取子结点的xml
|
||||
*
|
||||
* @param children
|
||||
* @return String
|
||||
* @param children 集合
|
||||
* @return String 子结点的xml
|
||||
*/
|
||||
public static String getChildrenText(List children) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
@@ -122,9 +130,9 @@ public class XML {
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description:将请求参数转换为xml格式的string
|
||||
* 将请求参数转换为xml格式的string
|
||||
* @param parameters 请求参数
|
||||
* @return
|
||||
* @return xml
|
||||
*/
|
||||
public static String getMap2Xml(Map<String, Object> parameters) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
@@ -10,8 +10,10 @@ import java.util.*;
|
||||
* 签名 工具
|
||||
*
|
||||
* @author: egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2016/11/9 17:45
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2016/11/9 17:45
|
||||
* </pre>
|
||||
*/
|
||||
public enum SignUtils {
|
||||
|
||||
@@ -21,7 +23,7 @@ public enum SignUtils {
|
||||
* @param content 需要签名的内容
|
||||
* @param key 密钥
|
||||
* @param characterEncoding 字符编码
|
||||
* @return
|
||||
* @return 签名值
|
||||
*/
|
||||
@Override
|
||||
public String createSign(String content, String key, String characterEncoding) {
|
||||
@@ -76,64 +78,6 @@ public enum SignUtils {
|
||||
return parameterText(parameters, "&");
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 把数组所有元素排序,并按照“参数=参数值”的模式用“@param separator”字符拼接成字符串
|
||||
* @param parameters 参数
|
||||
* @param separator 分隔符
|
||||
* @return 去掉空值与签名参数后的新签名,拼接后字符串
|
||||
*/
|
||||
/* public static String parameterText(Map parameters, String separator) {
|
||||
if(parameters == null){
|
||||
return "";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
// TODO 2016/11/11 10:14 author: egan 已经排序好处理
|
||||
if (parameters instanceof SortedMap) {
|
||||
for (String k : ((Set<String>) parameters.keySet())) {
|
||||
Object v = parameters.get(k);
|
||||
if (null == v || "".equals(v.toString().trim()) || "sign".equals(k) || "key".equals(k) || "appId".equals(k) || "sign_type".equalsIgnoreCase(k)) {
|
||||
continue;
|
||||
}
|
||||
sb.append(k ).append("=").append( v.toString().trim()).append(separator);
|
||||
}
|
||||
if (sb.length() > 0 && !"".equals(separator)) {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TODO 2016/11/11 10:14 author: egan 未排序须处理
|
||||
List<String> keys = new ArrayList<String>(parameters.keySet());
|
||||
//排序
|
||||
Collections.sort(keys);
|
||||
for (String k : keys) {
|
||||
String valueStr = "";
|
||||
Object o = parameters.get(k);
|
||||
if (o instanceof String[]) {
|
||||
String[] values = (String[]) o;
|
||||
if (null == values){continue;}
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
String value = values[i].trim();
|
||||
if ("".equals(value)){ continue;}
|
||||
valueStr += (i == values.length - 1) ? value : value + ",";
|
||||
}
|
||||
} else if (o != null) {
|
||||
valueStr = o.toString();
|
||||
}
|
||||
if (null == valueStr || "".equals(valueStr.toString().trim()) || "sign".equals(k) || "key".equals(k) || "appId".equals(k) || "sign_type".equalsIgnoreCase(k)) {
|
||||
continue;
|
||||
}
|
||||
sb.append(k ).append("=").append( valueStr).append(separator);
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
return sb.toString();
|
||||
}*/
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -211,9 +155,9 @@ public enum SignUtils {
|
||||
/**
|
||||
* 将参数集合(事前做好排序)按分割符号拼凑字符串并加密为MD5
|
||||
* example: mchnt_cd+"|" +order_id+"|"+order_amt+"|"+order_pay_type+"|"+page_notify_url+"|"+back_notify_url+"|"+order_valid_time+"|"+iss_ins_cd+"|"+goods_name+"|"+"+goods_display_url+"|"+rem+"|"+ver+"|"+mchnt_key
|
||||
* @param parameters
|
||||
* @param separator
|
||||
* @return
|
||||
* @param parameters 参数集合
|
||||
* @param separator 分隔符
|
||||
* @return 参数排序好的值
|
||||
*/
|
||||
public static String parameters2MD5Str(Object parameters, String separator){
|
||||
StringBuffer sb = new StringBuffer();
|
||||
@@ -240,7 +184,7 @@ public enum SignUtils {
|
||||
|
||||
/**
|
||||
* 获取随机字符串
|
||||
* @return
|
||||
* @return 随机字符串
|
||||
*/
|
||||
public static String randomStr(){
|
||||
return UUID.randomUUID().toString().replace("-", "");
|
||||
@@ -252,7 +196,7 @@ public enum SignUtils {
|
||||
* @param parameters 需要进行排序签名的参数
|
||||
* @param key 密钥
|
||||
* @param characterEncoding 编码格式
|
||||
* @return
|
||||
* @return 签名值
|
||||
*/
|
||||
public String sign(Map parameters, String key, String characterEncoding) {
|
||||
|
||||
@@ -262,9 +206,9 @@ public enum SignUtils {
|
||||
* 签名
|
||||
* @param parameters 需要进行排序签名的参数
|
||||
* @param key 密钥
|
||||
* @param separator 分隔符 默认 &
|
||||
* @param separator 分隔符 默认 &
|
||||
* @param characterEncoding 编码格式
|
||||
* @return
|
||||
* @return 签名值
|
||||
*/
|
||||
public String sign(Map parameters, String key, String separator, String characterEncoding) {
|
||||
|
||||
@@ -278,7 +222,7 @@ public enum SignUtils {
|
||||
* @param content 需要签名的内容
|
||||
* @param key 密钥
|
||||
* @param characterEncoding 字符编码
|
||||
* @return
|
||||
* @return 签名值
|
||||
*/
|
||||
public abstract String createSign(String content, String key, String characterEncoding);
|
||||
|
||||
@@ -293,7 +237,6 @@ public enum SignUtils {
|
||||
*/
|
||||
public boolean verify(Map params, String sign, String key, String characterEncoding){
|
||||
//判断是否一样
|
||||
// return StringUtils.equals(sign(params, key, characterEncoding), sign);
|
||||
return this.verify(parameterText(params), sign, key, characterEncoding);
|
||||
}
|
||||
|
||||
@@ -309,8 +252,4 @@ public enum SignUtils {
|
||||
*/
|
||||
public abstract boolean verify(String text, String sign, String key, String characterEncoding);
|
||||
|
||||
|
||||
|
||||
//签名错误代码
|
||||
public static final int SIGN_ERROR = 91;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,7 @@ public class MD5 {
|
||||
/**
|
||||
* @param content 需要加密串
|
||||
* @param charset 字符集
|
||||
* @return
|
||||
* @throws SignatureException
|
||||
* @throws UnsupportedEncodingException
|
||||
* @return 加密后的字节数组
|
||||
*/
|
||||
public static byte[] getContentBytes(String content, String charset) {
|
||||
if (StringUtils.isEmpty(charset)) {
|
||||
|
||||
@@ -101,6 +101,7 @@ public class RSA{
|
||||
* @param privateKey 商户私钥
|
||||
* @param characterEncoding 编码格式
|
||||
* @return 解密后的字符串
|
||||
* @throws Exception 解密异常
|
||||
*/
|
||||
public static String decrypt(String content, String privateKey, String characterEncoding) throws Exception {
|
||||
PrivateKey prikey = getPrivateKey(privateKey);
|
||||
@@ -132,7 +133,8 @@ public class RSA{
|
||||
/**
|
||||
* 得到私钥
|
||||
* @param key 密钥字符串(经过base64编码)
|
||||
* @throws Exception
|
||||
* @throws Exception 加密异常
|
||||
* @return 私钥
|
||||
*/
|
||||
public static PrivateKey getPrivateKey(String key) throws Exception {
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public class RSA2 {
|
||||
* @param privateKey 商户私钥
|
||||
* @param characterEncoding 编码格式
|
||||
* @return 解密后的字符串
|
||||
* @throws Exception 解密异常
|
||||
*/
|
||||
public static String decrypt(String content, String privateKey, String characterEncoding) throws Exception {
|
||||
return RSA.decrypt(content, privateKey, characterEncoding);
|
||||
@@ -45,7 +46,8 @@ public class RSA2 {
|
||||
/**
|
||||
* 得到私钥
|
||||
* @param key 密钥字符串(经过base64编码)
|
||||
* @throws Exception
|
||||
* @throws Exception 加密异常
|
||||
* @return 私钥
|
||||
*/
|
||||
public static PrivateKey getPrivateKey(String key) throws Exception {
|
||||
return RSA.getPrivateKey(key);
|
||||
|
||||
Reference in New Issue
Block a user