|
@@ -9,7 +9,9 @@ import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
|
|
|
import com.alipay.easysdk.payment.wap.models.AlipayTradeWapPayResponse;
|
|
|
import com.zanxiang.common.domain.ResultMap;
|
|
|
import com.zanxiang.common.enums.HttpStatusEnum;
|
|
|
+import com.zanxiang.common.enums.OsEnum;
|
|
|
import com.zanxiang.common.enums.ResEnum;
|
|
|
+import com.zanxiang.sdk.common.util.HttpUtil;
|
|
|
import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
|
|
|
import com.zanxiang.sdk.service.OrderPayService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -21,10 +23,13 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.Enumeration;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* @author xufeng
|
|
@@ -42,6 +47,8 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
@Value("payConfig.alipay.notifyUrl")
|
|
|
private String notifyUrl;
|
|
|
|
|
|
+ private Config config;
|
|
|
+
|
|
|
/**
|
|
|
* 支付调起
|
|
|
*
|
|
@@ -49,7 +56,6 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
-
|
|
|
public ResultMap create(ProductPayParamBO product) {
|
|
|
this.attach = product.getAttach();
|
|
|
configInit(getPayConfig(product.getGameId(), product.getPayWay(), product.getPayWay()));
|
|
@@ -64,7 +70,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
case 1:
|
|
|
return this.pc(product);
|
|
|
case 2:
|
|
|
- return this.mobile(product);
|
|
|
+ return this.mobile2(product);
|
|
|
case 3:
|
|
|
return this.app(product);
|
|
|
default:
|
|
@@ -82,7 +88,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
@Override
|
|
|
public String notify(HttpServletRequest request, HttpServletResponse response) {
|
|
|
try {
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
Enumeration<String> parameterNames = request.getParameterNames();
|
|
|
while (parameterNames.hasMoreElements()) {
|
|
|
String parameterName = parameterNames.nextElement();
|
|
@@ -118,7 +124,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
public ResultMap synNotify(HttpServletRequest request) {
|
|
|
try {
|
|
|
//获取支付宝GET过来反馈信息
|
|
|
- Map<String, String> params = new HashMap<>();
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, String[]> requestParams = request.getParameterMap();
|
|
|
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
|
|
|
String name = iter.next();
|
|
@@ -173,16 +179,76 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
|
logger.info("mobile端支付生成,result:{}", response);
|
|
|
if (ResponseChecker.success(response)) {
|
|
|
+ System.out.println("mobile端支付生成================");
|
|
|
+ System.out.println(response.getBody());
|
|
|
return ResultMap.ok(product.getPayDevice(), response.getBody());
|
|
|
} else {
|
|
|
return ResultMap.ok(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private ResultMap mobile2(ProductPayParamBO product) {
|
|
|
+ try {
|
|
|
+ logger.info("mobile端支付生成,请求参数 bo:{}", product);
|
|
|
+ AlipayTradeWapPayResponse response = Factory.Payment
|
|
|
+ .Wap().asyncNotify(notifyUrl)
|
|
|
+ .pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), "", this.returnUrl);
|
|
|
+ logger.info("mobile端支付生成,result:{}", response);
|
|
|
+ if (ResponseChecker.success(response)) {
|
|
|
+ HashMap<String, String> result = new HashMap<>();
|
|
|
+ String body = response.getBody();
|
|
|
+ result.put("fromData", body);
|
|
|
+ //安卓与ios系统时才单独获取app支付地址
|
|
|
+ if (product.getDeviceSystem().contains(OsEnum.SYSTEM_ANDROID.getOs()) || product.getDeviceSystem().contains(OsEnum.SYSTEM_IOS.getOs())) {
|
|
|
+ Pattern pattern = Pattern.compile("action=\"(.*)\">", Pattern.CASE_INSENSITIVE);
|
|
|
+ Matcher matcher = pattern.matcher(body);
|
|
|
+ if (matcher.find()) {
|
|
|
+ String url = matcher.group();
|
|
|
+ url = url.substring(8, url.length() - 2);
|
|
|
+ System.out.println(url);
|
|
|
+ Pattern param = Pattern.compile("value=\"(.*)\">", Pattern.CASE_INSENSITIVE);
|
|
|
+ Matcher paraMatcher = param.matcher(body);
|
|
|
+ if (paraMatcher.find()) {
|
|
|
+ String paramData = paraMatcher.group();
|
|
|
+ paramData = paramData.substring(7, paramData.length() - 2);
|
|
|
+ paramData = paramData.replace(""", "\"");
|
|
|
+ String mobileClientUrl = HttpUtil.postDataUrl(url, "biz_content=" + paramData, null);
|
|
|
+ System.out.println(mobileClientUrl);
|
|
|
+ String alipayContentBody = HttpUtil.postData(mobileClientUrl, "");
|
|
|
+ Pattern mobileClientParam = Pattern.compile("\\{\"queryResultUrl\".*?\"}", Pattern.CASE_INSENSITIVE);
|
|
|
+ Matcher mobileClientMatcher = mobileClientParam.matcher(alipayContentBody);
|
|
|
+ System.out.println(mobileClientMatcher);
|
|
|
+ String deeplink_android = "alipays://platformapi/startApp?appId=20000125&orderSuffix=";
|
|
|
+ String deeplink_ios = "alipay://alipayclient/?";
|
|
|
+ if (mobileClientMatcher.find()) {
|
|
|
+ //示例:{"queryResultUrl":"/h5/h5RoutePayResultQuery.json?h5_route_token=GZ00rxXoidjHj2airAK8nhYz70MUBsmobilecashierGZ00","invokeAlipayData":{"dataString":"h5_route_token=\"GZ00rxXoidjHj2airAK8nhYz70MUBsmobilecashierGZ00\"&is_h5_route=\"true\""}
|
|
|
+ String pageData = mobileClientMatcher.group() + "}";
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(pageData);
|
|
|
+ Object invokeAlipayData = jsonObject.get("invokeAlipayData");
|
|
|
+ String dataString = JSONObject.parseObject(invokeAlipayData.toString()).get("dataString").toString();
|
|
|
+ deeplink_android += URLEncoder.encode(dataString, "utf-8");
|
|
|
+ deeplink_ios += URLEncoder.encode(pageData, "utf-8");
|
|
|
+ if (product.getDeviceSystem().contains(OsEnum.SYSTEM_ANDROID.getOs())) {
|
|
|
+ result.put("appLink", deeplink_android);
|
|
|
+ } else {
|
|
|
+ result.put("appLink", deeplink_ios);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultMap.ok(product.getPayDevice(), result);
|
|
|
+ }
|
|
|
+ } catch (
|
|
|
+ Exception e) {
|
|
|
+ return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
+ }
|
|
|
+ return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 电脑支付
|
|
|
*
|
|
@@ -194,6 +260,7 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
logger.info("pc端支付生成,请求参数 bo:{}", product);
|
|
|
AlipayTradePagePayResponse response = Factory.Payment
|
|
|
.Page().asyncNotify(notifyUrl)
|
|
|
+ .optional("goods_detail", "1")
|
|
|
.pay(product.getSubject(), product.getOutTradeNo(), product.getTotalFee(), this.returnUrl);
|
|
|
logger.info("pc端支付生成,result:{}", response);
|
|
|
if (ResponseChecker.success(response)) {
|
|
@@ -203,7 +270,6 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("pc端支付生成异常 e:{}", e);
|
|
|
- e.printStackTrace();
|
|
|
return ResultMap.error(ResEnum.FAIL.getMsg());
|
|
|
}
|
|
|
}
|
|
@@ -239,5 +305,6 @@ public class AlipayServiceImpl extends PayService implements OrderPayService {
|
|
|
public void configInit(String obj) {
|
|
|
Config config = JSONObject.parseObject(obj, Config.class);
|
|
|
Factory.setOptions(config);
|
|
|
+ this.config = config;
|
|
|
}
|
|
|
-}
|
|
|
+}
|