重新定义二维码支付的接口

This commit is contained in:
egzosn
2017-03-19 23:25:48 +08:00
parent 171abfc31a
commit d1f6c241a2
6 changed files with 66 additions and 47 deletions

View File

@@ -135,10 +135,10 @@ public interface PayService {
/**
* 获取输出二维码,用户返回给支付端,
*
* @param orderInfo 发起支付的订单信息
* @param order 发起支付的订单信息
* @return
*/
BufferedImage genQrPay(Map<String, Object> orderInfo);
BufferedImage genQrPay(PayOrder order);
/**
* 交易查询接口

View File

@@ -9,7 +9,7 @@ import in.egan.pay.common.bean.PayOutMessage;
* @email egzosn@gmail.com
* @date 2017/1/13 14:30
*/
public class JsonBuilder extends BaseBuilder<TextBuilder, PayOutMessage>{
public class JsonBuilder extends BaseBuilder<JsonBuilder, PayOutMessage>{
JSONObject json = null;
public JsonBuilder(JSONObject json) {

View File

@@ -24,6 +24,8 @@ import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import static in.egan.pay.common.http.UriVariables.getMapToParameters;
/**
* 一个HTTP请求的客户端
* @author: egan
@@ -94,48 +96,6 @@ public class ClientHttpRequest<T> extends HttpEntityEnclosingRequestBase impleme
return this;
}
/**
* Map转化为对应得参数字符串
* @param pe
* @return
*/
public static String getMapToParameters(Map pe){
StringBuilder builder = new StringBuilder();
for (Object key : pe.keySet()) {
Object o = pe.get(key);
if (null == o) {
continue;
}
if (o instanceof List) {
o = ((List) o).toArray();
}
try {
if (o instanceof Object[]) {
Object[] os = (Object[]) o;
String valueStr = "";
for (int i = 0, len = os.length; i < len; i++) {
if (null == os[i]) {
continue;
}
String value = os[i].toString().trim();
valueStr += (i == len - 1) ? value : value + ",";
}
builder.append(key).append("=").append(URLEncoder.encode(valueStr, "utf-8")).append("&");
continue;
}
builder.append(key).append("=").append(URLEncoder.encode((String) pe.get(key), "utf-8")).append("&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
if (builder.length() > 1) {
builder.deleteCharAt(builder.length() - 1);
}
return builder.toString();
}
/**
* 设置请求参数

View File

@@ -1,6 +1,14 @@
package in.egan.pay.common.http;
import com.alibaba.fastjson.JSON;
import org.apache.http.Consts;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -39,6 +47,8 @@ public class UriVariables {
return uri;
}
/**
* 匹配Map.key
* @param uri
@@ -70,4 +80,51 @@ public class UriVariables {
}
/**
* Map转化为对应得参数字符串
* @param pe
* @return
*/
public static String getMapToParameters(Map pe){
StringBuilder builder = new StringBuilder();
for (Object key : pe.keySet()) {
Object o = pe.get(key);
if (null == o) {
continue;
}
if (o instanceof List) {
o = ((List) o).toArray();
}
try {
if (o instanceof Object[]) {
Object[] os = (Object[]) o;
String valueStr = "";
for (int i = 0, len = os.length; i < len; i++) {
if (null == os[i]) {
continue;
}
String value = os[i].toString().trim();
valueStr += (i == len - 1) ? value : value + ",";
}
builder.append(key).append("=").append(URLEncoder.encode(valueStr, "utf-8")).append("&");
continue;
}
builder.append(key).append("=").append(URLEncoder.encode((String) pe.get(key), "utf-8")).append("&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
if (builder.length() > 1) {
builder.deleteCharAt(builder.length() - 1);
}
return builder.toString();
}
}