123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
- <title>Document</title>
- </head>
- <body>
- <blockquote><h1>快来给钱</h1></blockquote>
- <p id="result">result: </p>
- <input type="button" id="pay" value="支付咯" />
- <p id="p"></p>
- </body>
- <script type="application/javascript">
- // 调试时可以通过在页面定义一个元素,打印信息,使用alert方法不够优雅
- function log(obj) {
- $("#result").append(obj).append(" ").append("<br />");
- }
- $(document).ready(async () => {
- let data = await $.get("/token" + location.search, function(data){
- return data;
- });
- $("#pay").click(function() {
- tradePay(data);
- });
- $("#closeButton").click(function() {
- AlipayJSBridge.call('closeWebview');
- });
- });
- // 由于js的载入是异步的,所以可以通过该方法,当AlipayJSBridgeReady事件发生后,再执行callback方法
- function ready(callback) {
- if (window.AlipayJSBridge) {
- callback && callback();
- } else {
- document.addEventListener('AlipayJSBridgeReady', callback, false);
- }
- }
- function tradePay(tradeNO) {
- ready(function(){
- // 通过传入交易号唤起快捷调用方式(注意tradeNO大小写严格)
- AlipayJSBridge.call("tradePay", {
- tradeNO: tradeNO
- }, function (data) {
- log(JSON.stringify(data));
- if ("9000" == data.resultCode) {
- log("支付成功");
- }
- });
- });
- }
- </script>
- </html>
|