pay_alipay_wap.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
  6. <title>支付测试页</title>
  7. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  8. </head>
  9. <body>
  10. <div>点击如下按钮,发起支付的测试</div>
  11. <div>
  12. <button id="alipay_wap">支付宝手机网站支付</button>
  13. </div>
  14. <div id="dynamic_form"></div>
  15. </body>
  16. <script>
  17. let shopOrderId = undefined;
  18. let payOrderId = undefined;
  19. let server = 'http://127.0.0.1:48080';
  20. //let server = 'http://niubi.natapp1.cc';
  21. $(function() {
  22. // 自动发起商城订单编号
  23. $.ajax({
  24. url: server + "/app-api/shop/order/create",
  25. method: 'POST',
  26. success: function( result ) {
  27. if (result.code !== 0) {
  28. alert('创建商城订单失败,原因:' + result.msg)
  29. return;
  30. }
  31. shopOrderId = result.data.id;
  32. payOrderId = result.data.payOrderId;
  33. console.log("商城订单:" + shopOrderId)
  34. console.log("支付订单:" + payOrderId)
  35. }
  36. })
  37. });
  38. $( "#alipay_wap").on( "click", function() {
  39. // 提交支付
  40. $.ajax({
  41. url: server + "/app-api/pay/order/submit",
  42. method: 'POST',
  43. dataType: "json",
  44. contentType: "application/json",
  45. data: JSON.stringify({
  46. "id": payOrderId,
  47. "channelCode": 'alipay_wap'
  48. }),
  49. success: function( result ) {
  50. if (result.code !== 0) {
  51. alert('提交支付订单失败,原因:' + result.msg)
  52. return;
  53. }
  54. alert('点击确定,开始支付');
  55. //支付宝 手机WAP 返回表单,自动跳到支付宝支付页面
  56. let data = result.data.invokeResponse;
  57. $("#dynamic_form").html(data.body);
  58. }
  59. })
  60. });
  61. </script>
  62. </html>