|
|
@@ -10,9 +10,11 @@ import com.alipay.api.domain.AlipayTradeWapPayModel;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
|
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
|
|
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
|
|
+import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.request.AlipayUserInfoShareRequest;
|
|
|
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
|
|
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
|
|
+import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
|
|
import com.uas.platform.core.util.HttpUtil;
|
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
@@ -34,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
@@ -281,6 +284,8 @@ public class AlipayController {
|
|
|
String notifySellerId = params.get("seller_id") == null ? "" : params.get("seller_id");
|
|
|
String notifySellerEmail = params.get("seller_email") == null ? "" : params.get("seller_id");
|
|
|
|
|
|
+ System.out.print("*************************异步通知********************************* 商户订单号:" + notifyOutTradeNo);
|
|
|
+
|
|
|
//商户系统订单支付状态
|
|
|
short projectRecodePayStatus = 1;
|
|
|
if ("TRADE_SUCCESS".equals(notifyTradeStatus)) {
|
|
|
@@ -356,7 +361,8 @@ public class AlipayController {
|
|
|
*/
|
|
|
@ResponseBody
|
|
|
@RequestMapping("/returnUrl")
|
|
|
- public String returnUrl(HttpServletRequest request){
|
|
|
+ public ModelAndView returnUrl(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ ModelAndView modelAndView = new ModelAndView();
|
|
|
Map<String, String> params = AlipayApi.toMap(request);
|
|
|
String data = AlipayApi.getRequestData(request); // data json格式
|
|
|
System.out.print(data);
|
|
|
@@ -364,21 +370,70 @@ public class AlipayController {
|
|
|
try {
|
|
|
signVerified = AlipaySignature.rsaCheckV1(params, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.CHARSET, AlipayConfig.SIGNTYPE);
|
|
|
} catch (AlipayApiException e) {
|
|
|
- System.out.print("fail");
|
|
|
- return "fail";
|
|
|
+ //TODO 此处让用户自己判断有没有支付成功。
|
|
|
}
|
|
|
|
|
|
if(signVerified){
|
|
|
// TODO 验签成功后,按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,校验成功后在response中返回success并继续商户自身业务处理,校验失败返回failure
|
|
|
- System.out.print("success");
|
|
|
- return data;
|
|
|
+ String notifyOutTradeNo = params.get("out_trade_no");//通知返回的商户订单号
|
|
|
+ String notifyTradeNo = params.get("trade_no");//通知返回的支付宝交易号
|
|
|
+ AlipayTradeQueryResponse tradeQueryResponse = queryTrade(notifyOutTradeNo, notifyTradeNo);
|
|
|
+
|
|
|
+ if (tradeQueryResponse == null) {
|
|
|
+ //TODO 提示系统繁忙(其实是查询支付宝订单报错)
|
|
|
+ } else {
|
|
|
+ if ("10000".equals(tradeQueryResponse.getCode())) {
|
|
|
+ if ("TRADE_SUCCESS".equals(tradeQueryResponse.getTradeStatus())) {
|
|
|
+ String url = "/project#/donationsOver/" + notifyOutTradeNo;
|
|
|
+ modelAndView.setViewName("redirect:" + url);
|
|
|
+ }
|
|
|
+ //TODO 其他状态判断
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}else{
|
|
|
+ //TODO 此处让用户自己判断有没有支付成功。
|
|
|
// TODO 验签失败则记录异常日志,并在response中返回failure.
|
|
|
- System.out.print("fail");
|
|
|
- return "fail";
|
|
|
}
|
|
|
+ return modelAndView;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询支付宝订单
|
|
|
+ * @param outTradeNo
|
|
|
+ * @param tradeNo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "/queryTrade", method = RequestMethod.GET)
|
|
|
+ public AlipayTradeQueryResponse queryTrade(String outTradeNo, String tradeNo){
|
|
|
+ AlipayTradeQueryRequest tradeQueryRequest = new AlipayTradeQueryRequest();
|
|
|
+ tradeQueryRequest.setBizContent("{" +
|
|
|
+ "\"out_trade_no\":" + outTradeNo + "," +
|
|
|
+ "\"trade_no\":" + tradeNo +
|
|
|
+ "}");
|
|
|
+ AlipayTradeQueryResponse tradeQueryResponse = null;
|
|
|
+ try {
|
|
|
+ tradeQueryResponse = alipayClient.execute(tradeQueryRequest);
|
|
|
+ } catch (AlipayApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return tradeQueryResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否需要用户授权获取会员信息
|
|
|
*/
|
|
|
@@ -396,6 +451,9 @@ public class AlipayController {
|
|
|
|
|
|
/**
|
|
|
* 拼接用户授权接口url
|
|
|
+ * https://docs.open.alipay.com/289/105656
|
|
|
+ * https://docs.open.alipay.com/284/106001
|
|
|
+ *
|
|
|
* 正式url拼接规则:https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=SCOPE&redirect_uri=ENCODED_URL
|
|
|
* 沙箱url拼接规则:https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=SCOPE&redirect_uri=ENCODED_URL
|
|
|
*/
|