53 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
| <!DOCTYPE html>
 | |
| <html lang="en">
 | |
| <head>
 | |
|     <meta charset="UTF-8">
 | |
|     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | |
|     <title>微信授权登录</title>
 | |
|     <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
 | |
| </head>
 | |
| <body onload="getCode()">
 | |
| <button id="loginBtn">微信登录</button>
 | |
| <script>
 | |
|     function getCode() {
 | |
|         // 获取当前 URL 的查询参数
 | |
|         const urlParams = new URLSearchParams(window.location.search);
 | |
| 
 | |
|         // 获取名为 "id" 的查询参数值
 | |
|         const id = urlParams.get('id');
 | |
| 
 | |
|         fetch('/pay/front/api/v1/wx/getWxAuthUrl', {
 | |
|             method: 'POST',
 | |
|             headers: {
 | |
|                 'Content-Type': 'application/json',
 | |
|             },
 | |
|             body: JSON.stringify({
 | |
|                 'pay_channel_id': id
 | |
|             }),
 | |
|         })
 | |
|             .then(async response => {
 | |
|                 if (response.ok) {
 | |
|                     const data = await response.json()
 | |
|                     console.log(data)
 | |
|                     if (data.code === 200) {
 | |
|                         return data;
 | |
|                     } else {
 | |
|                         throw new Error('获取url失败');
 | |
|                     }
 | |
|                 } else {
 | |
|                     throw new Error('获取url失败');
 | |
|                 }
 | |
|             })
 | |
|             .then(data => {
 | |
|                 console.log('获取url:', data);
 | |
|                 console.log('获取url:', data.data);
 | |
|                 window.location.href = data.data; // 跳转
 | |
|             })
 | |
|             .catch(error => {
 | |
|                 console.error('获取url失败:', error);
 | |
|             });
 | |
|     }
 | |
| </script>
 | |
| </body>
 | |
| </html>
 |