<template>
	<!-- 获取authcode页面 -->
  <div>
	  <button type="primary" onTap="getAuthCode">
	    获取授权码
	  </button>
    <button @click="handleLogin">登录</button>
  </div>
</template>

<script>

export default {
  methods: {
	  getAuthCode: () => {
	    my.getAuthCode({
	      scopes: 'auth_user',
	      success: ({ authCode }) => {
	        console.log(`authCode:`, authCode);
	        my.alert({
	           content: authCode,
	        });
	      },
	    });
	  },
    handleLogin() {
      uni.login({
        provider: 'alipay',
        success: async (loginRes) => {
          const { code } = loginRes;
          if (!code) {
            console.log('登录失败，没有获取到 code');
            return;
          }

          uni.request({
            url: 'http://localhost:9999/api/Alipay/test/parseCode',
            method: 'GET',
            data: {
              authCode: code,
            },
            success: (response) => {
              console.log(response.data); // 登录成功后的处理...
            },
            fail: (error) => {
              console.error('登录失败', error.message);
            },
          });
        },
      });
    },
  },
};
</script>