支付宝手机网站支付

This commit is contained in:
jason
2021-11-04 00:26:56 +08:00
parent aa77eb029f
commit 2c60a3aafa
14 changed files with 204 additions and 21 deletions

View File

@ -6,17 +6,21 @@ import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayOrderCoreServic
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitReqDTO;
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayOrderSubmitRespDTO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.pay.core.client.dto.NotifyDataDTO;
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitReqVO;
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayOrderSubmitRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
@ -54,7 +58,7 @@ public class PayOrderController {
@ApiOperation("通知微信公众号支付的结果")
public String notifyWxPayOrder(@PathVariable("channelId") Long channelId,
@RequestBody String xmlData) throws Exception {
payOrderCoreService.notifyPayOrder(channelId, PayChannelEnum.WX_PUB.getCode(), xmlData);
payOrderCoreService.notifyPayOrder(channelId, PayChannelEnum.WX_PUB.getCode(), NotifyDataDTO.builder().origData(xmlData).build());
return "success";
}
@ -72,4 +76,27 @@ public class PayOrderController {
return "success";
}
@PostMapping(value = "/notify/alipay-wap/{channelId}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ApiOperation("支付宝wap页面回调")
public String notifyAliPayWapPayOrder(@PathVariable("channelId") Long channelId,
@RequestParam Map<String, String> params,
@RequestBody String originData) throws Exception {
//TODO @jason 校验 是否支付宝调用。 使用 支付宝publickey payclient 或许加一个校验方法
payOrderCoreService.notifyPayOrder(channelId, PayChannelEnum.ALIPAY_WAP.getCode(), NotifyDataDTO.builder().params(params).origData(originData).build());
return "success";
}
/**
* https://opendocs.alipay.com/open/203/105285#%E5%89%8D%E5%8F%B0%E5%9B%9E%E8%B7%B3%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E
* @param channelId
* @return
* @throws Exception
*/
@GetMapping(value = "/return/alipay-wap/{channelId}")
@ApiOperation("支付宝wap页面回跳")
public String returnAliPayWapPayOrder(@PathVariable("channelId") Long channelId){
//TODO @jason 校验 是否支付宝调用。 支付宝publickey 可以根据 appId 跳转不同的页面
return "支付成功";
}
}

View File

@ -153,5 +153,6 @@ yudao:
- ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求
demo: false # 关闭演示模式
pay:
pay-notify-url: http://niubi.natapp1.cc/api/pay/order/notify
refund-notify-url: http://niubi.natapp1.cc/api/pay/refund/notify
pay-notify-url: http://jg6rde.natappfree.cc/api/pay/order/notify
refund-notify-url: http://jg6rde.natappfree.cc/api/pay/refund/notify
return-url: http://jg6rde.natappfree.cc/api/pay/order/return

View File

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<title>支付测试页</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<div>点击如下按钮,发起支付的测试</div>
<div>
<button id="alipay_wap">支付宝h5</button>
</div>
<div id="dynamic_form"></div>
</body>
<script>
let shopOrderId = undefined;
let payOrderId = undefined;
let server = 'http://127.0.0.1:28080';
//let server = 'http://niubi.natapp1.cc';
// TODO openid
//let openid = "ockUAwIZ-0OeMZl9ogcZ4ILrGba0";
$(function() {
// 自动发起商城订单编号
$.ajax({
url: server + "/api/shop/order/create",
method: 'POST',
success: function( result ) {
if (result.code !== 0) {
alert('创建商城订单失败,原因:' + result.msg)
return;
}
shopOrderId = result.data.id;
payOrderId = result.data.payOrderId;
console.log("商城订单:" + shopOrderId)
console.log("支付订单:" + payOrderId)
}
})
});
// 微信公众号
$( "#alipay_wap").on( "click", function() {
// 提交支付
$.ajax({
url: server + "/api/pay/order/submit",
method: 'POST',
dataType: "json",
contentType: "application/json",
data: JSON.stringify({
"id": payOrderId,
"channelCode": 'alipay_wap'
}),
success: function( result ) {
if (result.code !== 0) {
alert('提交支付订单失败,原因:' + result.msg)
return;
}
alert('点击确定,开始支付');
// 开始调用微信支付
let data = result.data.invokeResponse;
$("#dynamic_form").html(data.body);
}
})
});
</script>
</html>