“mitao”
2026-04-30 2e8e30594ae4b6c9ddb7371c53ebd5205a3c82a6
Merge remote-tracking branch 'origin/master'
2个文件已修改
104 ■■■■■ 已修改文件
traditionalApp/manifest.json 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/settings/settings.vue 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/manifest.json
@@ -48,11 +48,13 @@
                    "<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
                ],
                "minSdkVersion" : 28,
                "targetSdkVersion" : 30
                "targetSdkVersion" : 30,
                "schemes" : "ag8spw"
            },
            /* ios打包配置 */
            "ios" : {
                "dSYMs" : false,
                "schemes" : "ag8spw",
                "capabilities" : {
                    "entitlements" : {
                        "com.apple.developer.associated-domains" : [
traditionalApp/pages/settings/settings.vue
@@ -44,7 +44,7 @@
                        <image class="edit-icon" src="/static/image/mine/edit.png" mode="aspectFit" @tap="editPassword"></image>
                    </view>
                </view>
                <view class="list-item">
                <view class="list-item" @tap="swapWechat">
                    <view class="list-left">
                        <image class="list-icon" src="/static/image/mine/weixinIcon.png" mode="aspectFit"></image>
                        <text class="list-title">绑定微信</text>
@@ -55,7 +55,7 @@
                            <text class="wechat-name">{{ profile.wechatBinding.nickname || '已绑定微信' }}</text>
                        </view>
                        <text class="wechat-unbound" v-else>去绑定</text>
                        <image class="swap-icon" src="/static/image/mine/refish.png" mode="aspectFit" @tap="swapWechat"></image>
                        <image class="swap-icon" src="/static/image/mine/refish.png" mode="aspectFit" @tap.stop="swapWechat"></image>
                    </view>
                </view>
            </view>
@@ -250,7 +250,7 @@
        })
    } catch (error) {
        uni.showToast({
            title: '微信绑定失败',
            title: resolveWechatBindErrorMessage(error),
            icon: 'none',
        })
    } finally {
@@ -345,6 +345,33 @@
 */
function requestWechatAuthorization() {
    return new Promise<WechatLoginResult>((resolve, reject) => {
        // #ifdef APP-PLUS
        plus.oauth.getServices((services) => {
            const weixinService = services.find((service) => service.id === 'weixin')
            if (!weixinService) {
                reject({
                    code: -3,
                    errMsg: '当前环境不支持微信登录',
                })
                return
            }
            if (!weixinService.nativeClient) {
                reject({
                    code: -8,
                    errMsg: '请先安装微信客户端',
                })
                return
            }
            requestWechatAuthorizeByService(weixinService, resolve, reject)
        }, (error: any) => {
            reject({
                code: error?.code,
                errMsg: error?.message || '获取微信登录服务失败',
            })
        })
        return
        // #endif
        uni.login({
            provider: 'weixin',
            success: (res) => {
@@ -354,6 +381,62 @@
                reject(error)
            },
        })
    })
}
/**
 * 通过微信原生服务执行授权;如存在旧授权态则先退出再重新拉起。
 */
function requestWechatAuthorizeByService(
    weixinService: any,
    resolve: (value: WechatLoginResult) => void,
    reject: (reason?: any) => void
) {
    const executeAuthorize = () => {
        weixinService.authorize((event: any) => {
            const code = normalizeOptionalText(event?.code)
            const authResult = weixinService.authResult || {}
            const accessToken = normalizeOptionalText(authResult.access_token || authResult.accessToken)
            const openid = normalizeOptionalText(authResult.openid || authResult.openId)
            if (!code && !(accessToken && openid)) {
                reject({
                    code: -99,
                    errMsg: '微信授权未返回有效凭证',
                })
                return
            }
            resolve({
                code,
                authResult: {
                    access_token: authResult.access_token,
                    accessToken: authResult.accessToken,
                    openid: authResult.openid,
                    openId: authResult.openId,
                    unionid: authResult.unionid,
                    unionId: authResult.unionId,
                },
            })
        }, (error: any) => {
            reject({
                code: error?.code,
                errMsg: error?.message || '微信授权失败',
            })
        }, {
            scope: 'snsapi_userinfo',
            state: 'bind_wechat',
        })
    }
    const authResult = weixinService?.authResult || {}
    const hasAuthorized = !!normalizeOptionalText(authResult.access_token || authResult.accessToken || authResult.openid || authResult.openId)
    if (!hasAuthorized || typeof weixinService.logout !== 'function') {
        executeAuthorize()
        return
    }
    weixinService.logout(() => {
        executeAuthorize()
    }, () => {
        executeAuthorize()
    })
}
@@ -377,6 +460,17 @@
    })
    return null
}
/**
 * 将微信绑定错误归一化为可直接提示给用户的文案。
 */
function resolveWechatBindErrorMessage(error: any) {
    const errorMessage = normalizeOptionalText(error?.errMsg || error?.message)
    if (errorMessage) {
        return errorMessage
    }
    return '微信绑定失败'
}
</script>
<style lang="scss" scoped>