石广澎
2025-11-30 55ee7bd313c7d8030ce8c547b18ad5f19507afd2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
    <view>
        <movable-area :style="'width: ' + windowWidth + 'px;height:' + windowHeight + 'px'">
            <web-view :src="url">
            </web-view>
            <movable-view direction="all" x="553rpx" :y="windowHeight/2-hf" v-if="cid" @click="openPay" class="pay-btn">
                <image class="pay-img" src="/static/pay-btn.jpeg" mode=""></image>
            </movable-view>
        </movable-area>
 
    </view>
</template>
 
<script>
    import {
        ACCESSTOKEN,
        config
    } from '@/common/config.js';
    import {
        getWechatInfo,
        getOpenId,
        getOpenIdBase
    } from '@/common/api/index'
    export default {
        data() {
            return {
                hf: uni.upx2px(81),
                cid: '',
                windowHeight: 724,
                windowWidth: 0,
                url: ''
            };
        },
        onLoad(opt) {
            let sysInfo = uni.getSystemInfoSync();
            this.windowHeight = sysInfo.windowHeight;
            this.windowWidth = sysInfo.windowWidth;
            if (opt.cid) {
                uni.setStorageSync('CID', opt.cid)
                if (opt.cid == '1285474127884455937') {
                    this.url =
                        "https://fxm.xintoucloud.com/scene-user-fillin?sceneCode=DE88783ECF1D4DC2BCBF25A1A683651AFA4A9523573FF4080F2086B00E00E78A1235219708A15E8B223AAC2D243884DE"
                } else if (opt.cid == '1586530233928945664') {
                    this.url =
                        "https://fxm.xintoucloud.com/scene-user-fillin?sceneCode=622C5D9E30E54D07BCB3BF280DBEE266F4C88598A368881C81D0D8CECA02C3DB1235219708A15E8B223AAC2D243884DE"
                }
                this.cid = opt.cid
            }
            if (opt.code) {
                uni.showLoading()
                getOpenId({
                    params: {
                        code: opt.code
                    }
                }).then(res => {
                    uni.setStorageSync(ACCESSTOKEN, res.token.accessToken)
                    uni.setStorageSync('IS_NEW', res.isNew)
                    let url = '/pages/pay/scanpay?cid=' + this.cid
                    if (res.isNew) {
                        url = '/pages/pay/wxpay?cid=' + this.cid
                    }
                    uni.hideLoading()
                    uni.redirectTo({
                        url: url
                    })
                }).catch(() => {
                    uni.hideLoading()
                })
            }
        },
        methods: {
            openPay() {
                const TOKEN = uni.getStorageSync(ACCESSTOKEN) || null;
                if (TOKEN) {
                    const IS_NEW = uni.getStorageSync('IS_NEW') || null;
                    let url = '/pages/pay/scanpay?cid=' + this.cid
                    if (IS_NEW) {
                        url = '/pages/pay/wxpay?cid=' + this.cid
                    }
                    uni.redirectTo({
                        url: url
                    })
                } else {
                    uni.showLoading()
                    getWechatInfo().then(res => {
                        const redirect_uri = encodeURIComponent(
                            `${config.webURL}/pages/pay/scanRes?cid=${this.cid}`)
                        window.location.href =
                            `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
                    })
                }
            }
 
        }
    }
</script>
 
<style lang="scss">
    .pay-btn {
        position: fixed;
        z-index: 99999;
        width: 162rpx;
        height: 162rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        border-radius: 15rpx;
        overflow: hidden;
    }
 
    .pay-img {
        width: 162rpx;
        height: 162rpx;
    }
</style>